Skip to content

Commit 867a480

Browse files
authored
Rollup merge of rust-lang#152963 - JonathanBrouwer:revert-str-as-str, r=jhpratt
Revert "Stabilize `str_as_str`" Reverts rust-lang#151603, clean revert. Fixes rust-lang#152961
2 parents 42994d6 + 51d7272 commit 867a480

File tree

9 files changed

+52
-12
lines changed

9 files changed

+52
-12
lines changed

library/alloctests/tests/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#![feature(thin_box)]
3434
#![feature(drain_keep_rest)]
3535
#![feature(local_waker)]
36+
#![feature(str_as_str)]
3637
#![feature(strict_provenance_lints)]
3738
#![feature(string_replace_in_place)]
3839
#![feature(vec_deque_truncate_front)]

library/core/src/bstr/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ impl ByteStr {
7474
/// it helps dereferencing other "container" types,
7575
/// for example `Box<ByteStr>` or `Arc<ByteStr>`.
7676
#[inline]
77+
// #[unstable(feature = "str_as_str", issue = "130366")]
7778
#[unstable(feature = "bstr", issue = "134915")]
7879
pub const fn as_byte_str(&self) -> &ByteStr {
7980
self
@@ -85,6 +86,7 @@ impl ByteStr {
8586
/// it helps dereferencing other "container" types,
8687
/// for example `Box<ByteStr>` or `MutexGuard<ByteStr>`.
8788
#[inline]
89+
// #[unstable(feature = "str_as_str", issue = "130366")]
8890
#[unstable(feature = "bstr", issue = "134915")]
8991
pub const fn as_mut_byte_str(&mut self) -> &mut ByteStr {
9092
self

library/core/src/ffi/c_str.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,7 @@ impl CStr {
655655
/// it helps dereferencing other string-like types to string slices,
656656
/// for example references to `Box<CStr>` or `Arc<CStr>`.
657657
#[inline]
658-
#[stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")]
659-
#[rustc_const_stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")]
658+
#[unstable(feature = "str_as_str", issue = "130366")]
660659
pub const fn as_c_str(&self) -> &CStr {
661660
self
662661
}

library/core/src/slice/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5337,8 +5337,7 @@ impl<T> [T] {
53375337
/// it helps dereferencing other "container" types to slices,
53385338
/// for example `Box<[T]>` or `Arc<[T]>`.
53395339
#[inline]
5340-
#[stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")]
5341-
#[rustc_const_stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")]
5340+
#[unstable(feature = "str_as_str", issue = "130366")]
53425341
pub const fn as_slice(&self) -> &[T] {
53435342
self
53445343
}
@@ -5349,8 +5348,7 @@ impl<T> [T] {
53495348
/// it helps dereferencing other "container" types to slices,
53505349
/// for example `Box<[T]>` or `MutexGuard<[T]>`.
53515350
#[inline]
5352-
#[stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")]
5353-
#[rustc_const_stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")]
5351+
#[unstable(feature = "str_as_str", issue = "130366")]
53545352
pub const fn as_mut_slice(&mut self) -> &mut [T] {
53555353
self
53565354
}

library/core/src/str/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3137,8 +3137,7 @@ impl str {
31373137
/// it helps dereferencing other string-like types to string slices,
31383138
/// for example references to `Box<str>` or `Arc<str>`.
31393139
#[inline]
3140-
#[stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")]
3141-
#[rustc_const_stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")]
3140+
#[unstable(feature = "str_as_str", issue = "130366")]
31423141
pub const fn as_str(&self) -> &str {
31433142
self
31443143
}

library/std/src/ffi/os_str.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,8 +1285,7 @@ impl OsStr {
12851285
/// it helps dereferencing other string-like types to string slices,
12861286
/// for example references to `Box<OsStr>` or `Arc<OsStr>`.
12871287
#[inline]
1288-
#[stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")]
1289-
#[rustc_const_stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")]
1288+
#[unstable(feature = "str_as_str", issue = "130366")]
12901289
pub const fn as_os_str(&self) -> &OsStr {
12911290
self
12921291
}

library/std/src/path.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3235,8 +3235,7 @@ impl Path {
32353235
/// it helps dereferencing other `PathBuf`-like types to `Path`s,
32363236
/// for example references to `Box<Path>` or `Arc<Path>`.
32373237
#[inline]
3238-
#[stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")]
3239-
#[rustc_const_stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")]
3238+
#[unstable(feature = "str_as_str", issue = "130366")]
32403239
pub const fn as_path(&self) -> &Path {
32413240
self
32423241
}

tests/ui/resolve/slice-as-slice.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//@ check-pass
2+
// This is a regression test for github.com/rust-lang/rust/issues/152961
3+
// This broke when a method `as_slice` was added on slices
4+
// This pattern is used in the `rgb` crate
5+
6+
struct Meow;
7+
8+
trait ComponentSlice<T> {
9+
fn as_slice(&self) -> &[T];
10+
}
11+
12+
impl ComponentSlice<u8> for [Meow] {
13+
fn as_slice(&self) -> &[u8] {
14+
todo!()
15+
}
16+
}
17+
18+
fn a(data: &[Meow]) {
19+
b(data.as_slice());
20+
//~^ WARN a method with this name may be added to the standard library in the future
21+
//~| WARN once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior!
22+
}
23+
24+
fn b(_b: &[u8]) { }
25+
26+
fn main() {}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
warning: a method with this name may be added to the standard library in the future
2+
--> $DIR/slice-as-slice.rs:19:12
3+
|
4+
LL | b(data.as_slice());
5+
| ^^^^^^^^
6+
|
7+
= warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior!
8+
= note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919>
9+
= help: call with fully qualified syntax `ComponentSlice::as_slice(...)` to keep using the current method
10+
= note: `#[warn(unstable_name_collisions)]` (part of `#[warn(future_incompatible)]`) on by default
11+
help: add `#![feature(str_as_str)]` to the crate attributes to enable `core::slice::<impl [T]>::as_slice`
12+
|
13+
LL + #![feature(str_as_str)]
14+
|
15+
16+
warning: 1 warning emitted
17+

0 commit comments

Comments
 (0)