1macro_rules!include_example {
2 ($name:literal) => {
3concat!(
4"```rust,compile_fail\n",
5include_str!(concat!("../../../tests/ui/attributes/doc_examples/", $name, ".rs")),
6"```\n",
7"produces:\n",
8" ```text\n",
9include_str!(concat!("../../../tests/ui/attributes/doc_examples/", $name, ".stderr")),
10"```\n",
11 )
12 };
13}
1415#[doc(attribute = "rustc_dump_clauses")]
16/// Dumps the list of [`ty::Clause`]s as computed by the [`clauses_of`] query.
17///
18/// See [`AttributeKind::RustcDumpClauses`] for the internal representation of this attribute.
19///
20/// # Example
21///
22#[doc = "```rust,compile_fail\n//@ dont-require-annotations: ERROR\n//@ compile-flags: --crate-type lib -Z ui-testing=no\n//@ normalize-stderr: \"DefId\\((\\d+):(\\d+)\" -> \"DefId(..:..\"\n//@ normalize-stderr: \"\\[[A-Fa-f0-9]{4}\\]\" -> \"[....]\"\n\n#![feature(negative_impls)]\n#![feature(rustc_attrs)]\n\n#[rustc_dump_clauses]\nfn function<T: Send>(_t: T) {}\n\n#[rustc_dump_clauses]\ntrait Trait: Sync {\n #[rustc_dump_clauses]\n type Assoc;\n}\n\n#[rustc_dump_clauses]\nstruct X<\'a, T: ?Sized, I: Iterator> {\n x: &\'a T,\n y: &\'a I::Item,\n}\n\n#[rustc_dump_clauses]\nimpl<T: ?Sized, I> !Sync for X<\'_, T, I> {}\n```\nproduces:\n ```text\nerror: rustc_dump_clauses\n --> $DIR/rustc_dump_clauses.rs:10:1\n |\n10 | fn function<T: Send>(_t: T) {}\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n |\n = note: Binder { value: TraitClause(<T as std::marker::Sized>, polarity:Positive), bound_vars: [] }\n = note: Binder { value: TraitClause(<T as std::marker::Send>, polarity:Positive), bound_vars: [] }\n\nerror: rustc_dump_clauses\n --> $DIR/rustc_dump_clauses.rs:13:1\n |\n13 | trait Trait: Sync {\n | ^^^^^^^^^^^^^^^^^\n |\n = note: Binder { value: TraitClause(<Self as std::marker::MetaSized>, polarity:Positive), bound_vars: [] }\n = note: Binder { value: TraitClause(<Self as std::marker::Sync>, polarity:Positive), bound_vars: [] }\n = note: Binder { value: TraitClause(<Self as Trait>, polarity:Positive), bound_vars: [] }\n\nerror: rustc_dump_clauses\n --> $DIR/rustc_dump_clauses.rs:19:1\n |\n19 | struct X<\'a, T: ?Sized, I: Iterator> {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n |\n = note: Binder { value: TraitClause(<T as std::marker::MetaSized>, polarity:Positive), bound_vars: [] }\n = note: Binder { value: TraitClause(<I as std::marker::Sized>, polarity:Positive), bound_vars: [] }\n = note: Binder { value: TraitClause(<I as std::iter::Iterator>, polarity:Positive), bound_vars: [] }\n = note: Binder { value: OutlivesClause(T/#1, \'a/#0), bound_vars: [] }\n = note: Binder { value: OutlivesClause(Alias(No, Alias { kind: Projection { def_id: DefId(..:.. ~ core[....]::iter::traits::iterator::Iterator::Item) }, args: [I/#2], .. }), \'a/#0), bound_vars: [] }\n\nerror: rustc_dump_clauses\n --> $DIR/rustc_dump_clauses.rs:25:1\n |\n25 | impl<T: ?Sized, I> !Sync for X<\'_, T, I> {}\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n |\n = note: Binder { value: TraitClause(<T as std::marker::MetaSized>, polarity:Positive), bound_vars: [] }\n = note: Binder { value: TraitClause(<I as std::marker::Sized>, polarity:Positive), bound_vars: [] }\n\nerror: rustc_dump_clauses\n --> $DIR/rustc_dump_clauses.rs:15:5\n |\n15 | type Assoc;\n | ^^^^^^^^^^\n |\n = note: Binder { value: TraitClause(<Self as std::marker::MetaSized>, polarity:Positive), bound_vars: [] }\n = note: Binder { value: TraitClause(<Self as std::marker::Sync>, polarity:Positive), bound_vars: [] }\n = note: Binder { value: TraitClause(<Self as Trait>, polarity:Positive), bound_vars: [] }\n\nerror: aborting due to 5 previous errors\n\n```\n"include_example!("rustc_dump_clauses")]
23///
24/// # Example: super trait bounds are not elaborated
25///
26#[doc = "```rust,compile_fail\n//@ dont-require-annotations: ERROR\n//@ compile-flags: --crate-type lib -Z ui-testing=no\n\n#![feature(rustc_attrs)]\n\n#[rustc_dump_clauses]\nfn foo<T: Copy>(t: &T) -> T {\n *t\n}\n```\nproduces:\n ```text\nerror: rustc_dump_clauses\n --> $DIR/rustc_dump_clauses_super_trait.rs:7:1\n |\n7 | fn foo<T: Copy>(t: &T) -> T {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n |\n = note: Binder { value: TraitClause(<T as std::marker::Sized>, polarity:Positive), bound_vars: [] }\n = note: Binder { value: TraitClause(<T as std::marker::Copy>, polarity:Positive), bound_vars: [] }\n\nerror: aborting due to 1 previous error\n\n```\n"include_example!("rustc_dump_clauses_super_trait")]
27///
28/// [`clauses_of`]: ../rustc_middle/ty/struct.TyCtxt.html#method.clauses_of
29/// [`ty::Clause`]: ../rustc_middle/ty/struct.Clause.html
30const _: () = ();
3132#[doc(attribute = "rustc_dump_def_parents")]
33/// Dumps the parents of the annotated item and of any anonymous constants contained within it.
34///
35/// See also [`opt_parent`](../rustc_middle/ty/struct.TyCtxt.html#method.opt_parent).
36///
37/// See [`AttributeKind::RustcDumpDefParents`] for the internal representation of this attribute.
38///
39/// # Example
40///
41#[doc = "```rust,compile_fail\n//@ dont-require-annotations: ERROR\n//@ compile-flags: --crate-type lib -Z ui-testing=no\n\n#![feature(rustc_attrs)]\n\nfn parent() {\n #[rustc_dump_def_parents]\n fn child() {}\n}\n\nstruct Struct<const N: usize>;\n\nconst CONST: Struct<42> = Struct::<\n {\n #[rustc_dump_def_parents]\n fn baby() {}\n\n 42\n },\n>;\n```\nproduces:\n ```text\nerror: rustc_dump_def_parents: DefId(0:4 ~ rustc_dump_def_parents[9c2e]::parent::child)\n --> $DIR/rustc_dump_def_parents.rs:8:5\n |\n 8 | fn child() {}\n | ^^^^^^^^^^\n |\nnote: DefId(0:3 ~ rustc_dump_def_parents[9c2e]::parent)\n --> $DIR/rustc_dump_def_parents.rs:6:1\n |\n 6 | fn parent() {\n | ^^^^^^^^^^^\nnote: DefId(0:0 ~ rustc_dump_def_parents[9c2e])\n --> $DIR/rustc_dump_def_parents.rs:4:1\n |\n 4 | / #![feature(rustc_attrs)]\n 5 | |\n 6 | | fn parent() {\n 7 | | #[rustc_dump_def_parents]\n... |\n19 | | },\n20 | | >;\n | |__^\n\nerror: rustc_dump_def_parents: DefId(0:11 ~ rustc_dump_def_parents[9c2e]::CONST::{constant#1}::baby)\n --> $DIR/rustc_dump_def_parents.rs:16:9\n |\n16 | fn baby() {}\n | ^^^^^^^^^\n |\nnote: DefId(0:10 ~ rustc_dump_def_parents[9c2e]::CONST::{constant#1})\n --> $DIR/rustc_dump_def_parents.rs:14:5\n |\n14 | / {\n15 | | #[rustc_dump_def_parents]\n16 | | fn baby() {}\n... |\n19 | | },\n | |_____^\nnote: DefId(0:8 ~ rustc_dump_def_parents[9c2e]::CONST)\n --> $DIR/rustc_dump_def_parents.rs:13:1\n |\n13 | const CONST: Struct<42> = Struct::<\n | ^^^^^^^^^^^^^^^^^^^^^^^\nnote: DefId(0:0 ~ rustc_dump_def_parents[9c2e])\n --> $DIR/rustc_dump_def_parents.rs:4:1\n |\n 4 | / #![feature(rustc_attrs)]\n 5 | |\n 6 | | fn parent() {\n 7 | | #[rustc_dump_def_parents]\n... |\n19 | | },\n20 | | >;\n | |__^\n\nerror: aborting due to 2 previous errors\n\n```\n"include_example!("rustc_dump_def_parents")]
42const _: () = ();
4344#[doc(attribute = "rustc_dump_def_path")]
45/// Dumps the def path of the annotated item.
46///
47/// See also [`def_path_str`] and [`def_path_str_with_args`].
48///
49/// See [`AttributeKind::RustcDumpDefPath`] for the internal representation of this attribute.
50///
51/// # Example
52///
53#[doc = "```rust,compile_fail\n//@ dont-require-annotations: ERROR\n//@ compile-flags: --crate-type lib -Z ui-testing=no\n//@ build-fail\n\n#![feature(rustc_attrs)]\n\n#[rustc_dump_def_path]\nfn main() {\n || {\n unsafe extern \"C\" {\n #[rustc_dump_def_path]\n static Foo: u8;\n }\n };\n}\n\nmod a {\n mod b {\n mod c {\n #[rustc_dump_def_path]\n fn d() {}\n }\n }\n}\n```\nproduces:\n ```text\nerror: def-path(main)\n --> $DIR/rustc_dump_def_path.rs:7:1\n |\n7 | #[rustc_dump_def_path]\n | ^^^^^^^^^^^^^^^^^^^^^^\n\nerror: def-path(a::b::c::d)\n --> $DIR/rustc_dump_def_path.rs:20:13\n |\n20 | #[rustc_dump_def_path]\n | ^^^^^^^^^^^^^^^^^^^^^^\n\nerror: def-path(main::{closure#0}::Foo)\n --> $DIR/rustc_dump_def_path.rs:11:13\n |\n11 | #[rustc_dump_def_path]\n | ^^^^^^^^^^^^^^^^^^^^^^\n\nerror: aborting due to 3 previous errors\n\n```\n"include_example!("rustc_dump_def_path")]
54///
55/// [`def_path_str`]: ../rustc_middle/ty/struct.TyCtxt.html#method.def_path_str
56/// [`def_path_str_with_args`]: ../rustc_middle/ty/struct.TyCtxt.html#method.def_path_str_with_args
57const _: () = ();
5859#[doc(attribute = "rustc_dump_generics")]
60/// Dumps the generics of the annotated item.
61///
62/// See [`generics_of`] and [`ty::Generics`] for what "generics" means here.
63///
64/// See [`AttributeKind::RustcDumpGenerics`] for the internal representation of this attribute.
65///
66/// # Example
67///
68#[doc = "```rust,compile_fail\n//@ dont-require-annotations: ERROR\n//@ compile-flags: --crate-type lib -Z ui-testing=no\n//@ normalize-stderr: \"DefId\\((\\d+):(\\d+)\" -> \"DefId(..:..\"\n//@ normalize-stderr: \"\\[[A-Fa-f0-9]{4}\\]\" -> \"[....]\"\n\n#![feature(rustc_attrs)]\n\n#[rustc_dump_generics]\nstruct Struct<\'lifetime, const CONST: usize, GENERIC> {\n stuff: &\'lifetime [GENERIC; CONST],\n}\n```\nproduces:\n ```text\nerror: rustc_dump_generics: DefId(..:.. ~ rustc_dump_generics[....]::Struct)\n --> $DIR/rustc_dump_generics.rs:9:1\n |\n9 | struct Struct<\'lifetime, const CONST: usize, GENERIC> {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n |\nnote: Generics {\n parent: None,\n parent_count: 0,\n own_params: [\n GenericParamDef {\n name: \"\'lifetime\",\n def_id: DefId(..:.. ~ rustc_dump_generics[....]::Struct::\'lifetime),\n index: 0,\n pure_wrt_drop: false,\n kind: Lifetime,\n },\n GenericParamDef {\n name: \"CONST\",\n def_id: DefId(..:.. ~ rustc_dump_generics[....]::Struct::CONST),\n index: 1,\n pure_wrt_drop: false,\n kind: Const {\n has_default: false,\n },\n },\n GenericParamDef {\n name: \"GENERIC\",\n def_id: DefId(..:.. ~ rustc_dump_generics[....]::Struct::GENERIC),\n index: 2,\n pure_wrt_drop: false,\n kind: Type {\n has_default: false,\n synthetic: false,\n },\n },\n ],\n param_def_id_to_index: [\n (\n DefId(..:.. ~ rustc_dump_generics[....]::Struct::\'lifetime),\n 0,\n ),\n (\n DefId(..:.. ~ rustc_dump_generics[....]::Struct::CONST),\n 1,\n ),\n (\n DefId(..:.. ~ rustc_dump_generics[....]::Struct::GENERIC),\n 2,\n ),\n ],\n has_self: false,\n has_late_bound_regions: None,\n }\n --> $DIR/rustc_dump_generics.rs:9:1\n |\n9 | struct Struct<\'lifetime, const CONST: usize, GENERIC> {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nerror: aborting due to 1 previous error\n\n```\n"include_example!("rustc_dump_generics")]
69///
70/// [`generics_of`]: ../rustc_middle/ty/struct.TyCtxt.html#method.generics_of
71/// [`ty::Generics`]: ../rustc_middle/ty/struct.Generics.html
72const _: () = ();
7374#[doc(attribute = "rustc_dump_hidden_type_of_opaques")]
75/// Dumps the hidden types of the opaque items in this crate.
76///
77/// This ends up calling the [`type_of`] query, which, for opaque types, reveals their hidden types.
78///
79/// See [`AttributeKind::RustcDumpHiddenTypeOfOpaques`] for the internal representation of this attribute.
80///
81/// # Example
82///
83#[doc = "```rust,compile_fail\n//@ dont-require-annotations: ERROR\n//@ compile-flags: --crate-type lib -Z ui-testing=no -Z verbose-internals\n\n#![feature(rustc_attrs)]\n#![rustc_dump_hidden_type_of_opaques]\n\ntrait Foo {\n fn hello(&self) -> impl Sized;\n}\n\nfn hello<\'s, T: Foo>(x: &\'s T) -> impl Sized + use<\'s, T> {\n x.hello()\n}\n```\nproduces:\n ```text\nerror: <T as Foo>::hello::{anon_assoc#0}<\'s/#1>\n --> $DIR/rustc_dump_hidden_type_of_opaques.rs:11:35\n |\n11 | fn hello<\'s, T: Foo>(x: &\'s T) -> impl Sized + use<\'s, T> {\n | ^^^^^^^^^^^^^^^^^^^^^^^\n\nerror: aborting due to 1 previous error\n\n```\n"include_example!("rustc_dump_hidden_type_of_opaques")]
84///
85/// [`type_of`]: ../rustc_middle/ty/struct.TyCtxt.html#method.type_of
86const _: () = ();
8788#[doc(attribute = "rustc_dump_inferred_outlives")]
89/// Dumps the inferred outlives-clauses of the annotated item.
90///
91/// See also the [`inferred_outlives_of`] query.
92///
93/// See [`AttributeKind::RustcDumpInferredOutlives`] for the internal representation of this attribute.
94///
95/// # Example
96///
97#[doc = "```rust,compile_fail\n//@ dont-require-annotations: ERROR\n//@ compile-flags: --crate-type lib -Z ui-testing=no\n\n#![feature(rustc_attrs)]\n\ntrait Trait<\'x, T>\nwhere\n T: \'x,\n{\n type Type;\n}\n\n#[rustc_dump_inferred_outlives]\nstruct Foo<\'a, A, B>\nwhere\n A: Trait<\'a, B>,\n{\n foo: <A as Trait<\'a, B>>::Type,\n}\n```\nproduces:\n ```text\nerror: rustc_dump_inferred_outlives\n --> $DIR/rustc_dump_inferred_outlives.rs:14:1\n |\n14 | struct Foo<\'a, A, B>\n | ^^^^^^^^^^^^^^^^^^^^\n |\n = note: B: \'a\n\nerror: aborting due to 1 previous error\n\n```\n"include_example!("rustc_dump_inferred_outlives")]
98///
99/// [`inferred_outlives_of`]: ../rustc_middle/ty/struct.TyCtxt.html#method.inferred_outlives_of
100const _: () = ();
101102#[doc(attribute = "rustc_dump_item_bounds")]
103/// Dumps the item bounds of the annotated item.
104///
105/// This ends up calling the [`item_bounds`] query and prints the [`ty::Clause`] of the item.
106///
107/// See [`AttributeKind::RustcDumpItemBounds`] for the internal representation of this attribute.
108///
109/// # Example
110///
111#[doc = "```rust,compile_fail\n//@ dont-require-annotations: ERROR\n//@ compile-flags: --crate-type lib -Z ui-testing=no\n\n#![feature(rustc_attrs)]\n\ntrait Trait<T> {\n #[rustc_dump_item_bounds]\n type Assoc: PartialEq<String>;\n}\n```\nproduces:\n ```text\nerror: rustc_dump_item_bounds\n --> $DIR/rustc_dump_item_bounds.rs:8:5\n |\n8 | type Assoc: PartialEq<String>;\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n |\n = note: Binder { value: TraitClause(<<Self as Trait<T>>::Assoc as std::cmp::PartialEq<std::string::String>>, polarity:Positive), bound_vars: [] }\n = note: Binder { value: TraitClause(<<Self as Trait<T>>::Assoc as std::marker::Sized>, polarity:Positive), bound_vars: [] }\n\nerror: aborting due to 1 previous error\n\n```\n"include_example!("rustc_dump_item_bounds")]
112///
113/// [`item_bounds`]: ../rustc_middle/ty/struct.TyCtxt.html#method.item_bounds
114/// [`ty::Clause`]: ../rustc_middle/ty/struct.Clause.html
115const _: () = ();
116117#[doc(attribute = "rustc_dump_layout")]
118/// Dumps the layout of the annotated item.
119///
120/// This ends up calling the [`layout_of`] query to get the [`Layout`] of the annotated item. If used
121/// with the `debug` modifier, it will print the entirety of `Layout`. Other modifiers will print
122/// only parts of it.
123///
124/// See [`AttributeKind::RustcDumpLayout`] for the internal representation of this attribute.
125///
126/// # Example: `debug`
127///
128#[doc = "```rust,compile_fail\n//@ dont-require-annotations: ERROR\n//@ compile-flags: --crate-type lib -Z ui-testing=no\n//@ normalize-stderr: \"randomization_seed: \\d+\" -> \"randomization_seed: $$SEED\"\n\n#![feature(rustc_attrs)]\n\n#[rustc_dump_layout(debug)]\npub union Union {\n Float: f32,\n Int: u32,\n}\n```\nproduces:\n ```text\nerror: layout_of(Union) = Layout {\n size: Size(4 bytes),\n align: AbiAlign {\n abi: Align(4 bytes),\n },\n backend_repr: Memory {\n sized: true,\n },\n fields: Union(\n 2,\n ),\n largest_niche: None,\n uninhabited: false,\n variants: Single {\n index: 0,\n },\n max_repr_align: None,\n unadjusted_abi_align: Align(4 bytes),\n repr_c: false,\n randomization_seed: $SEED,\n }\n --> $DIR/rustc_dump_layout_debug.rs:8:1\n |\n8 | pub union Union {\n | ^^^^^^^^^^^^^^^\n\nerror: aborting due to 1 previous error\n\n```\n"include_example!("rustc_dump_layout_debug")]
129///
130/// # Example: `largest_niche`
131///
132#[doc = "```rust,compile_fail\n//@ dont-require-annotations: ERROR\n//@ compile-flags: --crate-type lib -Z ui-testing=no\n\n#![feature(rustc_attrs)]\n\n#[rustc_dump_layout(largest_niche)]\ntype Alias = Option<char>;\n```\nproduces:\n ```text\nerror: largest_niche: Some(Niche { offset: Size(0 bytes), value: u32, valid_range: (..=1114111) | (4294967295..) })\n --> $DIR/rustc_dump_layout_largest_niche.rs:7:1\n |\n7 | type Alias = Option<char>;\n | ^^^^^^^^^^\n\nerror: aborting due to 1 previous error\n\n```\n"include_example!("rustc_dump_layout_largest_niche")]
133///
134/// # Example: `size`
135///
136#[doc = "```rust,compile_fail\n//@ dont-require-annotations: ERROR\n//@ compile-flags: --crate-type lib -Z ui-testing=no\n\n#![feature(rustc_attrs)]\n\n#[rustc_dump_layout(size)]\ntype ID = std::any::TypeId;\n```\nproduces:\n ```text\nerror: size: Size(16 bytes)\n --> $DIR/rustc_dump_layout_size.rs:7:1\n |\n7 | type ID = std::any::TypeId;\n | ^^^^^^^\n\nerror: aborting due to 1 previous error\n\n```\n"include_example!("rustc_dump_layout_size")]
137///
138/// # Example: `align`
139///
140#[doc = "```rust,compile_fail\n//@ dont-require-annotations: ERROR\n//@ compile-flags: --crate-type lib -Z ui-testing=no\n\n#![feature(rustc_attrs)]\n\n#[rustc_dump_layout(align)]\nenum Enum {\n Bytes([u8; 4]),\n Int(u32),\n}\n```\nproduces:\n ```text\nerror: align: Align(4 bytes)\n --> $DIR/rustc_dump_layout_align.rs:7:1\n |\n7 | enum Enum {\n | ^^^^^^^^^\n\nerror: aborting due to 1 previous error\n\n```\n"include_example!("rustc_dump_layout_align")]
141///
142/// # Example: `backend_repr`
143///
144#[doc = "```rust,compile_fail\n//@ dont-require-annotations: ERROR\n//@ compile-flags: --crate-type lib -Z ui-testing=no\n\n#![feature(rustc_attrs)]\n#![feature(portable_simd)]\n\n#[rustc_dump_layout(backend_repr)]\ntype Simd = std::simd::u32x4;\n```\nproduces:\n ```text\nerror: backend_repr: SimdVector { element: u32 is .., count: BackendLaneCount(4) }\n --> $DIR/rustc_dump_layout_backend_repr.rs:8:1\n |\n8 | type Simd = std::simd::u32x4;\n | ^^^^^^^^^\n\nerror: aborting due to 1 previous error\n\n```\n"include_example!("rustc_dump_layout_backend_repr")]
145///
146/// # Example: `homogeneous_aggregate`
147///
148#[doc = "```rust,compile_fail\n//@ dont-require-annotations: ERROR\n//@ compile-flags: --crate-type lib -Z ui-testing=no\n\n#![feature(rustc_attrs)]\n\n#[rustc_dump_layout(homogeneous_aggregate)]\n#[repr(C)]\nstruct Struct {\n field: [u8; 32],\n unit: (),\n}\n```\nproduces:\n ```text\nerror: homogeneous_aggregate: Ok(Homogeneous(Reg { kind: Integer, size: Size(1 bytes) }))\n --> $DIR/rustc_dump_layout_homogeneous_aggregate.rs:8:1\n |\n8 | struct Struct {\n | ^^^^^^^^^^^^^\n\nerror: aborting due to 1 previous error\n\n```\n"include_example!("rustc_dump_layout_homogeneous_aggregate")]
149///
150/// [`layout_of`]: ../rustc_middle/ty/struct.TyCtxt.html#method.layout_of
151/// [`Layout`]: rustc_abi::Layout
152const _: () = ();
153154#[doc(attribute = "rustc_dump_object_lifetime_defaults")]
155/// Dumps the trait object lifetime defaults induced by the type parameters of the annotated item.
156///
157/// It will dump this information separately for each type parameter of the annotated item.
158///
159/// See also the [`object_lifetime_default`] query.
160///
161/// See [`AttributeKind::RustcDumpObjectLifetimeDefaults`] for the internal representation of this attribute.
162///
163/// # Example
164///
165#[doc = "```rust,compile_fail\n//@ dont-require-annotations: ERROR\n//@ compile-flags: --crate-type lib -Z ui-testing=no\n\n#![feature(rustc_attrs)]\n\n#[rustc_dump_object_lifetime_defaults]\nstruct Ref<\'a, T: \'a>(&\'a T);\n```\nproduces:\n ```text\nerror: \'a\n --> $DIR/rustc_dump_object_lifetime_defaults.rs:7:16\n |\n7 | struct Ref<\'a, T: \'a>(&\'a T);\n | ^\n\nerror: aborting due to 1 previous error\n\n```\n"include_example!("rustc_dump_object_lifetime_defaults")]
166///
167/// [`object_lifetime_default`]: ../rustc_middle/ty/struct.TyCtxt.html#method.object_lifetime_default
168const _: () = ();
169170#[doc(attribute = "rustc_dump_symbol_name")]
171/// Dumps the symbol name of the annotated item, also demangling it if necessary.
172///
173/// See also the [`symbol_name`] query.
174///
175/// See [`AttributeKind::RustcDumpSymbolName`] for the internal representation of this attribute.
176///
177/// # Example
178///
179#[doc = "```rust,compile_fail\n//@ dont-require-annotations: ERROR\n//@ compile-flags: --crate-type lib --crate-name crate_name -Z ui-testing=no\n//@ build-fail\n\n#![feature(rustc_attrs)]\n\n#[rustc_dump_symbol_name]\nfn mangled() {}\n\n#[rustc_dump_symbol_name]\n#[unsafe(no_mangle)]\nfn no_mangle() {}\n\nunsafe extern \"C\" {\n #[rustc_dump_symbol_name]\n fn abort();\n}\n```\nproduces:\n ```text\nerror: symbol-name(_RNvCsCRATE_HASH_10crate_name7mangled)\n --> $DIR/rustc_dump_symbol_name.rs:7:1\n |\n7 | / #[rustc_dump_symbol_name]\n8 | | fn mangled() {}\n | |____________^\n |\n = note: demangling(crate_name[8cfd4c3bf0e8f389]::mangled)\n = note: demangling-alt(crate_name::mangled)\n\nerror: symbol-name(no_mangle)\n --> $DIR/rustc_dump_symbol_name.rs:10:1\n |\n10 | / #[rustc_dump_symbol_name]\n11 | | #[unsafe(no_mangle)]\n12 | | fn no_mangle() {}\n | |______________^\n\nerror: symbol-name(abort)\n --> $DIR/rustc_dump_symbol_name.rs:15:5\n |\n15 | / #[rustc_dump_symbol_name]\n16 | | fn abort();\n | |_______________^\n\nerror: aborting due to 3 previous errors\n\n```\n"include_example!("rustc_dump_symbol_name")]
180///
181/// [`symbol_name`]: ../rustc_middle/ty/struct.TyCtxt.html#method.symbol_name
182const _: () = ();
183184#[doc(attribute = "rustc_dump_variances")]
185/// Dumps the variances of the annotated item.
186///
187/// See also the [`variances_of`] query and [`ty::Variance`].
188///
189/// See [`AttributeKind::RustcDumpVariances`] for the internal representation of this attribute.
190///
191/// # Example
192///
193#[doc = "```rust,compile_fail\n//@ dont-require-annotations: ERROR\n//@ compile-flags: --crate-type lib -Z ui-testing=no\n\n#![feature(rustc_attrs)]\n\n#[rustc_dump_variances]\nstruct Ref<\'a, T> {\n r: &\'a T,\n}\n\n#[rustc_dump_variances]\nstruct RefMut<\'a, T> {\n r: &\'a mut T,\n}\n\n#[rustc_dump_variances]\nstruct CellRef<\'a, T> {\n r: &\'a core::cell::UnsafeCell<T>,\n}\n\n#[rustc_dump_variances]\nfn x<T, U>(_t: T) -> U {\n todo!()\n}\n```\nproduces:\n ```text\nerror: [\'a: +, T: +]\n --> $DIR/rustc_dump_variances.rs:7:1\n |\n7 | struct Ref<\'a, T> {\n | ^^^^^^^^^^^^^^^^^\n\nerror: [\'a: +, T: o]\n --> $DIR/rustc_dump_variances.rs:12:1\n |\n12 | struct RefMut<\'a, T> {\n | ^^^^^^^^^^^^^^^^^^^^\n\nerror: [\'a: +, T: o]\n --> $DIR/rustc_dump_variances.rs:17:1\n |\n17 | struct CellRef<\'a, T> {\n | ^^^^^^^^^^^^^^^^^^^^^\n\nerror: [T: -, U: +]\n --> $DIR/rustc_dump_variances.rs:22:1\n |\n22 | fn x<T, U>(_t: T) -> U {\n | ^^^^^^^^^^^^^^^^^^^^^^\n\nerror: aborting due to 4 previous errors\n\n```\n"include_example!("rustc_dump_variances")]
194///
195/// [`variances_of`]: ../rustc_middle/ty/struct.TyCtxt.html#method.variances_of
196/// [`ty::Variance`]: ../rustc_middle/ty/enum.Variance.html
197const _: () = ();
198199#[doc(attribute = "rustc_dump_variances_of_opaques")]
200/// Dumps the variances of opaque types in this crate.
201///
202/// See also the [`variances_of`] query.
203///
204/// See [`AttributeKind::RustcDumpVariancesOfOpaques`] for the internal representation of this attribute.
205///
206/// # Example
207///
208#[doc = "```rust,compile_fail\n//@ dont-require-annotations: ERROR\n//@ compile-flags: --crate-type lib -Z ui-testing=no\n\n#![feature(rustc_attrs)]\n#![rustc_dump_variances_of_opaques]\n\ntrait Captures<\'a> {}\nimpl<T> Captures<\'_> for T {}\n\nfn not_captured_early<\'a: \'a>() -> impl Sized {}\n\nfn captured_early<\'a: \'a>() -> impl Sized + Captures<\'a> {}\n\nfn not_captured_late<\'a>(_: &\'a ()) -> impl Sized {}\n\nfn captured_late<\'a>(_: &\'a ()) -> impl Sized + Captures<\'a> {}\n```\nproduces:\n ```text\nerror: [\'a: *]\n --> $DIR/rustc_dump_variances_of_opaques.rs:10:36\n |\n10 | fn not_captured_early<\'a: \'a>() -> impl Sized {}\n | ^^^^^^^^^^\n\nerror: [\'a: *, \'a: o]\n --> $DIR/rustc_dump_variances_of_opaques.rs:12:32\n |\n12 | fn captured_early<\'a: \'a>() -> impl Sized + Captures<\'a> {}\n | ^^^^^^^^^^^^^^^^^^^^^^^^^\n\nerror: []\n --> $DIR/rustc_dump_variances_of_opaques.rs:14:40\n |\n14 | fn not_captured_late<\'a>(_: &\'a ()) -> impl Sized {}\n | ^^^^^^^^^^\n\nerror: [\'a: o]\n --> $DIR/rustc_dump_variances_of_opaques.rs:16:36\n |\n16 | fn captured_late<\'a>(_: &\'a ()) -> impl Sized + Captures<\'a> {}\n | ^^^^^^^^^^^^^^^^^^^^^^^^^\n\nerror: aborting due to 4 previous errors\n\n```\n"include_example!("rustc_dump_variances_of_opaques")]
209///
210/// [`variances_of`]: ../rustc_middle/ty/struct.TyCtxt.html#method.variances_of
211const _: () = ();
212213#[doc(attribute = "rustc_dump_vtable")]
214/// Dumps the virtual method table ("vtable") of the annotated item.
215///
216/// See also the [`vtable_entries`] query.
217///
218/// See [`AttributeKind::RustcDumpVtable`] for the internal representation of this attribute.
219///
220/// # Example
221///
222#[doc = "```rust,compile_fail\n//@ dont-require-annotations: ERROR\n//@ compile-flags: --crate-type lib -Z ui-testing=no\n\n#![feature(rustc_attrs)]\n\n#[rustc_dump_vtable]\ntype X = dyn Send;\n\n#[rustc_dump_vtable]\ntype Y = dyn core::any::Any;\n\nstruct C;\n\n#[rustc_dump_vtable]\nimpl Iterator for C {\n type Item = ();\n fn next(&mut self) -> Option<Self::Item> {\n Some(())\n }\n}\n```\nproduces:\n ```text\nerror: vtable entries: [\n MetadataDropInPlace,\n MetadataSize,\n MetadataAlign,\n ]\n --> $DIR/rustc_dump_vtable.rs:7:1\n |\n7 | type X = dyn Send;\n | ^^^^^^\n\nerror: vtable entries: [\n MetadataDropInPlace,\n MetadataSize,\n MetadataAlign,\n Method(<dyn Any as Any>::type_id - shim(reify)),\n ]\n --> $DIR/rustc_dump_vtable.rs:10:1\n |\n10 | type Y = dyn core::any::Any;\n | ^^^^^^\n\nerror: vtable entries: [\n MetadataDropInPlace,\n MetadataSize,\n MetadataAlign,\n Method(<C as Iterator>::next),\n Method(<C as Iterator>::size_hint),\n Method(<C as Iterator>::advance_by),\n Method(<C as Iterator>::nth),\n ]\n --> $DIR/rustc_dump_vtable.rs:15:1\n |\n15 | impl Iterator for C {\n | ^^^^^^^^^^^^^^^^^^^\n\nerror: aborting due to 3 previous errors\n\n```\n"include_example!("rustc_dump_vtable")]
223///
224/// [`vtable_entries`]: ../rustc_middle/ty/struct.TyCtxt.html#method.vtable_entries
225const _: () = ();
226227#[doc(attribute = "rustc_dyn_incompatible_trait", alias = "rustc_do_not_implement_via_object")]
228/// Opts a trait out of [dyn compatibility].
229///
230/// This is useful to reserve the ability to add dyn incompatible supertraits or methods to a trait
231/// in the future and to ensure the soundness of various constructs - see below for more about that.
232///
233/// For example [`Field`], [`FnPtr`], [`Tuple`], [`TransmuteFrom`], [`Sized`] and [`Unsize`] must
234/// be dyn incompatible because these traits describe properties and layouts of types that would
235/// be invalid for trait objects.
236///
237/// While making a trait dyn incompatible can also be done by including a (hidden and/or unstable)
238/// dyn incompatible method in the trait, using `#[rustc_dyn_incompatible_trait]` should be
239/// preferred because it is self-documenting and generates better error messages.
240///
241/// # Example
242///
243#[doc = "```rust,compile_fail\n//@ dont-require-annotations: ERROR\n//@ compile-flags: --crate-type lib -Z ui-testing=no\n#![feature(rustc_attrs)]\n\n#[rustc_dyn_incompatible_trait]\npub trait DynIncompatible {}\n\npub fn f(_x: &dyn DynIncompatible) {}\n```\nproduces:\n ```text\nerror[E0038]: the trait `DynIncompatible` is not dyn compatible\n --> $DIR/rustc_dyn_incompatible_trait.rs:8:15\n |\n8 | pub fn f(_x: &dyn DynIncompatible) {}\n | ^^^^^^^^^^^^^^^^^^^ `DynIncompatible` is not dyn compatible\n |\nnote: for a trait to be dyn compatible it needs to allow building a vtable\n for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>\n --> $DIR/rustc_dyn_incompatible_trait.rs:5:1\n |\n5 | #[rustc_dyn_incompatible_trait]\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...because it opted out of dyn-compatibility\n6 | pub trait DynIncompatible {}\n | --------------- this trait is not dyn compatible...\n\nerror: aborting due to 1 previous error\n\nFor more information about this error, try `rustc --explain E0038`.\n```\n"include_example!("rustc_dyn_incompatible_trait")]
244///
245/// # Unsafe traits and dyn (in)compatibility
246///
247/// [Recall] that a trait object (`dyn Trait`) implements the base trait, its auto traits, and any supertraits of
248/// the base trait. This means that it's possible to run into subtle soundness problems when relying
249/// on the safety contract of a dyn compatible unsafe trait. See the following example:
250///
251// ignore-tidy-odd-backticks
252/// ```should_panic
253#[doc = "//@run-fail\nmod foreign_crate {\n /// # Safety requirements\n ///\n /// If this type also implements `SafeTrait`,\n /// then that implementation must always return `true`.\n pub unsafe trait UnsafeTrait {}\n unsafe impl<T: UnsafeTrait + ?Sized> UnsafeTrait for &T {}\n\n pub trait SafeTrait {\n fn returns_true(&self) -> bool;\n }\n impl<T: SafeTrait + ?Sized> SafeTrait for &T {\n fn returns_true(&self) -> bool {\n (*self).returns_true()\n }\n }\n\n impl SafeTrait for u8 {\n fn returns_true(&self) -> bool {\n true\n }\n }\n /// Safety: impl returns `true`.\n unsafe impl UnsafeTrait for u8 {}\n\n pub fn function(x: impl UnsafeTrait + SafeTrait) {\n // Can\'t panic, after all, `x: UnsafeTrait`\n // guarantees `returns_true` actually returns `true`\n assert!(x.returns_true());\n }\n}\n\nuse foreign_crate::{SafeTrait, UnsafeTrait, function};\n\npub trait LocalTrait: UnsafeTrait {}\nimpl<T: UnsafeTrait> LocalTrait for T {}\n\n// We can do this because `dyn LocalTrait` is a local type.\n// But `LocalTrait: UnsafeTrait`, so `dyn LocalTrait: UnsafeTrait` holds,\n// and we don\'t have to `unsafe impl` it.\nimpl SafeTrait for dyn LocalTrait {\n fn returns_true(&self) -> bool {\n false\n }\n}\n\nfn main() {\n let x = 42_u8;\n let y: &dyn LocalTrait = &x;\n function(y); // panics\n}\n"include_str!("../../../tests/ui/attributes/doc_examples/rustc_dyn_incompatible_trait2.rs")]
254// ignore-tidy-odd-backticks
255/// ```
256///
257/// A solution for this is to make `UnsafeTrait` dyn incompatible, forcing `LocalTrait` to also be
258/// dyn incompatible so that a `dyn LocalTrait` cannot be formed. This is what we ended up doing for
259/// [#154619].
260///
261/// [`Allocator`] has had similar problems with [`Clone`] ([#156920])
262/// but as we really wanted `dyn Allocator` to be a thing we ended up not making it dyn
263/// incompatible -- we ended up moving the safety contract to [`AllocatorClone`] instead.
264///
265/// See also [#156917] and [#160045] for more examples of this problem.
266///
267/// See [`AttributeKind::RustcDynIncompatibleTrait`] for the internal representation of this attribute.
268///
269/// [`Allocator`]: core::alloc::Allocator
270/// [`AllocatorClone`]: core::alloc::AllocatorClone
271/// [`Clone`]: core::clone::Clone
272/// [`Field`]: core::field::Field
273// FIXME: use core::ops::FnPtr once trickled down to beta
274/// [`FnPtr`]: https://doc.rust-lang.org/nightly/core/ops/trait.FnPtr.html
275/// [`Tuple`]: core::marker::Tuple
276/// [`TransmuteFrom`]: core::mem::TransmuteFrom
277/// [`Sized`]: core::marker::Sized
278/// [`Unsize`]: core::marker::Unsize
279/// [dyn compatibility]: https://doc.rust-lang.org/nightly/reference/items/traits.html#dyn-compatibility
280/// [recall]: https://doc.rust-lang.org/nightly/reference/types/trait-object.html#r-type.trait-object.impls
281/// [#154619]: https://github.com/rust-lang/rust/issues/154619 "`deref_patterns` is unsound due to `dyn` of subtrait of `DerefPure`"
282/// [#156917]: https://github.com/rust-lang/rust/issues/156917 "`dyn Allocator` together with `Allocator + PartialEq` safety requirements leads to unsoundness"
283/// [#156920]:https://github.com/rust-lang/rust/issues/156920 "`dyn Allocator` together with `Allocator + Clone` requirements is unsound, leading to UB with `Arc`"
284/// [#160045]:https://github.com/rust-lang/rust/issues/160045 "`iter::Rev`'s `TrustedLen` impl is unsound with trait objects"
285const _: () = ();
286287#[doc(attribute = "rustc_comptime")]
288/// Marks a function as only callable at compile time.
289///
290/// Unlike `const fn`, which *can* be called from a [const context], comptime functions *must* be
291/// called from a const context. It is an error to call a comptime function outside a const context.
292///
293/// # Example
294///
295#[doc = "```rust,compile_fail\n//@ dont-require-annotations: ERROR\n//@ compile-flags: --crate-type lib -Z ui-testing=no\n\n#![feature(rustc_attrs)]\n\n#[rustc_comptime]\nfn comptime() {}\n\nfn from_runtime() {\n comptime(); // ERROR\n\n const { comptime() }; // OK\n}\n\n// comptime functions cannot be called from const\n// functions, as these may be called at runtime\nconst fn const_or_runtime() {\n comptime();\n}\n```\nproduces:\n ```text\nerror: comptime functions can only be called at compile time\n --> $DIR/rustc_comptime.rs:10:5\n |\n10 | comptime(); // ERROR\n | ^^^^^^^^^^\n |\nhelp: wrap the call in a const block to force compile time evaluation\n |\n10 | const { comptime() }; // ERROR\n | +++++++ +\n\nerror: comptime functions can only be called at compile time\n --> $DIR/rustc_comptime.rs:18:5\n |\n18 | comptime();\n | ^^^^^^^^^^\n |\nhelp: wrap the call in a const block to force compile time evaluation\n |\n18 | const { comptime() };\n | +++++++ +\n\nerror: aborting due to 2 previous errors\n\n```\n"include_example!("rustc_comptime")]
296///
297/// There are many things which only have meaning at compile time and can make use of such
298/// functions:
299/// - the [`type_info`] feature, for compile time type reflection.
300/// - the const heap intrinsics [`const_allocate`] and [`const_deallocate`], at runtime, return a null
301/// pointer and do nothing respectively.
302/// - intrinsics such as [`size_of`] and friends cause an ICE when they are called at runtime. The
303/// stabilized versions of these functions forward to these intrinsics via associated constants on
304/// the `SizedTypeProperties` trait.
305///
306/// At this time,
307// < October of 2026 >
308/// the primary motivation for comptime functions is the [`type_info`] feature. The constructs
309/// in [`mem::type_info`] only makes sense at compile time as during compile time we can simply
310/// ask the compiler for whatever information we need. At runtime, though, that cannot be done - to
311/// support runtime reflection we would have to create some global table with all the information
312/// we might possibly need. This is unfeasible and any (third party wrappers for) "runtime
313/// reflection" based on `type_info` would be limited to retrieving information queried in advance
314/// at compile time.
315///
316/// See the [reflection and comptime project goal] for more information about reflection and
317/// comptime.
318///
319/// See [`AttributeKind::RustcComptime`] for the internal representation of this attribute.
320///
321/// [const context]: https://doc.rust-lang.org/nightly/reference/const_eval.html#const-context
322/// [`type_info`]: https://github.com/rust-lang/rust/issues/146922
323/// [`const_allocate`]: std::intrinsics::const_allocate
324/// [`const_deallocate`]: std::intrinsics::const_deallocate
325/// [`mem::type_info`]: std::mem::type_info
326/// [reflection and comptime project goal]: https://goals.rust-lang.org/2026/reflection-and-comptime.html
327const _: () = ();
328329#[doc(attribute = "rustc_on_unimplemented")]
330/// Customize the error message when a trait is not implemented.
331///
332/// It must be used on the declaration of said trait.
333///
334/// # Syntax
335///
336/// ```grammar
337/// RustcOnUnimplementedAttribute ->
338/// rustc_on_unimplemented ( ( Directive ),+ )
339///
340/// Directive ->
341/// on ( Filter, ( DirectiveOption ),+ )
342/// | ( DirectiveOption ),*
343///
344/// DirectiveOption ->
345/// message = STRING_LITERAL
346/// | label = STRING_LITERAL
347/// | note = STRING_LITERAL
348///
349/// Filter ->
350/// FilterAll
351/// | FilterAny
352/// | FilterNot
353/// | FilterOption
354///
355/// FilterAll ->
356/// all ( ( Filter ),* )
357///
358/// FilterAny ->
359/// any ( ( Filter ),* )
360///
361/// FilterNot ->
362/// not ( Filter )
363///
364/// FilterOption ->
365/// crate_local
366/// | direct
367/// | from_desugaring ( = STRING_LITERAL )?
368/// | cause = STRING_LITERAL
369/// | IDENTIFIER = STRING_LITERAL
370///
371/// ```
372///
373/// The following keys have the given meaning. At least one must be specified.
374/// - `on` - filters the application of the attribute. See [#Filters](#filters).
375/// - `message` — The text for the top level error message. May only be specified at most once.
376/// - `label` — The text for the label shown inline in the broken code in the error message.
377/// May only be specified at most once.
378/// - `note` — Provides additional note(s)
379///
380/// `message`, `label`, and `note` are available with the [`diagnostic::on_unimplemented`]
381/// attribute. If possible, use that instead.
382///
383/// # Example
384///
385#[doc = "```rust,compile_fail\n//@ dont-require-annotations: ERROR\n//@ compile-flags: --crate-type lib -Z ui-testing=no\n\n#![feature(rustc_attrs)]\n\n#[rustc_on_unimplemented(\n message = \"cannot add `{Rhs}` to `{Self}`\",\n label = \"no implementation for `{Self} + {Rhs}`\",\n)]\npub trait MyAdd<Rhs = Self> {\n fn add(self, rhs: Rhs) -> Self;\n}\n\nfn main() {\n MyAdd::add(42_u8, 42.0);\n}\n```\nproduces:\n ```text\nerror[E0277]: cannot add `_` to `u8`\n --> $DIR/rustc_on_unimplemented.rs:15:16\n |\n15 | MyAdd::add(42_u8, 42.0);\n | ---------- ^^^^^ no implementation for `u8 + _`\n | |\n | required by a bound introduced by this call\n |\n = help: the trait `MyAdd<_>` is not implemented for `u8`\nhelp: this trait has no implementations, consider adding one\n --> $DIR/rustc_on_unimplemented.rs:10:1\n |\n10 | pub trait MyAdd<Rhs = Self> {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nerror: aborting due to 1 previous error\n\nFor more information about this error, try `rustc --explain E0277`.\n```\n"include_example!("rustc_on_unimplemented")]
386///
387/// # Filters
388///
389/// To allow more targeted error messages, it is possible to filter the
390/// application of these keys with `on`.
391///
392/// You can filter on the following boolean flags:
393/// - `crate_local`: whether the code causing the trait bound to not be
394/// fulfilled is part of the user's crate.
395/// This is used to avoid suggesting code changes that would require modifying a dependency.
396/// - `direct`: whether this is a user-specified rather than derived obligation.
397/// - `from_desugaring`: whether we are in some kind of desugaring, like `?`
398/// or a `try` block for example.
399/// This flag can also be matched on, see below.
400///
401/// You can match on the following names and values, using `name = "value"`:
402/// - `cause`: Match against one variant of the `ObligationCauseCode` enum.
403/// Only `"MainFunctionType"` is supported.
404/// - `from_desugaring`: Match against a particular variant of the `DesugaringKind` enum.
405/// The desugaring is identified by its variant name, for example
406/// `"QuestionMark"` for `?` desugaring, or `"TryBlock"` for `try` blocks.
407/// - `Self` and any generic arguments of the trait, like `Self = "alloc::string::String"`
408/// or `Rhs="i32"`.
409///
410/// The compiler provides several values to match on, for example:
411/// - the self_ty, pretty printed with and without type arguments resolved.
412/// - `"{integral}"`, if self_ty is an integral of which the type is known.
413/// - `"[]"`, `"[{ty}]"`, `"[{ty}; _]"`, `"[{ty}; $N]"` when applicable.
414/// - references to said slices and arrays.
415/// - `"fn"`, `"unsafe fn"` or `"#[target_feature] fn"` when self is a function.
416/// - `"{integer}"` and `"{float}"` if the type is a number but we haven't inferred it yet.
417/// - `"{struct}"`, `"{enum}"` and `"{union}"` to match self as an ADT
418/// - combinations of the above, like `"[{integral}; _]"`.
419///
420#[doc = "```rust,compile_fail\n//@ dont-require-annotations: ERROR\n//@ compile-flags: --crate-type lib -Z ui-testing=no\n\n#![feature(rustc_attrs)]\n\n#[rustc_on_unimplemented(\n on(all(Self = \"{integer}\", Rhs = \"{float}\"), message = \"cannot add a float to an integer\",),\n on(all(Self = \"{float}\", Rhs = \"{integer}\"), message = \"cannot add an integer to a float\",),\n message = \"cannot add `{Rhs}` to `{Self}`\",\n label = \"no implementation for `{Self} + {Rhs}`\"\n)]\npub trait MyAdd<Rhs = Self> {\n fn add(self, rhs: Rhs) -> Self;\n}\n\nfn main() {\n MyAdd::add(42_u8, 42.0);\n}\n```\nproduces:\n ```text\nerror[E0277]: cannot add `_` to `u8`\n --> $DIR/rustc_on_unimplemented_filter.rs:17:16\n |\n17 | MyAdd::add(42_u8, 42.0);\n | ---------- ^^^^^ no implementation for `u8 + _`\n | |\n | required by a bound introduced by this call\n |\n = help: the trait `MyAdd<_>` is not implemented for `u8`\nhelp: this trait has no implementations, consider adding one\n --> $DIR/rustc_on_unimplemented_filter.rs:12:1\n |\n12 | pub trait MyAdd<Rhs = Self> {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nerror: aborting due to 1 previous error\n\nFor more information about this error, try `rustc --explain E0277`.\n```\n"include_example!("rustc_on_unimplemented_filter")]
421///
422/// # Formatting
423///
424/// The string literals are format strings that accept parameters wrapped in braces -
425/// positional and listed parameters are not accepted.
426/// The following parameter names are valid:
427/// - `Self` and all generic parameters of the trait.
428/// - `This`: the name of the trait the attribute is on, without generics.
429/// - `This:path`: the full path of the trait the attribute is on, with unresolved generics.
430/// - `This:resolved`: the full path of the trait the attribute is on, with resolved generics.
431/// Additionally, this will "sugar" the `Fn(...)` traits.
432/// - `ItemContext`: the kind of `hir::Node` we're in, things like `"an async block"`,
433/// `"a function"`, `"an async function"`, etc.
434///
435#[doc = "```rust,compile_fail\n//@ dont-require-annotations: ERROR\n//@ compile-flags: --crate-type lib -Z ui-testing=no\n\n#![feature(rustc_attrs)]\n\n#[rustc_on_unimplemented(message = \"Self = `{Self}`, \\n \\\n T = `{T}`, this = `{This}`, path = `{This:path}`, \\n \\\n resolved = `{This:resolved}`, context = `{ItemContext}`\")]\npub trait From<T>: Sized {\n fn from(x: T) -> Self;\n}\n\nfn main() {\n let x: i8 = From::from(42_i32);\n}\n```\nproduces:\n ```text\nerror[E0277]: Self = `i8`, \n T = `i32`, this = `From`, path = `From<T>`, \n resolved = `From<i32>`, context = `a function`\n --> $DIR/rustc_on_unimplemented_format.rs:14:28\n |\n14 | let x: i8 = From::from(42_i32);\n | ---------- ^^^^^^ the trait `From<i32>` is not implemented for `i8`\n | |\n | required by a bound introduced by this call\n |\nhelp: this trait has no implementations, consider adding one\n --> $DIR/rustc_on_unimplemented_format.rs:9:1\n |\n 9 | pub trait From<T>: Sized {\n | ^^^^^^^^^^^^^^^^^^^^^^^^\n\nerror: aborting due to 1 previous error\n\nFor more information about this error, try `rustc --explain E0277`.\n```\n"include_example!("rustc_on_unimplemented_format")]
436///
437/// [`diagnostic::on_unimplemented`]: https://doc.rust-lang.org/nightly/reference/attributes/diagnostics.html#the-diagnosticon_unimplemented-attribute
438const _: () = ();