Skip to content

Commit a3797ff

Browse files
Robert Bastianrobertbastian
authored andcommitted
str
1 parent a7a6c64 commit a3797ff

File tree

35 files changed

+292
-73
lines changed

35 files changed

+292
-73
lines changed

compiler/rustc_feature/src/unstable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,8 @@ declare_features! (
527527
(unstable, import_trait_associated_functions, "CURRENT_RUSTC_VERSION", Some(134691)),
528528
/// Allows associated types in inherent impls.
529529
(incomplete, inherent_associated_types, "1.52.0", Some(8995)),
530+
/// Adds `from_utf8*` functions as inherent methods on the `str` type.
531+
(unstable, inherent_str_constructors, "1.82.0", Some(131114)),
530532
/// Allow anonymous constants from an inline `const` block in pattern position
531533
(unstable, inline_const_pat, "1.58.0", Some(76001)),
532534
/// 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
@@ -1110,6 +1110,7 @@ symbols! {
11101110
infer_outlives_requirements,
11111111
infer_static_outlives_requirements,
11121112
inherent_associated_types,
1113+
inherent_str_constructors,
11131114
inherit,
11141115
inlateout,
11151116
inline,

library/alloc/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
#![feature(fn_traits)]
119119
#![feature(formatting_options)]
120120
#![feature(hasher_prefixfree_extras)]
121+
#![feature(inherent_str_constructors)]
121122
#![feature(inplace_iteration)]
122123
#![feature(iter_advance_by)]
123124
#![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, Utf8Pattern};
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

@@ -698,7 +701,7 @@ pub fn convert_while_ascii(s: &str, convert: fn(&u8) -> u8) -> (String, &str) {
698701

699702
// SAFETY: we know this is a valid char boundary
700703
// since we only skipped over leading ascii bytes
701-
let rest = core::str::from_utf8_unchecked(slice);
704+
let rest = str::from_utf8_unchecked(slice);
702705

703706
(ascii_string, rest)
704707
}

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, CharIndices, Chars, Utf8Error, from_utf8_unchecked_mut};
65+
use crate::str::{CharIndices, Chars, Utf8Error};
6666
#[cfg(not(no_global_oom_handling))]
6767
use crate::str::{FromStr, from_boxed_utf8_unchecked};
6868
use crate::vec::{self, Vec};
@@ -2110,7 +2110,7 @@ impl String {
21102110
#[inline]
21112111
pub fn leak<'a>(self) -> &'a mut str {
21122112
let slice = self.vec.leak();
2113-
unsafe { from_utf8_unchecked_mut(slice) }
2113+
unsafe { str::from_utf8_unchecked_mut(slice) }
21142114
}
21152115
}
21162116

library/alloc/src/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3508,7 +3508,7 @@ impl Default for Arc<str> {
35083508
#[inline]
35093509
fn default() -> Self {
35103510
let arc: Arc<[u8]> = Default::default();
3511-
debug_assert!(core::str::from_utf8(&*arc).is_ok());
3511+
debug_assert!(str::from_utf8(&*arc).is_ok());
35123512
let (ptr, alloc) = Arc::into_inner_with_allocator(arc);
35133513
unsafe { Arc::from_ptr_in(ptr.as_ptr() as *mut ArcInner<str>, alloc) }
35143514
}

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::panic::const_panic;
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

@@ -701,7 +700,7 @@ impl char {
701700
#[inline]
702701
pub const fn encode_utf8(self, dst: &mut [u8]) -> &mut str {
703702
// SAFETY: `char` is not a surrogate, so this is valid UTF-8.
704-
unsafe { from_utf8_unchecked_mut(encode_utf8_raw(self as u32, dst)) }
703+
unsafe { str::from_utf8_unchecked_mut(encode_utf8_raw(self as u32, dst)) }
705704
}
706705

707706
/// 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
@@ -8,7 +8,7 @@ use crate::iter::FusedIterator;
88
use crate::marker::PhantomData;
99
use crate::ptr::NonNull;
1010
use crate::slice::memchr;
11-
use crate::{fmt, ops, slice, str};
11+
use crate::{fmt, ops, slice};
1212

1313
// FIXME: because this is doc(inline)d, we *have* to use intra-doc links because the actual link
1414
// depends on where the item is being documented. however, since this is libcore, we can't
@@ -651,7 +651,7 @@ impl CStr {
651651
/// ```
652652
#[stable(feature = "cstr_to_str", since = "1.4.0")]
653653
#[rustc_const_stable(feature = "const_cstr_methods", since = "1.72.0")]
654-
pub const fn to_str(&self) -> Result<&str, str::Utf8Error> {
654+
pub const fn to_str(&self) -> Result<&str, crate::str::Utf8Error> {
655655
// N.B., when `CStr` is changed to perform the length check in `.to_bytes()`
656656
// instead of in `from_ptr()`, it may be worth considering if this should
657657
// 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)