Skip to content

Commit 48544c1

Browse files
committed
Make rustc_on_unimplemented std-agnostic
1 parent 25b5af1 commit 48544c1

File tree

6 files changed

+60
-30
lines changed

6 files changed

+60
-30
lines changed

library/core/src/convert/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ pub trait Into<T>: Sized {
532532
#[rustc_diagnostic_item = "From"]
533533
#[stable(feature = "rust1", since = "1.0.0")]
534534
#[rustc_on_unimplemented(on(
535-
all(_Self = "&str", T = "std::string::String"),
535+
all(_Self = "&str", any(T = "alloc::string::String", T = "std::string::String")),
536536
note = "to coerce a `{T}` into a `{Self}`, use `&*` as a prefix",
537537
))]
538538
pub trait From<T>: Sized {

library/core/src/iter/traits/iterator.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ fn _assert_is_object_safe(_: &dyn Iterator<Item = ()>) {}
2626
#[stable(feature = "rust1", since = "1.0.0")]
2727
#[rustc_on_unimplemented(
2828
on(
29-
_Self = "std::ops::RangeTo<Idx>",
29+
any(_Self = "core::ops::RangeTo<Idx>", _Self = "std::ops::RangeTo<Idx>"),
3030
label = "if you meant to iterate until a value, add a starting value",
3131
note = "`..end` is a `RangeTo`, which cannot be iterated on; you might have meant to have a \
3232
bounded `Range`: `0..end`"
3333
),
3434
on(
35-
_Self = "std::ops::RangeToInclusive<Idx>",
35+
any(_Self = "core::ops::RangeToInclusive<Idx>", _Self = "std::ops::RangeToInclusive<Idx>"),
3636
label = "if you meant to iterate until a value (including it), add a starting value",
3737
note = "`..=end` is a `RangeToInclusive`, which cannot be iterated on; you might have meant \
3838
to have a bounded `RangeInclusive`: `0..=end`"
@@ -43,15 +43,15 @@ fn _assert_is_object_safe(_: &dyn Iterator<Item = ()>) {}
4343
),
4444
on(_Self = "&[]", label = "`{Self}` is not an iterator; try calling `.iter()`"),
4545
on(
46-
_Self = "std::vec::Vec<T, A>",
46+
any(_Self = "alloc::vec::Vec<T, A>", _Self = "std::vec::Vec<T, A>"),
4747
label = "`{Self}` is not an iterator; try calling `.into_iter()` or `.iter()`"
4848
),
4949
on(
5050
_Self = "&str",
5151
label = "`{Self}` is not an iterator; try calling `.chars()` or `.bytes()`"
5252
),
5353
on(
54-
_Self = "std::string::String",
54+
any(_Self = "alloc::string::String", _Self = "std::string::String"),
5555
label = "`{Self}` is not an iterator; try calling `.chars()` or `.bytes()`"
5656
),
5757
on(

library/core/src/marker.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -575,59 +575,59 @@ impl<T: ?Sized> Copy for &T {}
575575
#[lang = "sync"]
576576
#[rustc_on_unimplemented(
577577
on(
578-
_Self = "std::cell::OnceCell<T>",
578+
any(_Self = "core::cell:OnceCell<T>", _Self = "std::cell::OnceCell<T>"),
579579
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::OnceLock` instead"
580580
),
581581
on(
582-
_Self = "std::cell::Cell<u8>",
582+
any(_Self = "core::cell::Cell<u8>", _Self = "std::cell::Cell<u8>"),
583583
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicU8` instead",
584584
),
585585
on(
586-
_Self = "std::cell::Cell<u16>",
586+
any(_Self = "core::cell::Cell<u16>", _Self = "std::cell::Cell<u16>"),
587587
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicU16` instead",
588588
),
589589
on(
590-
_Self = "std::cell::Cell<u32>",
590+
any(_Self = "core::cell::Cell<u32>", _Self = "std::cell::Cell<u32>"),
591591
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicU32` instead",
592592
),
593593
on(
594-
_Self = "std::cell::Cell<u64>",
594+
any(_Self = "core::cell::Cell<u64>", _Self = "std::cell::Cell<u64>"),
595595
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicU64` instead",
596596
),
597597
on(
598-
_Self = "std::cell::Cell<usize>",
598+
any(_Self = "core::cell::Cell<usize>", _Self = "std::cell::Cell<usize>"),
599599
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicUsize` instead",
600600
),
601601
on(
602-
_Self = "std::cell::Cell<i8>",
602+
any(_Self = "core::cell::Cell<i8>", _Self = "std::cell::Cell<i8>"),
603603
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicI8` instead",
604604
),
605605
on(
606-
_Self = "std::cell::Cell<i16>",
606+
any(_Self = "core::cell::Cell<i16>", _Self = "std::cell::Cell<i16>"),
607607
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicI16` instead",
608608
),
609609
on(
610-
_Self = "std::cell::Cell<i32>",
610+
any(_Self = "core::cell::Cell<i32>", _Self = "std::cell::Cell<i32>"),
611611
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicI32` instead",
612612
),
613613
on(
614-
_Self = "std::cell::Cell<i64>",
614+
any(_Self = "core::cell::Cell<i64>", _Self = "std::cell::Cell<i64>"),
615615
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicI64` instead",
616616
),
617617
on(
618-
_Self = "std::cell::Cell<isize>",
618+
any(_Self = "core::cell::Cell<isize>", _Self = "std::cell::Cell<isize>"),
619619
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicIsize` instead",
620620
),
621621
on(
622-
_Self = "std::cell::Cell<bool>",
622+
any(_Self = "core::cell::Cell<bool>", _Self = "std::cell::Cell<bool>"),
623623
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicBool` instead",
624624
),
625625
on(
626-
_Self = "std::cell::Cell<T>",
626+
any(_Self = "core::cell::Cell<T>", _Self = "std::cell::Cell<T>"),
627627
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock`",
628628
),
629629
on(
630-
_Self = "std::cell::RefCell<T>",
630+
any(_Self = "core::cell::RefCell<T>", _Self = "std::cell::RefCell<T>"),
631631
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` instead",
632632
),
633633
message = "`{Self}` cannot be shared between threads safely",

library/core/src/ops/index.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#ind
153153
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>"
154154
),
155155
on(
156-
_Self = "std::string::String",
156+
any(_Self = "alloc::string::String", _Self = "std::string::String"),
157157
note = "you can use `.chars().nth()` or `.bytes().nth()`
158158
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>"
159159
),

library/core/src/ops/try_trait.rs

+36-9
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,14 @@ pub trait Try: FromResidual {
226226
on(
227227
all(
228228
from_desugaring = "QuestionMark",
229-
_Self = "std::result::Result<T, E>",
230-
R = "std::option::Option<std::convert::Infallible>"
229+
any(
230+
_Self = "core::result::Result<T, E>",
231+
_Self = "std::result::Result<T, E>",
232+
),
233+
any(
234+
R = "core::option::Option<core::convert::Infallible>",
235+
R = "std::option::Option<std::convert::Infallible>",
236+
)
231237
),
232238
message = "the `?` operator can only be used on `Result`s, not `Option`s, \
233239
in {ItemContext} that returns `Result`",
@@ -237,7 +243,10 @@ pub trait Try: FromResidual {
237243
on(
238244
all(
239245
from_desugaring = "QuestionMark",
240-
_Self = "std::result::Result<T, E>",
246+
any(
247+
_Self = "core::result::Result<T, E>",
248+
_Self = "std::result::Result<T, E>",
249+
)
241250
),
242251
// There's a special error message in the trait selection code for
243252
// `From` in `?`, so this is not shown for result-in-result errors,
@@ -250,8 +259,14 @@ pub trait Try: FromResidual {
250259
on(
251260
all(
252261
from_desugaring = "QuestionMark",
253-
_Self = "std::option::Option<T>",
254-
R = "std::result::Result<T, E>",
262+
any(
263+
_Self = "core::option::Option<T>",
264+
_Self = "std::option::Option<T>",
265+
),
266+
any(
267+
R = "core::result::Result<T, E>",
268+
R = "std::result::Result<T, E>",
269+
)
255270
),
256271
message = "the `?` operator can only be used on `Option`s, not `Result`s, \
257272
in {ItemContext} that returns `Option`",
@@ -261,7 +276,10 @@ pub trait Try: FromResidual {
261276
on(
262277
all(
263278
from_desugaring = "QuestionMark",
264-
_Self = "std::option::Option<T>",
279+
any(
280+
_Self = "core::option::Option<T>",
281+
_Self = "std::option::Option<T>",
282+
)
265283
),
266284
// `Option`-in-`Option` always works, as there's only one possible
267285
// residual, so this can also be phrased strongly.
@@ -273,8 +291,14 @@ pub trait Try: FromResidual {
273291
on(
274292
all(
275293
from_desugaring = "QuestionMark",
276-
_Self = "std::ops::ControlFlow<B, C>",
277-
R = "std::ops::ControlFlow<B, C>",
294+
any(
295+
_Self = "core::ops::ControlFlow<B, C>",
296+
_Self = "std::ops::ControlFlow<B, C>",
297+
),
298+
any(
299+
R = "core::ops::ControlFlow<B, C>",
300+
R = "std::ops::ControlFlow<B, C>",
301+
)
278302
),
279303
message = "the `?` operator in {ItemContext} that returns `ControlFlow<B, _>` \
280304
can only be used on other `ControlFlow<B, _>`s (with the same Break type)",
@@ -285,7 +309,10 @@ pub trait Try: FromResidual {
285309
on(
286310
all(
287311
from_desugaring = "QuestionMark",
288-
_Self = "std::ops::ControlFlow<B, C>",
312+
any(
313+
_Self = "core::ops::ControlFlow<B, C>",
314+
_Self = "std::ops::ControlFlow<B, C>",
315+
)
289316
// `R` is not a `ControlFlow`, as that case was matched previously
290317
),
291318
message = "the `?` operator can only be used on `ControlFlow`s \

library/core/src/slice/index.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ mod private_slice_index {
152152
#[rustc_on_unimplemented(
153153
on(T = "str", label = "string indices are ranges of `usize`",),
154154
on(
155-
all(any(T = "str", T = "&str", T = "std::string::String"), _Self = "{integer}"),
155+
all(
156+
any(T = "str", T = "&str", T = "alloc::string::String", T = "std::string::String"),
157+
_Self = "{integer}"
158+
),
156159
note = "you can use `.chars().nth()` or `.bytes().nth()`\n\
157160
for more information, see chapter 8 in The Book: \
158161
<https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>"

0 commit comments

Comments
 (0)