Skip to content

Commit eca6331

Browse files
author
Robert Bastian
committed
str
1 parent 8dd5cd0 commit eca6331

File tree

35 files changed

+292
-74
lines changed

35 files changed

+292
-74
lines changed

compiler/rustc_feature/src/unstable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,8 @@ declare_features! (
495495
(unstable, impl_trait_in_fn_trait_return, "1.64.0", Some(99697)),
496496
/// Allows associated types in inherent impls.
497497
(incomplete, inherent_associated_types, "1.52.0", Some(8995)),
498+
/// Adds `from_utf8*` functions as inherent methods on the `str` type.
499+
(unstable, inherent_str_constructors, "1.82.0", Some(131114)),
498500
/// Allow anonymous constants from an inline `const` block in pattern position
499501
(unstable, inline_const_pat, "1.58.0", Some(76001)),
500502
/// Allows using `pointer` and `reference` in intra-doc links

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,7 @@ symbols! {
10651065
infer_outlives_requirements,
10661066
infer_static_outlives_requirements,
10671067
inherent_associated_types,
1068+
inherent_str_constructors,
10681069
inherit,
10691070
inlateout,
10701071
inline,

library/alloc/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
#![feature(fmt_internals)]
127127
#![feature(fn_traits)]
128128
#![feature(hasher_prefixfree_extras)]
129+
#![feature(inherent_str_constructors)]
129130
#![feature(inplace_iteration)]
130131
#![feature(iter_advance_by)]
131132
#![feature(iter_next_chunk)]

library/alloc/src/str.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use core::iter::FusedIterator;
1212
use core::mem::MaybeUninit;
1313
#[stable(feature = "encode_utf16", since = "1.8.0")]
1414
pub use core::str::EncodeUtf16;
15+
#[stable(feature = "rust1", since = "1.0.0")]
16+
pub use core::str::ParseBoolError;
1517
#[stable(feature = "split_ascii_whitespace", since = "1.34.0")]
1618
pub use core::str::SplitAsciiWhitespace;
1719
#[stable(feature = "split_inclusive", since = "1.51.0")]
@@ -22,7 +24,7 @@ pub use core::str::SplitWhitespace;
2224
pub use core::str::pattern;
2325
use core::str::pattern::{DoubleEndedSearcher, Pattern, ReverseSearcher, Searcher};
2426
#[stable(feature = "rust1", since = "1.0.0")]
25-
pub use core::str::{Bytes, CharIndices, Chars, from_utf8, from_utf8_mut};
27+
pub use core::str::{Bytes, CharIndices, Chars};
2628
#[stable(feature = "str_escape", since = "1.34.0")]
2729
pub use core::str::{EscapeDebug, EscapeDefault, EscapeUnicode};
2830
#[stable(feature = "rust1", since = "1.0.0")]
@@ -35,8 +37,6 @@ pub use core::str::{MatchIndices, RMatchIndices};
3537
#[stable(feature = "rust1", since = "1.0.0")]
3638
pub use core::str::{Matches, RMatches};
3739
#[stable(feature = "rust1", since = "1.0.0")]
38-
pub use core::str::{ParseBoolError, from_utf8_unchecked, from_utf8_unchecked_mut};
39-
#[stable(feature = "rust1", since = "1.0.0")]
4040
pub use core::str::{RSplit, Split};
4141
#[stable(feature = "rust1", since = "1.0.0")]
4242
pub use core::str::{RSplitN, SplitN};
@@ -46,6 +46,9 @@ pub use core::str::{RSplitTerminator, SplitTerminator};
4646
pub use core::str::{Utf8Chunk, Utf8Chunks};
4747
#[unstable(feature = "str_from_raw_parts", issue = "119206")]
4848
pub use core::str::{from_raw_parts, from_raw_parts_mut};
49+
#[allow(deprecated_in_future)]
50+
#[stable(feature = "rust1", since = "1.0.0")]
51+
pub use core::str::{from_utf8, from_utf8_mut, from_utf8_unchecked, from_utf8_unchecked_mut};
4952
use core::unicode::conversions;
5053
use core::{mem, ptr};
5154

@@ -681,7 +684,7 @@ pub fn convert_while_ascii(s: &str, convert: fn(&u8) -> u8) -> (String, &str) {
681684

682685
// SAFETY: we know this is a valid char boundary
683686
// since we only skipped over leading ascii bytes
684-
let rest = core::str::from_utf8_unchecked(slice);
687+
let rest = str::from_utf8_unchecked(slice);
685688

686689
(ascii_string, rest)
687690
}

library/alloc/src/string.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ use crate::alloc::Allocator;
6262
use crate::borrow::{Cow, ToOwned};
6363
use crate::boxed::Box;
6464
use crate::collections::TryReserveError;
65-
use crate::str::{self, Chars, Utf8Error, from_utf8_unchecked_mut};
65+
use crate::str::{Chars, Utf8Error};
6666
#[cfg(not(no_global_oom_handling))]
6767
use crate::str::{FromStr, from_boxed_utf8_unchecked};
6868
use crate::vec::Vec;
@@ -2043,7 +2043,7 @@ impl String {
20432043
#[inline]
20442044
pub fn leak<'a>(self) -> &'a mut str {
20452045
let slice = self.vec.leak();
2046-
unsafe { from_utf8_unchecked_mut(slice) }
2046+
unsafe { str::from_utf8_unchecked_mut(slice) }
20472047
}
20482048
}
20492049

library/alloc/src/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3482,7 +3482,7 @@ impl Default for Arc<str> {
34823482
#[inline]
34833483
fn default() -> Self {
34843484
let arc: Arc<[u8]> = Default::default();
3485-
debug_assert!(core::str::from_utf8(&*arc).is_ok());
3485+
debug_assert!(str::from_utf8(&*arc).is_ok());
34863486
let (ptr, alloc) = Arc::into_inner_with_allocator(arc);
34873487
unsafe { Arc::from_ptr_in(ptr.as_ptr() as *mut ArcInner<str>, alloc) }
34883488
}

library/core/src/char/methods.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use super::*;
44
use crate::intrinsics::const_eval_select;
55
use crate::slice;
6-
use crate::str::from_utf8_unchecked_mut;
76
use crate::unicode::printable::is_printable;
87
use crate::unicode::{self, conversions};
98

@@ -678,7 +677,7 @@ impl char {
678677
#[inline]
679678
pub const fn encode_utf8(self, dst: &mut [u8]) -> &mut str {
680679
// SAFETY: `char` is not a surrogate, so this is valid UTF-8.
681-
unsafe { from_utf8_unchecked_mut(encode_utf8_raw(self as u32, dst)) }
680+
unsafe { str::from_utf8_unchecked_mut(encode_utf8_raw(self as u32, dst)) }
682681
}
683682

684683
/// Encodes this character as UTF-16 into the provided `u16` buffer,

library/core/src/ffi/c_str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::iter::FusedIterator;
77
use crate::marker::PhantomData;
88
use crate::ptr::NonNull;
99
use crate::slice::memchr;
10-
use crate::{fmt, intrinsics, ops, slice, str};
10+
use crate::{fmt, intrinsics, ops, slice};
1111

1212
// FIXME: because this is doc(inline)d, we *have* to use intra-doc links because the actual link
1313
// depends on where the item is being documented. however, since this is libcore, we can't
@@ -664,7 +664,7 @@ impl CStr {
664664
/// ```
665665
#[stable(feature = "cstr_to_str", since = "1.4.0")]
666666
#[rustc_const_stable(feature = "const_cstr_methods", since = "1.72.0")]
667-
pub const fn to_str(&self) -> Result<&str, str::Utf8Error> {
667+
pub const fn to_str(&self) -> Result<&str, crate::str::Utf8Error> {
668668
// N.B., when `CStr` is changed to perform the length check in `.to_bytes()`
669669
// instead of in `from_ptr()`, it may be worth considering if this should
670670
// be rewritten to do the UTF-8 check inline with the length calculation

library/core/src/fmt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::char::EscapeDebugExtArgs;
77
use crate::marker::PhantomData;
88
use crate::num::fmt as numfmt;
99
use crate::ops::Deref;
10-
use crate::{iter, mem, result, str};
10+
use crate::{iter, mem, result};
1111

1212
mod builders;
1313
#[cfg(not(no_fp_fmt_parse))]

library/core/src/fmt/num.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::mem::MaybeUninit;
44
use crate::num::fmt as numfmt;
55
use crate::ops::{Div, Rem, Sub};
6-
use crate::{fmt, ptr, slice, str};
6+
use crate::{fmt, ptr, slice};
77

88
#[doc(hidden)]
99
trait DisplayInt:

0 commit comments

Comments
 (0)