Skip to content

Commit 8dd40b1

Browse files
Rollup merge of rust-lang#119216 - weiznich:use_diagnostic_namespace_in_stdlib, r=compiler-errors
Use diagnostic namespace in stdlib This required a minor fix to have the diagnostics shown in third party crates when the `diagnostic_namespace` feature is not enabled. See rust-lang@5d63f5d for details. I've opted for having a single PR for both changes as it's really not that much code. If it is required it should be easy to split up the change into several PR's. r? ``@compiler-errors``
2 parents bacddd3 + 54967d7 commit 8dd40b1

File tree

14 files changed

+80
-33
lines changed

14 files changed

+80
-33
lines changed

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ impl<'tcx> OnUnimplementedDirective {
521521
pub fn of_item(tcx: TyCtxt<'tcx>, item_def_id: DefId) -> Result<Option<Self>, ErrorGuaranteed> {
522522
if let Some(attr) = tcx.get_attr(item_def_id, sym::rustc_on_unimplemented) {
523523
return Self::parse_attribute(attr, false, tcx, item_def_id);
524-
} else if tcx.features().diagnostic_namespace {
524+
} else {
525525
tcx.get_attrs_by_path(item_def_id, &[sym::diagnostic, sym::on_unimplemented])
526526
.filter_map(|attr| Self::parse_attribute(attr, true, tcx, item_def_id).transpose())
527527
.try_fold(None, |aggr: Option<Self>, directive| {
@@ -592,8 +592,6 @@ impl<'tcx> OnUnimplementedDirective {
592592
Ok(Some(directive))
593593
}
594594
})
595-
} else {
596-
Ok(None)
597595
}
598596
}
599597

library/core/src/future/future.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::task::{Context, Poll};
2828
#[must_use = "futures do nothing unless you `.await` or poll them"]
2929
#[stable(feature = "futures_api", since = "1.36.0")]
3030
#[lang = "future_trait"]
31-
#[rustc_on_unimplemented(
31+
#[diagnostic::on_unimplemented(
3232
label = "`{Self}` is not a future",
3333
message = "`{Self}` is not a future",
3434
note = "{Self} must be a future or must implement `IntoFuture` to be awaited"

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@
217217
#![feature(const_trait_impl)]
218218
#![feature(decl_macro)]
219219
#![feature(deprecated_suggestion)]
220+
#![feature(diagnostic_namespace)]
220221
#![feature(doc_cfg)]
221222
#![feature(doc_cfg_hide)]
222223
#![feature(doc_notable_trait)]

library/core/src/marker.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ macro marker_impls {
7575
/// [ub]: ../../reference/behavior-considered-undefined.html
7676
#[stable(feature = "rust1", since = "1.0.0")]
7777
#[cfg_attr(not(test), rustc_diagnostic_item = "Send")]
78-
#[rustc_on_unimplemented(
78+
#[diagnostic::on_unimplemented(
7979
message = "`{Self}` cannot be sent between threads safely",
8080
label = "`{Self}` cannot be sent between threads safely"
8181
)]
@@ -134,7 +134,7 @@ unsafe impl<T: Sync + ?Sized> Send for &T {}
134134
#[doc(alias = "?", alias = "?Sized")]
135135
#[stable(feature = "rust1", since = "1.0.0")]
136136
#[lang = "sized"]
137-
#[rustc_on_unimplemented(
137+
#[diagnostic::on_unimplemented(
138138
message = "the size for values of type `{Self}` cannot be known at compilation time",
139139
label = "doesn't have a size known at compile-time"
140140
)]
@@ -205,7 +205,7 @@ pub trait Unsize<T: ?Sized> {
205205
/// [RFC1445]: https://github.com/rust-lang/rfcs/blob/master/text/1445-restrict-constants-in-patterns.md
206206
/// [issue 63438]: https://github.com/rust-lang/rust/issues/63438
207207
#[unstable(feature = "structural_match", issue = "31434")]
208-
#[rustc_on_unimplemented(message = "the type `{Self}` does not `#[derive(PartialEq)]`")]
208+
#[diagnostic::on_unimplemented(message = "the type `{Self}` does not `#[derive(PartialEq)]`")]
209209
#[lang = "structural_peq"]
210210
pub trait StructuralPartialEq {
211211
// Empty.
@@ -273,7 +273,7 @@ marker_impls! {
273273
/// of the two derives (`#[derive(PartialEq)]` and `#[derive(Eq)]`) and check
274274
/// that both of them are present as part of structural-match checking.
275275
#[unstable(feature = "structural_match", issue = "31434")]
276-
#[rustc_on_unimplemented(message = "the type `{Self}` does not `#[derive(Eq)]`")]
276+
#[diagnostic::on_unimplemented(message = "the type `{Self}` does not `#[derive(Eq)]`")]
277277
#[lang = "structural_teq"]
278278
pub trait StructuralEq {
279279
// Empty.
@@ -941,7 +941,7 @@ marker_impls! {
941941
/// [Pin]: crate::pin::Pin
942942
/// [`pin` module]: crate::pin
943943
#[stable(feature = "pin", since = "1.33.0")]
944-
#[rustc_on_unimplemented(
944+
#[diagnostic::on_unimplemented(
945945
note = "consider using the `pin!` macro\nconsider using `Box::pin` if you need to access the pinned value outside of the current scope",
946946
message = "`{Self}` cannot be unpinned"
947947
)]
@@ -989,7 +989,7 @@ pub trait Destruct {}
989989
/// for any user type.
990990
#[unstable(feature = "tuple_trait", issue = "none")]
991991
#[lang = "tuple_trait"]
992-
#[rustc_on_unimplemented(message = "`{Self}` is not a tuple")]
992+
#[diagnostic::on_unimplemented(message = "`{Self}` is not a tuple")]
993993
#[rustc_deny_explicit_impl(implement_via_object = false)]
994994
pub trait Tuple {}
995995

@@ -999,7 +999,7 @@ pub trait Tuple {}
999999
/// `*const ()` automatically implement this trait.
10001000
#[unstable(feature = "pointer_like_trait", issue = "none")]
10011001
#[lang = "pointer_like"]
1002-
#[rustc_on_unimplemented(
1002+
#[diagnostic::on_unimplemented(
10031003
message = "`{Self}` needs to have the same ABI as a pointer",
10041004
label = "`{Self}` needs to be a pointer-like type"
10051005
)]
@@ -1013,7 +1013,7 @@ pub trait PointerLike {}
10131013
/// are `StructuralPartialEq`.
10141014
#[lang = "const_param_ty"]
10151015
#[unstable(feature = "adt_const_params", issue = "95174")]
1016-
#[rustc_on_unimplemented(message = "`{Self}` can't be used as a const parameter type")]
1016+
#[diagnostic::on_unimplemented(message = "`{Self}` can't be used as a const parameter type")]
10171017
#[allow(multiple_supertrait_upcastable)]
10181018
pub trait ConstParamTy: StructuralEq + StructuralPartialEq + Eq {}
10191019

library/core/src/ops/arith.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ sub_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
307307
/// ```
308308
#[lang = "mul"]
309309
#[stable(feature = "rust1", since = "1.0.0")]
310-
#[rustc_on_unimplemented(
310+
#[diagnostic::on_unimplemented(
311311
message = "cannot multiply `{Self}` by `{Rhs}`",
312312
label = "no implementation for `{Self} * {Rhs}`"
313313
)]
@@ -441,7 +441,7 @@ mul_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
441441
/// ```
442442
#[lang = "div"]
443443
#[stable(feature = "rust1", since = "1.0.0")]
444-
#[rustc_on_unimplemented(
444+
#[diagnostic::on_unimplemented(
445445
message = "cannot divide `{Self}` by `{Rhs}`",
446446
label = "no implementation for `{Self} / {Rhs}`"
447447
)]
@@ -543,7 +543,7 @@ div_impl_float! { f32 f64 }
543543
/// ```
544544
#[lang = "rem"]
545545
#[stable(feature = "rust1", since = "1.0.0")]
546-
#[rustc_on_unimplemented(
546+
#[diagnostic::on_unimplemented(
547547
message = "cannot calculate the remainder of `{Self}` divided by `{Rhs}`",
548548
label = "no implementation for `{Self} % {Rhs}`"
549549
)]
@@ -729,7 +729,7 @@ neg_impl! { isize i8 i16 i32 i64 i128 f32 f64 }
729729
/// ```
730730
#[lang = "add_assign"]
731731
#[stable(feature = "op_assign_traits", since = "1.8.0")]
732-
#[rustc_on_unimplemented(
732+
#[diagnostic::on_unimplemented(
733733
message = "cannot add-assign `{Rhs}` to `{Self}`",
734734
label = "no implementation for `{Self} += {Rhs}`"
735735
)]
@@ -796,7 +796,7 @@ add_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
796796
/// ```
797797
#[lang = "sub_assign"]
798798
#[stable(feature = "op_assign_traits", since = "1.8.0")]
799-
#[rustc_on_unimplemented(
799+
#[diagnostic::on_unimplemented(
800800
message = "cannot subtract-assign `{Rhs}` from `{Self}`",
801801
label = "no implementation for `{Self} -= {Rhs}`"
802802
)]
@@ -854,7 +854,7 @@ sub_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
854854
/// ```
855855
#[lang = "mul_assign"]
856856
#[stable(feature = "op_assign_traits", since = "1.8.0")]
857-
#[rustc_on_unimplemented(
857+
#[diagnostic::on_unimplemented(
858858
message = "cannot multiply-assign `{Self}` by `{Rhs}`",
859859
label = "no implementation for `{Self} *= {Rhs}`"
860860
)]
@@ -912,7 +912,7 @@ mul_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
912912
/// ```
913913
#[lang = "div_assign"]
914914
#[stable(feature = "op_assign_traits", since = "1.8.0")]
915-
#[rustc_on_unimplemented(
915+
#[diagnostic::on_unimplemented(
916916
message = "cannot divide-assign `{Self}` by `{Rhs}`",
917917
label = "no implementation for `{Self} /= {Rhs}`"
918918
)]
@@ -973,7 +973,7 @@ div_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
973973
/// ```
974974
#[lang = "rem_assign"]
975975
#[stable(feature = "op_assign_traits", since = "1.8.0")]
976-
#[rustc_on_unimplemented(
976+
#[diagnostic::on_unimplemented(
977977
message = "cannot calculate and assign the remainder of `{Self}` divided by `{Rhs}`",
978978
label = "no implementation for `{Self} %= {Rhs}`"
979979
)]

library/core/src/ops/bit.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl Not for ! {
137137
#[lang = "bitand"]
138138
#[doc(alias = "&")]
139139
#[stable(feature = "rust1", since = "1.0.0")]
140-
#[rustc_on_unimplemented(
140+
#[diagnostic::on_unimplemented(
141141
message = "no implementation for `{Self} & {Rhs}`",
142142
label = "no implementation for `{Self} & {Rhs}`"
143143
)]
@@ -237,7 +237,7 @@ bitand_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
237237
#[lang = "bitor"]
238238
#[doc(alias = "|")]
239239
#[stable(feature = "rust1", since = "1.0.0")]
240-
#[rustc_on_unimplemented(
240+
#[diagnostic::on_unimplemented(
241241
message = "no implementation for `{Self} | {Rhs}`",
242242
label = "no implementation for `{Self} | {Rhs}`"
243243
)]
@@ -337,7 +337,7 @@ bitor_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
337337
#[lang = "bitxor"]
338338
#[doc(alias = "^")]
339339
#[stable(feature = "rust1", since = "1.0.0")]
340-
#[rustc_on_unimplemented(
340+
#[diagnostic::on_unimplemented(
341341
message = "no implementation for `{Self} ^ {Rhs}`",
342342
label = "no implementation for `{Self} ^ {Rhs}`"
343343
)]
@@ -436,7 +436,7 @@ bitxor_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
436436
#[lang = "shl"]
437437
#[doc(alias = "<<")]
438438
#[stable(feature = "rust1", since = "1.0.0")]
439-
#[rustc_on_unimplemented(
439+
#[diagnostic::on_unimplemented(
440440
message = "no implementation for `{Self} << {Rhs}`",
441441
label = "no implementation for `{Self} << {Rhs}`"
442442
)]
@@ -554,7 +554,7 @@ shl_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 isize i128 }
554554
#[lang = "shr"]
555555
#[doc(alias = ">>")]
556556
#[stable(feature = "rust1", since = "1.0.0")]
557-
#[rustc_on_unimplemented(
557+
#[diagnostic::on_unimplemented(
558558
message = "no implementation for `{Self} >> {Rhs}`",
559559
label = "no implementation for `{Self} >> {Rhs}`"
560560
)]
@@ -681,7 +681,7 @@ shr_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize }
681681
#[lang = "bitand_assign"]
682682
#[doc(alias = "&=")]
683683
#[stable(feature = "op_assign_traits", since = "1.8.0")]
684-
#[rustc_on_unimplemented(
684+
#[diagnostic::on_unimplemented(
685685
message = "no implementation for `{Self} &= {Rhs}`",
686686
label = "no implementation for `{Self} &= {Rhs}`"
687687
)]
@@ -752,7 +752,7 @@ bitand_assign_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
752752
#[lang = "bitor_assign"]
753753
#[doc(alias = "|=")]
754754
#[stable(feature = "op_assign_traits", since = "1.8.0")]
755-
#[rustc_on_unimplemented(
755+
#[diagnostic::on_unimplemented(
756756
message = "no implementation for `{Self} |= {Rhs}`",
757757
label = "no implementation for `{Self} |= {Rhs}`"
758758
)]
@@ -823,7 +823,7 @@ bitor_assign_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
823823
#[lang = "bitxor_assign"]
824824
#[doc(alias = "^=")]
825825
#[stable(feature = "op_assign_traits", since = "1.8.0")]
826-
#[rustc_on_unimplemented(
826+
#[diagnostic::on_unimplemented(
827827
message = "no implementation for `{Self} ^= {Rhs}`",
828828
label = "no implementation for `{Self} ^= {Rhs}`"
829829
)]
@@ -892,7 +892,7 @@ bitxor_assign_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
892892
#[lang = "shl_assign"]
893893
#[doc(alias = "<<=")]
894894
#[stable(feature = "op_assign_traits", since = "1.8.0")]
895-
#[rustc_on_unimplemented(
895+
#[diagnostic::on_unimplemented(
896896
message = "no implementation for `{Self} <<= {Rhs}`",
897897
label = "no implementation for `{Self} <<= {Rhs}`"
898898
)]
@@ -974,7 +974,7 @@ shl_assign_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize }
974974
#[lang = "shr_assign"]
975975
#[doc(alias = ">>=")]
976976
#[stable(feature = "op_assign_traits", since = "1.8.0")]
977-
#[rustc_on_unimplemented(
977+
#[diagnostic::on_unimplemented(
978978
message = "no implementation for `{Self} >>= {Rhs}`",
979979
label = "no implementation for `{Self} >>= {Rhs}`"
980980
)]

library/core/src/ops/index.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
/// assert_eq!(nucleotide_count[Nucleotide::T], 12);
4848
/// ```
4949
#[lang = "index"]
50-
#[rustc_on_unimplemented(
50+
#[diagnostic::on_unimplemented(
5151
message = "the type `{Self}` cannot be indexed by `{Idx}`",
5252
label = "`{Self}` cannot be indexed by `{Idx}`"
5353
)]

library/core/src/panic/unwind_safe.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ use crate::task::{Context, Poll};
8383
/// implemented for any closed over variables passed to `catch_unwind`.
8484
#[stable(feature = "catch_unwind", since = "1.9.0")]
8585
#[cfg_attr(not(test), rustc_diagnostic_item = "unwind_safe_trait")]
86-
#[rustc_on_unimplemented(
86+
#[diagnostic::on_unimplemented(
8787
message = "the type `{Self}` may not be safely transferred across an unwind boundary",
8888
label = "`{Self}` may not be safely transferred across an unwind boundary"
8989
)]
@@ -99,7 +99,7 @@ pub auto trait UnwindSafe {}
9999
/// [`UnwindSafe`] trait, for more information see that documentation.
100100
#[stable(feature = "catch_unwind", since = "1.9.0")]
101101
#[cfg_attr(not(test), rustc_diagnostic_item = "ref_unwind_safe_trait")]
102-
#[rustc_on_unimplemented(
102+
#[diagnostic::on_unimplemented(
103103
message = "the type `{Self}` may contain interior mutability and a reference may not be safely \
104104
transferrable across a catch_unwind boundary",
105105
label = "`{Self}` may contain interior mutability and a reference may not be safely \

tests/rustdoc/synthetic_auto/no-redundancy.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// FIXME(fmease, #119216): Reenable this test!
2+
// ignore-test
3+
14
pub struct Inner<T> {
25
field: T,
36
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![feature(diagnostic_namespace)]
2+
3+
#[diagnostic::on_unimplemented(
4+
message = "Message",
5+
note = "Note",
6+
label = "label"
7+
)]
8+
pub trait Foo {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// aux-build:other.rs
2+
3+
extern crate other;
4+
5+
use other::Foo;
6+
7+
fn take_foo(_: impl Foo) {}
8+
9+
fn main() {
10+
take_foo(());
11+
//~^ERROR Message
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0277]: Message
2+
--> $DIR/error_is_shown_in_downstream_crates.rs:10:14
3+
|
4+
LL | take_foo(());
5+
| -------- ^^ label
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
= help: the trait `Foo` is not implemented for `()`
10+
= note: Note
11+
note: required by a bound in `take_foo`
12+
--> $DIR/error_is_shown_in_downstream_crates.rs:7:21
13+
|
14+
LL | fn take_foo(_: impl Foo) {}
15+
| ^^^ required by this bound in `take_foo`
16+
17+
error: aborting due to 1 previous error
18+
19+
For more information about this error, try `rustc --explain E0277`.

tests/ui/proc-macro/meta-macro-hygiene.stdout

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ crate0::{{expn1}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt:
5050
crate0::{{expn2}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "produce_it")
5151
crate0::{{expn3}}: parent: crate0::{{expn2}}, call_site_ctxt: #3, def_site_ctxt: #0, kind: Macro(Bang, "meta_macro::print_def_site")
5252
crate0::{{expn4}}: parent: crate0::{{expn3}}, call_site_ctxt: #4, def_site_ctxt: #0, kind: Macro(Bang, "$crate::dummy")
53+
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "diagnostic::on_unimplemented")
54+
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "diagnostic::on_unimplemented")
55+
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "diagnostic::on_unimplemented")
5356
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
5457
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
5558
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "include")

tests/ui/proc-macro/nonterminal-token-hygiene.stdout

+3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ crate0::{{expn1}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt:
7373
crate0::{{expn2}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "outer")
7474
crate0::{{expn3}}: parent: crate0::{{expn2}}, call_site_ctxt: #3, def_site_ctxt: #3, kind: Macro(Bang, "inner")
7575
crate0::{{expn4}}: parent: crate0::{{expn3}}, call_site_ctxt: #5, def_site_ctxt: #0, kind: Macro(Bang, "print_bang")
76+
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "diagnostic::on_unimplemented")
77+
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "diagnostic::on_unimplemented")
78+
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "diagnostic::on_unimplemented")
7679
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
7780
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Attr, "derive")
7881
crate1::{{expnNNN}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "include")

0 commit comments

Comments
 (0)