Skip to content

Commit e65b809

Browse files
Fixing A and COOP_PREFERRED generics. WIP.....
1 parent 9d05507 commit e65b809

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

library/alloc/src/string.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
use crate::alloc::Global;
4747

48-
use crate::vec::PlVec;
48+
use core::alloc;
4949
#[cfg(not(no_global_oom_handling))]
5050
use core::char::{decode_utf16, REPLACEMENT_CHARACTER};
5151
use core::error::Error;
@@ -413,8 +413,11 @@ where
413413
#[stable(feature = "rust1", since = "1.0.0")]
414414
#[cfg_attr(not(no_global_oom_handling), derive(Clone))]
415415
#[derive(Debug, PartialEq, Eq)]
416-
pub struct FromUtf8Error {
417-
bytes: PlVec<u8>,
416+
pub struct FromUtf8Error<const COOP_PREFERRED: bool>
417+
where
418+
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREFERRED)]:,
419+
{
420+
bytes: Vec<u8, Global, COOP_PREFERRED>,
418421
error: Utf8Error,
419422
}
420423

@@ -584,7 +587,7 @@ where
584587
/// [`into_bytes`]: String::into_bytes
585588
#[inline]
586589
#[stable(feature = "rust1", since = "1.0.0")]
587-
pub fn from_utf8(vec: Vec<u8, Global, COOP_PREFERRED>) -> Result<String, FromUtf8Error> {
590+
pub fn from_utf8(vec: Vec<u8, Global, COOP_PREFERRED>) -> Result<String<COOP_PREFERRED>, FromUtf8Error<COOP_PREFERRED>> {
588591
match str::from_utf8(&vec) {
589592
Ok(..) => Ok(String { vec }),
590593
Err(e) => Err(FromUtf8Error { bytes: vec, error: e }),
@@ -1910,7 +1913,9 @@ where
19101913
}
19111914
}
19121915

1913-
impl FromUtf8Error {
1916+
impl <const COOP_PREFERRED: bool> FromUtf8Error<COOP_PREFERRED>
1917+
where
1918+
[(); alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREFERRED)]:, {
19141919
/// Returns a slice of [`u8`]s bytes that were attempted to convert to a `String`.
19151920
///
19161921
/// # Examples
@@ -1951,7 +1956,7 @@ impl FromUtf8Error {
19511956
/// ```
19521957
#[must_use = "`self` will be dropped if the result is not used"]
19531958
#[stable(feature = "rust1", since = "1.0.0")]
1954-
pub fn into_bytes<const COOP_PREFERRED: bool>(self) -> Vec<u8, Global, COOP_PREFERRED>
1959+
pub fn into_bytes(self) -> Vec<u8, Global, COOP_PREFERRED>
19551960
where
19561961
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREFERRED)]:,
19571962
{
@@ -1989,7 +1994,10 @@ impl FromUtf8Error {
19891994
}
19901995

19911996
#[stable(feature = "rust1", since = "1.0.0")]
1992-
impl fmt::Display for FromUtf8Error {
1997+
impl<const COOP_PREFERRED: bool> fmt::Display for FromUtf8Error<COOP_PREFERRED>
1998+
where
1999+
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREFERRED)]:,
2000+
{
19932001
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19942002
fmt::Display::fmt(&self.error, f)
19952003
}
@@ -2003,7 +2011,10 @@ impl fmt::Display for FromUtf16Error {
20032011
}
20042012

20052013
#[stable(feature = "rust1", since = "1.0.0")]
2006-
impl Error for FromUtf8Error {
2014+
impl<const COOP_PREFERRED: bool> Error for FromUtf8Error<COOP_PREFERRED>
2015+
where
2016+
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREFERRED)]:,
2017+
{
20072018
#[allow(deprecated)]
20082019
fn description(&self) -> &str {
20092020
"invalid utf-8"

library/alloc/src/vec/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ pub type CoVec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: All
424424
Vec<T, A, true>;
425425

426426
/// "Plain" Vec. Not "cooperative" - not carrying extra data to assist the allocator.
427+
/// FIXME after cleanup, see if we still use this in core:: and/or alloc::
427428
#[unstable(feature = "global_co_alloc_plvec", issue = "none")]
428429
pub type PlVec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> =
429430
Vec<T, A, false>;

0 commit comments

Comments
 (0)