Skip to content

Commit 9360e9a

Browse files
authored
Unrolled build for rust-lang#116805
Rollup merge of rust-lang#116805 - Nilstrieb:onunimplemented-std-core-alloc-whatever-who-cares, r=compiler-errors Make `rustc_onunimplemented` export path agnostic This makes it so that all the matchers that match against paths use the definition path instead of the export path. This removes all duplication around `std`/`alloc`/`core`. This is not necessarily optimal because we now depend on internal implementation details like `core::ops::control_flow::ControlFlow`, which is not very nice and probably not acceptable for a stable `on_unimplemented`. An alternative would be to just string-replace normalize away `alloc`/`core` to `std` as a special case, keeping the export paths but making it so that we're still fully standard library flavor agnostic. Looking at the diff, I'm starting to think that some simple string replacement would go a long way towards fixing the problem of duplication while keeping export paths... What do you prefer? Also `@weiznich` for your thoughts about the stable version. r? compiler-errors
2 parents 49691b1 + 414135d commit 9360e9a

File tree

7 files changed

+37
-64
lines changed

7 files changed

+37
-64
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
180180
flags.push((sym::cause, Some("MainFunctionType".to_string())));
181181
}
182182

183-
// Add all types without trimmed paths.
184-
ty::print::with_no_trimmed_paths!({
183+
// Add all types without trimmed paths or visible paths, ensuring they end up with
184+
// their "canonical" def path.
185+
ty::print::with_no_trimmed_paths!(ty::print::with_no_visible_paths!({
185186
let generics = self.tcx.generics_of(def_id);
186187
let self_ty = trait_ref.self_ty();
187188
// This is also included through the generics list as `Self`,
@@ -296,7 +297,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
296297
{
297298
flags.push((sym::_Self, Some("&[{integral}]".to_owned())));
298299
}
299-
});
300+
}));
300301

301302
if let Ok(Some(command)) = OnUnimplementedDirective::of_item(self.tcx, def_id) {
302303
command.evaluate(self.tcx, trait_ref, &flags)
@@ -578,7 +579,9 @@ impl<'tcx> OnUnimplementedDirective {
578579
Some(tcx.features()),
579580
&mut |cfg| {
580581
let value = cfg.value.map(|v| {
581-
OnUnimplementedFormatString(v).format(tcx, trait_ref, &options_map)
582+
// `with_no_visible_paths` is also used when generating the options,
583+
// so we need to match it here.
584+
ty::print::with_no_visible_paths!(OnUnimplementedFormatString(v).format(tcx, trait_ref, &options_map))
582585
});
583586

584587
options.contains(&(cfg.name, value))

library/core/src/convert/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ pub trait Into<T>: Sized {
573573
#[rustc_diagnostic_item = "From"]
574574
#[stable(feature = "rust1", since = "1.0.0")]
575575
#[rustc_on_unimplemented(on(
576-
all(_Self = "&str", any(T = "alloc::string::String", T = "std::string::String")),
576+
all(_Self = "&str", T = "alloc::string::String"),
577577
note = "to coerce a `{T}` into a `{Self}`, use `&*` as a prefix",
578578
))]
579579
pub trait From<T>: Sized {

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

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

library/core/src/marker.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -573,59 +573,59 @@ impl<T: ?Sized> Copy for &T {}
573573
#[lang = "sync"]
574574
#[rustc_on_unimplemented(
575575
on(
576-
any(_Self = "core::cell:OnceCell<T>", _Self = "std::cell::OnceCell<T>"),
576+
_Self = "core::cell::once::OnceCell<T>",
577577
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::OnceLock` instead"
578578
),
579579
on(
580-
any(_Self = "core::cell::Cell<u8>", _Self = "std::cell::Cell<u8>"),
580+
_Self = "core::cell::Cell<u8>",
581581
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicU8` instead",
582582
),
583583
on(
584-
any(_Self = "core::cell::Cell<u16>", _Self = "std::cell::Cell<u16>"),
584+
_Self = "core::cell::Cell<u16>",
585585
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicU16` instead",
586586
),
587587
on(
588-
any(_Self = "core::cell::Cell<u32>", _Self = "std::cell::Cell<u32>"),
588+
_Self = "core::cell::Cell<u32>",
589589
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicU32` instead",
590590
),
591591
on(
592-
any(_Self = "core::cell::Cell<u64>", _Self = "std::cell::Cell<u64>"),
592+
_Self = "core::cell::Cell<u64>",
593593
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicU64` instead",
594594
),
595595
on(
596-
any(_Self = "core::cell::Cell<usize>", _Self = "std::cell::Cell<usize>"),
596+
_Self = "core::cell::Cell<usize>",
597597
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicUsize` instead",
598598
),
599599
on(
600-
any(_Self = "core::cell::Cell<i8>", _Self = "std::cell::Cell<i8>"),
600+
_Self = "core::cell::Cell<i8>",
601601
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicI8` instead",
602602
),
603603
on(
604-
any(_Self = "core::cell::Cell<i16>", _Self = "std::cell::Cell<i16>"),
604+
_Self = "core::cell::Cell<i16>",
605605
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicI16` instead",
606606
),
607607
on(
608-
any(_Self = "core::cell::Cell<i32>", _Self = "std::cell::Cell<i32>"),
608+
_Self = "core::cell::Cell<i32>",
609609
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicI32` instead",
610610
),
611611
on(
612-
any(_Self = "core::cell::Cell<i64>", _Self = "std::cell::Cell<i64>"),
612+
_Self = "core::cell::Cell<i64>",
613613
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicI64` instead",
614614
),
615615
on(
616-
any(_Self = "core::cell::Cell<isize>", _Self = "std::cell::Cell<isize>"),
616+
_Self = "core::cell::Cell<isize>",
617617
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicIsize` instead",
618618
),
619619
on(
620-
any(_Self = "core::cell::Cell<bool>", _Self = "std::cell::Cell<bool>"),
620+
_Self = "core::cell::Cell<bool>",
621621
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicBool` instead",
622622
),
623623
on(
624-
any(_Self = "core::cell::Cell<T>", _Self = "std::cell::Cell<T>"),
624+
_Self = "core::cell::Cell<T>",
625625
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock`",
626626
),
627627
on(
628-
any(_Self = "core::cell::RefCell<T>", _Self = "std::cell::RefCell<T>"),
628+
_Self = "core::cell::RefCell<T>",
629629
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` instead",
630630
),
631631
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-
any(_Self = "alloc::string::String", _Self = "std::string::String"),
156+
_Self = "alloc::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

+9-36
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,8 @@ pub trait Try: FromResidual {
226226
on(
227227
all(
228228
from_desugaring = "QuestionMark",
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-
)
229+
_Self = "core::result::Result<T, E>",
230+
R = "core::option::Option<core::convert::Infallible>",
237231
),
238232
message = "the `?` operator can only be used on `Result`s, not `Option`s, \
239233
in {ItemContext} that returns `Result`",
@@ -243,10 +237,7 @@ pub trait Try: FromResidual {
243237
on(
244238
all(
245239
from_desugaring = "QuestionMark",
246-
any(
247-
_Self = "core::result::Result<T, E>",
248-
_Self = "std::result::Result<T, E>",
249-
)
240+
_Self = "core::result::Result<T, E>",
250241
),
251242
// There's a special error message in the trait selection code for
252243
// `From` in `?`, so this is not shown for result-in-result errors,
@@ -259,14 +250,8 @@ pub trait Try: FromResidual {
259250
on(
260251
all(
261252
from_desugaring = "QuestionMark",
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-
)
253+
_Self = "core::option::Option<T>",
254+
R = "core::result::Result<T, E>",
270255
),
271256
message = "the `?` operator can only be used on `Option`s, not `Result`s, \
272257
in {ItemContext} that returns `Option`",
@@ -276,10 +261,7 @@ pub trait Try: FromResidual {
276261
on(
277262
all(
278263
from_desugaring = "QuestionMark",
279-
any(
280-
_Self = "core::option::Option<T>",
281-
_Self = "std::option::Option<T>",
282-
)
264+
_Self = "core::option::Option<T>",
283265
),
284266
// `Option`-in-`Option` always works, as there's only one possible
285267
// residual, so this can also be phrased strongly.
@@ -291,14 +273,8 @@ pub trait Try: FromResidual {
291273
on(
292274
all(
293275
from_desugaring = "QuestionMark",
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-
)
276+
_Self = "core::ops::control_flow::ControlFlow<B, C>",
277+
R = "core::ops::control_flow::ControlFlow<B, C>",
302278
),
303279
message = "the `?` operator in {ItemContext} that returns `ControlFlow<B, _>` \
304280
can only be used on other `ControlFlow<B, _>`s (with the same Break type)",
@@ -309,10 +285,7 @@ pub trait Try: FromResidual {
309285
on(
310286
all(
311287
from_desugaring = "QuestionMark",
312-
any(
313-
_Self = "core::ops::ControlFlow<B, C>",
314-
_Self = "std::ops::ControlFlow<B, C>",
315-
)
288+
_Self = "core::ops::control_flow::ControlFlow<B, C>",
316289
// `R` is not a `ControlFlow`, as that case was matched previously
317290
),
318291
message = "the `?` operator can only be used on `ControlFlow`s \

library/core/src/slice/index.rs

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

0 commit comments

Comments
 (0)