Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9ffd0bf

Browse files
committedMay 17, 2025
do away with _Self and TraitName and check generic params for rustc_on_unimplemented
1 parent c9b6ccc commit 9ffd0bf

14 files changed

+152
-138
lines changed
 

‎compiler/rustc_span/src/symbol.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,6 @@ symbols! {
398398
Wrapping,
399399
Yield,
400400
_DECLS,
401-
_Self,
402401
__D,
403402
__H,
404403
__S,

‎compiler/rustc_trait_selection/messages.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ trait_selection_rustc_on_unimplemented_expected_one_predicate_in_not = expected
337337
.label = unexpected quantity of predicates here
338338
trait_selection_rustc_on_unimplemented_invalid_flag = invalid flag in `on`-clause
339339
.label = expected one of the `crate_local`, `direct` or `from_desugaring` flags, not `{$invalid_flag}`
340+
trait_selection_rustc_on_unimplemented_invalid_name = invalid name in `on`-clause
341+
.label = expected one of `cause`, `from_desugaring`, `Self` or any generic parameter of the trait, not `{$invalid_name}`
340342
trait_selection_rustc_on_unimplemented_invalid_predicate = this predicate is invalid
341343
.label = expected one of `any`, `all` or `not` here, not `{$invalid_pred}`
342344
trait_selection_rustc_on_unimplemented_missing_value = this attribute must have a value

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,19 @@ impl<'tcx> OnUnimplementedDirective {
429429
.next()
430430
.ok_or_else(|| tcx.dcx().emit_err(InvalidOnClause::Empty { span }))?;
431431

432-
match OnUnimplementedCondition::parse(cond) {
432+
let generics: Vec<Symbol> = tcx
433+
.generics_of(item_def_id)
434+
.own_params
435+
.iter()
436+
.filter_map(|param| {
437+
if matches!(param.kind, GenericParamDefKind::Lifetime) {
438+
None
439+
} else {
440+
Some(param.name)
441+
}
442+
})
443+
.collect();
444+
match OnUnimplementedCondition::parse(cond, &generics) {
433445
Ok(condition) => Some(condition),
434446
Err(e) => return Err(tcx.dcx().emit_err(e)),
435447
}

‎compiler/rustc_trait_selection/src/error_reporting/traits/on_unimplemented_condition.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ impl OnUnimplementedCondition {
2626
})
2727
}
2828

29-
pub(crate) fn parse(input: &MetaItemInner) -> Result<Self, InvalidOnClause> {
29+
pub(crate) fn parse(
30+
input: &MetaItemInner,
31+
generics: &[Symbol],
32+
) -> Result<Self, InvalidOnClause> {
3033
let span = input.span();
31-
let pred = Predicate::parse(input)?;
34+
let pred = Predicate::parse(input, generics)?;
3235
Ok(OnUnimplementedCondition { span, pred })
3336
}
3437
}
@@ -52,7 +55,7 @@ enum Predicate {
5255
}
5356

5457
impl Predicate {
55-
fn parse(input: &MetaItemInner) -> Result<Self, InvalidOnClause> {
58+
fn parse(input: &MetaItemInner, generics: &[Symbol]) -> Result<Self, InvalidOnClause> {
5659
let meta_item = match input {
5760
MetaItemInner::MetaItem(meta_item) => meta_item,
5861
MetaItemInner::Lit(lit) => {
@@ -69,10 +72,10 @@ impl Predicate {
6972

7073
match meta_item.kind {
7174
MetaItemKind::List(ref mis) => match predicate.name {
72-
sym::any => Ok(Predicate::Any(Predicate::parse_sequence(mis)?)),
73-
sym::all => Ok(Predicate::All(Predicate::parse_sequence(mis)?)),
75+
sym::any => Ok(Predicate::Any(Predicate::parse_sequence(mis, generics)?)),
76+
sym::all => Ok(Predicate::All(Predicate::parse_sequence(mis, generics)?)),
7477
sym::not => match &**mis {
75-
[one] => Ok(Predicate::Not(Box::new(Predicate::parse(one)?))),
78+
[one] => Ok(Predicate::Not(Box::new(Predicate::parse(one, generics)?))),
7679
[first, .., last] => Err(InvalidOnClause::ExpectedOnePredInNot {
7780
span: first.span().to(last.span()),
7881
}),
@@ -83,7 +86,7 @@ impl Predicate {
8386
}
8487
},
8588
MetaItemKind::NameValue(MetaItemLit { symbol, .. }) => {
86-
let name = Name::parse(predicate);
89+
let name = Name::parse(predicate, generics)?;
8790
let value = FilterFormatString::parse(symbol);
8891
let kv = NameValue { name, value };
8992
Ok(Predicate::Match(kv))
@@ -95,8 +98,11 @@ impl Predicate {
9598
}
9699
}
97100

98-
fn parse_sequence(sequence: &[MetaItemInner]) -> Result<Vec<Self>, InvalidOnClause> {
99-
sequence.iter().map(Predicate::parse).collect()
101+
fn parse_sequence(
102+
sequence: &[MetaItemInner],
103+
generics: &[Symbol],
104+
) -> Result<Vec<Self>, InvalidOnClause> {
105+
sequence.iter().map(|item| Predicate::parse(item, generics)).collect()
100106
}
101107

102108
fn eval(&self, eval: &mut impl FnMut(FlagOrNv<'_>) -> bool) -> bool {
@@ -156,14 +162,13 @@ enum Name {
156162
}
157163

158164
impl Name {
159-
fn parse(Ident { name, .. }: Ident) -> Self {
165+
fn parse(Ident { name, span }: Ident, generics: &[Symbol]) -> Result<Self, InvalidOnClause> {
160166
match name {
161-
sym::_Self | kw::SelfUpper => Name::SelfUpper,
162-
sym::from_desugaring => Name::FromDesugaring,
163-
sym::cause => Name::Cause,
164-
// FIXME(mejrs) Perhaps we should start checking that
165-
// this actually is a valid generic parameter?
166-
generic => Name::GenericArg(generic),
167+
kw::SelfUpper => Ok(Name::SelfUpper),
168+
sym::from_desugaring => Ok(Name::FromDesugaring),
169+
sym::cause => Ok(Name::Cause),
170+
generic if generics.contains(&generic) => Ok(Name::GenericArg(generic)),
171+
invalid_name => Err(InvalidOnClause::InvalidName { invalid_name, span }),
167172
}
168173
}
169174
}

‎compiler/rustc_trait_selection/src/error_reporting/traits/on_unimplemented_format.rs

Lines changed: 6 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use std::fmt;
22
use std::ops::Range;
33

44
use errors::*;
5-
use rustc_middle::ty::TyCtxt;
65
use rustc_middle::ty::print::TraitRefPrintSugared;
6+
use rustc_middle::ty::{GenericParamDefKind, TyCtxt};
77
use rustc_parse_format::{
88
Alignment, Argument, Count, FormatSpec, ParseError, ParseMode, Parser, Piece as RpfPiece,
99
Position,
@@ -232,48 +232,16 @@ fn parse_arg<'tcx>(
232232
) -> FormatArg {
233233
let (Ctx::RustcOnUnimplemented { tcx, trait_def_id }
234234
| Ctx::DiagnosticOnUnimplemented { tcx, trait_def_id }) = ctx;
235-
let trait_name = tcx.item_ident(*trait_def_id);
236-
let generics = tcx.generics_of(trait_def_id);
235+
237236
let span = slice_span(input_span, arg.position_span.clone());
238237

239238
match arg.position {
240239
// Something like "hello {name}"
241240
Position::ArgumentNamed(name) => match (ctx, Symbol::intern(name)) {
242-
// accepted, but deprecated
243-
(Ctx::RustcOnUnimplemented { .. }, sym::_Self) => {
244-
warnings
245-
.push(FormatWarning::FutureIncompat { span, help: String::from("use {Self}") });
246-
FormatArg::SelfUpper
247-
}
248-
(
249-
Ctx::RustcOnUnimplemented { .. },
250-
sym::from_desugaring
251-
| sym::crate_local
252-
| sym::direct
253-
| sym::cause
254-
| sym::float
255-
| sym::integer_
256-
| sym::integral,
257-
) => {
258-
warnings.push(FormatWarning::FutureIncompat {
259-
span,
260-
help: String::from("don't use this in a format string"),
261-
});
262-
FormatArg::AsIs(String::new())
263-
}
264-
265241
// Only `#[rustc_on_unimplemented]` can use these
266242
(Ctx::RustcOnUnimplemented { .. }, sym::ItemContext) => FormatArg::ItemContext,
267243
(Ctx::RustcOnUnimplemented { .. }, sym::This) => FormatArg::This,
268244
(Ctx::RustcOnUnimplemented { .. }, sym::Trait) => FormatArg::Trait,
269-
// `{ThisTraitsName}`. Some attrs in std use this, but I'd like to change it to the more general `{This}`
270-
// because that'll be simpler to parse and extend in the future
271-
(Ctx::RustcOnUnimplemented { .. }, name) if name == trait_name.name => {
272-
warnings
273-
.push(FormatWarning::FutureIncompat { span, help: String::from("use {This}") });
274-
FormatArg::This
275-
}
276-
277245
// Any attribute can use these
278246
(
279247
Ctx::RustcOnUnimplemented { .. } | Ctx::DiagnosticOnUnimplemented { .. },
@@ -282,7 +250,10 @@ fn parse_arg<'tcx>(
282250
(
283251
Ctx::RustcOnUnimplemented { .. } | Ctx::DiagnosticOnUnimplemented { .. },
284252
generic_param,
285-
) if generics.own_params.iter().any(|param| param.name == generic_param) => {
253+
) if tcx.generics_of(trait_def_id).own_params.iter().any(|param| {
254+
!matches!(param.kind, GenericParamDefKind::Lifetime) && param.name == generic_param
255+
}) =>
256+
{
286257
FormatArg::GenericParam { generic_param }
287258
}
288259

@@ -375,39 +346,4 @@ pub mod errors {
375346
#[diag(trait_selection_missing_options_for_on_unimplemented_attr)]
376347
#[help]
377348
pub struct MissingOptionsForOnUnimplementedAttr;
378-
379-
#[derive(LintDiagnostic)]
380-
#[diag(trait_selection_ignored_diagnostic_option)]
381-
pub struct IgnoredDiagnosticOption {
382-
pub option_name: &'static str,
383-
#[label]
384-
pub span: Span,
385-
#[label(trait_selection_other_label)]
386-
pub prev_span: Span,
387-
}
388-
389-
impl IgnoredDiagnosticOption {
390-
pub fn maybe_emit_warning<'tcx>(
391-
tcx: TyCtxt<'tcx>,
392-
item_def_id: DefId,
393-
new: Option<Span>,
394-
old: Option<Span>,
395-
option_name: &'static str,
396-
) {
397-
if let (Some(new_item), Some(old_item)) = (new, old) {
398-
if let Some(item_def_id) = item_def_id.as_local() {
399-
tcx.emit_node_span_lint(
400-
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
401-
tcx.local_def_id_to_hir_id(item_def_id),
402-
new_item,
403-
IgnoredDiagnosticOption {
404-
span: new_item,
405-
prev_span: old_item,
406-
option_name,
407-
},
408-
);
409-
}
410-
}
411-
}
412-
}
413349
}

‎compiler/rustc_trait_selection/src/errors.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ pub enum InvalidOnClause {
7272
span: Span,
7373
invalid_flag: Symbol,
7474
},
75+
#[diag(trait_selection_rustc_on_unimplemented_invalid_name, code = E0232)]
76+
InvalidName {
77+
#[primary_span]
78+
#[label]
79+
span: Span,
80+
invalid_name: Symbol,
81+
},
7582
}
7683

7784
#[derive(Diagnostic)]

‎src/tools/clippy/tests/ui/duplicated_attributes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn foo() {}
2121
fn bar() {}
2222

2323
// No warning:
24-
#[rustc_on_unimplemented(on(_Self = "&str", label = "`a"), on(_Self = "alloc::string::String", label = "a"))]
24+
#[rustc_on_unimplemented(on(Self = "&str", label = "`a"), on(Self = "alloc::string::String", label = "a"))]
2525
trait Abc {}
2626

2727
#[proc_macro_attr::duplicated_attr()] // Should not warn!

‎tests/ui/diagnostic_namespace/on_unimplemented/do_not_accept_options_of_the_internal_rustc_attribute.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//@ reference: attributes.diagnostic.on_unimplemented.syntax
44
//@ reference: attributes.diagnostic.on_unimplemented.invalid-formats
55
#[diagnostic::on_unimplemented(
6-
on(_Self = "&str"),
6+
on(Self = "&str"),
77
//~^WARN malformed `on_unimplemented` attribute
88
//~|WARN malformed `on_unimplemented` attribute
99
message = "trait has `{Self}` and `{T}` as params",
@@ -41,7 +41,7 @@ impl Bar for i32 {}
4141
//~|WARN there is no parameter `integral` on trait `Baz`
4242
//~|WARN there is no parameter `integer` on trait `Baz`
4343
//~|WARN there is no parameter `integer` on trait `Baz`
44-
label = "{float}{_Self}{crate_local}{Trait}{ItemContext}"
44+
label = "{float}{_Self}{crate_local}{Trait}{ItemContext}{This}"
4545
//~^WARN there is no parameter `float` on trait `Baz`
4646
//~|WARN there is no parameter `float` on trait `Baz`
4747
//~|WARN there is no parameter `_Self` on trait `Baz`
@@ -52,6 +52,8 @@ impl Bar for i32 {}
5252
//~|WARN there is no parameter `Trait` on trait `Baz`
5353
//~|WARN there is no parameter `ItemContext` on trait `Baz`
5454
//~|WARN there is no parameter `ItemContext` on trait `Baz`
55+
//~|WARN there is no parameter `This` on trait `Baz`
56+
//~|WARN there is no parameter `This` on trait `Baz`
5557
)]
5658
trait Baz {}
5759

‎tests/ui/diagnostic_namespace/on_unimplemented/do_not_accept_options_of_the_internal_rustc_attribute.stderr

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ LL | #[diagnostic::on_unimplemented(message = "Not allowed to apply it on a impl
99
warning: malformed `on_unimplemented` attribute
1010
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:6:5
1111
|
12-
LL | on(_Self = "&str"),
13-
| ^^^^^^^^^^^^^^^^^^ invalid option found here
12+
LL | on(Self = "&str"),
13+
| ^^^^^^^^^^^^^^^^^ invalid option found here
1414
|
1515
= help: only `message`, `note` and `label` are allowed as options
1616

@@ -81,48 +81,56 @@ LL | message = "{from_desugaring}{direct}{cause}{integral}{integer}",
8181
warning: there is no parameter `float` on trait `Baz`
8282
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:15
8383
|
84-
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}"
84+
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}{This}"
8585
| ^^^^^
8686
|
8787
= help: expect either a generic argument name or `{Self}` as format argument
8888

8989
warning: there is no parameter `_Self` on trait `Baz`
9090
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:22
9191
|
92-
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}"
92+
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}{This}"
9393
| ^^^^^
9494
|
9595
= help: expect either a generic argument name or `{Self}` as format argument
9696

9797
warning: there is no parameter `crate_local` on trait `Baz`
9898
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:29
9999
|
100-
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}"
100+
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}{This}"
101101
| ^^^^^^^^^^^
102102
|
103103
= help: expect either a generic argument name or `{Self}` as format argument
104104

105105
warning: there is no parameter `Trait` on trait `Baz`
106106
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:42
107107
|
108-
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}"
108+
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}{This}"
109109
| ^^^^^
110110
|
111111
= help: expect either a generic argument name or `{Self}` as format argument
112112

113113
warning: there is no parameter `ItemContext` on trait `Baz`
114114
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:49
115115
|
116-
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}"
116+
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}{This}"
117117
| ^^^^^^^^^^^
118118
|
119119
= help: expect either a generic argument name or `{Self}` as format argument
120120

121+
warning: there is no parameter `This` on trait `Baz`
122+
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:62
123+
|
124+
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}{This}"
125+
| ^^^^
126+
|
127+
= help: expect either a generic argument name or `{Self}` as format argument
128+
121129
warning: malformed `on_unimplemented` attribute
122130
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:6:5
123131
|
124-
LL | on(_Self = "&str"),
125-
| ^^^^^^^^^^^^^^^^^^ invalid option found here
132+
LL | on(Self = "&str"),
133+
| ^^^^^^^^^^^^^^^^^ invalid option found here
126134
|
127135
= help: only `message`, `note` and `label` are allowed as options
128136
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
@@ -146,7 +154,7 @@ LL | append_const_msg
146154
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
147155

148156
error[E0277]: trait has `()` and `i32` as params
149-
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:63:15
157+
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:65:15
150158
|
151159
LL | takes_foo(());
152160
| --------- ^^ trait has `()` and `i32` as params
@@ -161,7 +169,7 @@ help: this trait has no implementations, consider adding one
161169
LL | trait Foo<T> {}
162170
| ^^^^^^^^^^^^
163171
note: required by a bound in `takes_foo`
164-
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:58:22
172+
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:60:22
165173
|
166174
LL | fn takes_foo(_: impl Foo<i32>) {}
167175
| ^^^^^^^^ required by this bound in `takes_foo`
@@ -176,7 +184,7 @@ LL | #[diagnostic::on_unimplemented = "Message"]
176184
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
177185

178186
error[E0277]: the trait bound `(): Bar` is not satisfied
179-
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:65:15
187+
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:67:15
180188
|
181189
LL | takes_bar(());
182190
| --------- ^^ the trait `Bar` is not implemented for `()`
@@ -185,7 +193,7 @@ LL | takes_bar(());
185193
|
186194
= help: the trait `Bar` is implemented for `i32`
187195
note: required by a bound in `takes_bar`
188-
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:59:22
196+
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:61:22
189197
|
190198
LL | fn takes_bar(_: impl Bar) {}
191199
| ^^^ required by this bound in `takes_bar`
@@ -238,7 +246,7 @@ LL | message = "{from_desugaring}{direct}{cause}{integral}{integer}",
238246
warning: there is no parameter `float` on trait `Baz`
239247
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:15
240248
|
241-
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}"
249+
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}{This}"
242250
| ^^^^^
243251
|
244252
= help: expect either a generic argument name or `{Self}` as format argument
@@ -247,7 +255,7 @@ LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}"
247255
warning: there is no parameter `_Self` on trait `Baz`
248256
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:22
249257
|
250-
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}"
258+
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}{This}"
251259
| ^^^^^
252260
|
253261
= help: expect either a generic argument name or `{Self}` as format argument
@@ -256,7 +264,7 @@ LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}"
256264
warning: there is no parameter `crate_local` on trait `Baz`
257265
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:29
258266
|
259-
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}"
267+
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}{This}"
260268
| ^^^^^^^^^^^
261269
|
262270
= help: expect either a generic argument name or `{Self}` as format argument
@@ -265,7 +273,7 @@ LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}"
265273
warning: there is no parameter `Trait` on trait `Baz`
266274
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:42
267275
|
268-
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}"
276+
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}{This}"
269277
| ^^^^^
270278
|
271279
= help: expect either a generic argument name or `{Self}` as format argument
@@ -274,32 +282,41 @@ LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}"
274282
warning: there is no parameter `ItemContext` on trait `Baz`
275283
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:49
276284
|
277-
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}"
285+
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}{This}"
278286
| ^^^^^^^^^^^
279287
|
280288
= help: expect either a generic argument name or `{Self}` as format argument
281289
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
282290

291+
warning: there is no parameter `This` on trait `Baz`
292+
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:62
293+
|
294+
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}{This}"
295+
| ^^^^
296+
|
297+
= help: expect either a generic argument name or `{Self}` as format argument
298+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
299+
283300
error[E0277]: {from_desugaring}{direct}{cause}{integral}{integer}
284-
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:67:15
301+
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:69:15
285302
|
286303
LL | takes_baz(());
287-
| --------- ^^ {float}{_Self}{crate_local}{Trait}{ItemContext}
304+
| --------- ^^ {float}{_Self}{crate_local}{Trait}{ItemContext}{This}
288305
| |
289306
| required by a bound introduced by this call
290307
|
291308
= help: the trait `Baz` is not implemented for `()`
292309
help: this trait has no implementations, consider adding one
293-
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:56:1
310+
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:58:1
294311
|
295312
LL | trait Baz {}
296313
| ^^^^^^^^^
297314
note: required by a bound in `takes_baz`
298-
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:60:22
315+
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:62:22
299316
|
300317
LL | fn takes_baz(_: impl Baz) {}
301318
| ^^^ required by this bound in `takes_baz`
302319

303-
error: aborting due to 3 previous errors; 29 warnings emitted
320+
error: aborting due to 3 previous errors; 31 warnings emitted
304321

305322
For more information about this error, try `rustc --explain E0277`.

‎tests/ui/diagnostic_namespace/on_unimplemented/do_not_fail_parsing_on_invalid_options_1.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ struct Bar {}
1414
//~|WARN malformed `on_unimplemented` attribute
1515
trait Baz {}
1616

17-
#[diagnostic::on_unimplemented(message = "Boom", on(_Self = "i32", message = "whatever"))]
17+
#[diagnostic::on_unimplemented(message = "Boom", on(Self = "i32", message = "whatever"))]
1818
//~^WARN malformed `on_unimplemented` attribute
1919
//~|WARN malformed `on_unimplemented` attribute
2020
trait Boom {}
2121

22+
#[diagnostic::on_unimplemented(message = "Boom", on(_Self = "i32", message = "whatever"))]
23+
//~^WARN malformed `on_unimplemented` attribute
24+
trait _Self {}
25+
2226
#[diagnostic::on_unimplemented = "boom"]
2327
//~^WARN malformed `on_unimplemented` attribute
2428
trait Doom {}

‎tests/ui/diagnostic_namespace/on_unimplemented/do_not_fail_parsing_on_invalid_options_1.stderr

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,37 @@ LL | #[diagnostic::on_unimplemented(message = "Boom", unsupported = "Bar")]
2525
warning: malformed `on_unimplemented` attribute
2626
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:17:50
2727
|
28+
LL | #[diagnostic::on_unimplemented(message = "Boom", on(Self = "i32", message = "whatever"))]
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid option found here
30+
|
31+
= help: only `message`, `note` and `label` are allowed as options
32+
33+
warning: malformed `on_unimplemented` attribute
34+
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:22:50
35+
|
2836
LL | #[diagnostic::on_unimplemented(message = "Boom", on(_Self = "i32", message = "whatever"))]
2937
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid option found here
3038
|
3139
= help: only `message`, `note` and `label` are allowed as options
3240

3341
warning: malformed `on_unimplemented` attribute
34-
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:22:32
42+
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:26:32
3543
|
3644
LL | #[diagnostic::on_unimplemented = "boom"]
3745
| ^^^^^^^^ invalid option found here
3846
|
3947
= help: only `message`, `note` and `label` are allowed as options
4048

4149
warning: missing options for `on_unimplemented` attribute
42-
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:26:1
50+
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:30:1
4351
|
4452
LL | #[diagnostic::on_unimplemented]
4553
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4654
|
4755
= help: at least one of the `message`, `note` and `label` options are expected
4856

4957
warning: there is no parameter `DoesNotExist` on trait `Test`
50-
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:31:44
58+
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:35:44
5159
|
5260
LL | #[diagnostic::on_unimplemented(message = "{DoesNotExist}")]
5361
| ^^^^^^^^^^^^
@@ -64,7 +72,7 @@ LL | #[diagnostic::on_unimplemented(unsupported = "foo")]
6472
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
6573

6674
error[E0277]: the trait bound `i32: Foo` is not satisfied
67-
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:43:14
75+
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:47:14
6876
|
6977
LL | take_foo(1_i32);
7078
| -------- ^^^^^ the trait `Foo` is not implemented for `i32`
@@ -77,7 +85,7 @@ help: this trait has no implementations, consider adding one
7785
LL | trait Foo {}
7886
| ^^^^^^^^^
7987
note: required by a bound in `take_foo`
80-
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:36:21
88+
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:40:21
8189
|
8290
LL | fn take_foo(_: impl Foo) {}
8391
| ^^^ required by this bound in `take_foo`
@@ -92,7 +100,7 @@ LL | #[diagnostic::on_unimplemented(message = "Boom", unsupported = "Bar")]
92100
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
93101

94102
error[E0277]: Boom
95-
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:45:14
103+
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:49:14
96104
|
97105
LL | take_baz(1_i32);
98106
| -------- ^^^^^ the trait `Baz` is not implemented for `i32`
@@ -105,22 +113,22 @@ help: this trait has no implementations, consider adding one
105113
LL | trait Baz {}
106114
| ^^^^^^^^^
107115
note: required by a bound in `take_baz`
108-
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:37:21
116+
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:41:21
109117
|
110118
LL | fn take_baz(_: impl Baz) {}
111119
| ^^^ required by this bound in `take_baz`
112120

113121
warning: malformed `on_unimplemented` attribute
114122
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:17:50
115123
|
116-
LL | #[diagnostic::on_unimplemented(message = "Boom", on(_Self = "i32", message = "whatever"))]
117-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid option found here
124+
LL | #[diagnostic::on_unimplemented(message = "Boom", on(Self = "i32", message = "whatever"))]
125+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid option found here
118126
|
119127
= help: only `message`, `note` and `label` are allowed as options
120128
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
121129

122130
error[E0277]: Boom
123-
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:47:15
131+
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:51:15
124132
|
125133
LL | take_boom(1_i32);
126134
| --------- ^^^^^ the trait `Boom` is not implemented for `i32`
@@ -133,13 +141,13 @@ help: this trait has no implementations, consider adding one
133141
LL | trait Boom {}
134142
| ^^^^^^^^^^
135143
note: required by a bound in `take_boom`
136-
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:38:22
144+
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:42:22
137145
|
138146
LL | fn take_boom(_: impl Boom) {}
139147
| ^^^^ required by this bound in `take_boom`
140148

141149
warning: missing options for `on_unimplemented` attribute
142-
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:26:1
150+
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:30:1
143151
|
144152
LL | #[diagnostic::on_unimplemented]
145153
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -148,26 +156,26 @@ LL | #[diagnostic::on_unimplemented]
148156
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
149157

150158
error[E0277]: the trait bound `i32: Whatever` is not satisfied
151-
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:49:19
159+
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:53:19
152160
|
153161
LL | take_whatever(1_i32);
154162
| ------------- ^^^^^ the trait `Whatever` is not implemented for `i32`
155163
| |
156164
| required by a bound introduced by this call
157165
|
158166
help: this trait has no implementations, consider adding one
159-
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:29:1
167+
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:33:1
160168
|
161169
LL | trait Whatever {}
162170
| ^^^^^^^^^^^^^^
163171
note: required by a bound in `take_whatever`
164-
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:39:26
172+
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:43:26
165173
|
166174
LL | fn take_whatever(_: impl Whatever) {}
167175
| ^^^^^^^^ required by this bound in `take_whatever`
168176

169177
warning: there is no parameter `DoesNotExist` on trait `Test`
170-
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:31:44
178+
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:35:44
171179
|
172180
LL | #[diagnostic::on_unimplemented(message = "{DoesNotExist}")]
173181
| ^^^^^^^^^^^^
@@ -176,24 +184,24 @@ LL | #[diagnostic::on_unimplemented(message = "{DoesNotExist}")]
176184
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
177185

178186
error[E0277]: {DoesNotExist}
179-
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:51:15
187+
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:55:15
180188
|
181189
LL | take_test(());
182190
| --------- ^^ the trait `Test` is not implemented for `()`
183191
| |
184192
| required by a bound introduced by this call
185193
|
186194
help: this trait has no implementations, consider adding one
187-
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:34:1
195+
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:38:1
188196
|
189197
LL | trait Test {}
190198
| ^^^^^^^^^^
191199
note: required by a bound in `take_test`
192-
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:40:22
200+
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:44:22
193201
|
194202
LL | fn take_test(_: impl Test) {}
195203
| ^^^^ required by this bound in `take_test`
196204

197-
error: aborting due to 5 previous errors; 12 warnings emitted
205+
error: aborting due to 5 previous errors; 13 warnings emitted
198206

199207
For more information about this error, try `rustc --explain E0277`.

‎tests/ui/on-unimplemented/bad-annotation.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ trait EmptyOn {}
5959
//~^^^ NOTE expected value here
6060
trait ExpectedPredicateInOn {}
6161

62-
#[rustc_on_unimplemented(on(x = "y"), message = "y")]
62+
#[rustc_on_unimplemented(on(Self = "y"), message = "y")]
6363
trait OnWithoutDirectives {}
6464

6565
#[rustc_on_unimplemented(on(from_desugaring, on(from_desugaring, message = "x")), message = "y")]
@@ -107,3 +107,13 @@ trait InvalidPredicate {}
107107
//~^ ERROR invalid flag in `on`-clause
108108
//~^^ NOTE expected one of the `crate_local`, `direct` or `from_desugaring` flags, not `something`
109109
trait InvalidFlag {}
110+
111+
#[rustc_on_unimplemented(on(_Self = "y", message = "y"))]
112+
//~^ ERROR invalid name in `on`-clause
113+
//~^^ NOTE expected one of `cause`, `from_desugaring`, `Self` or any generic parameter of the trait, not `_Self`
114+
trait InvalidName {}
115+
116+
#[rustc_on_unimplemented(on(abc = "y", message = "y"))]
117+
//~^ ERROR invalid name in `on`-clause
118+
//~^^ NOTE expected one of `cause`, `from_desugaring`, `Self` or any generic parameter of the trait, not `abc`
119+
trait InvalidName2 {}

‎tests/ui/on-unimplemented/bad-annotation.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,19 @@ error[E0232]: invalid flag in `on`-clause
125125
LL | #[rustc_on_unimplemented(on(something, message = "y"))]
126126
| ^^^^^^^^^ expected one of the `crate_local`, `direct` or `from_desugaring` flags, not `something`
127127

128-
error: aborting due to 18 previous errors
128+
error[E0232]: invalid name in `on`-clause
129+
--> $DIR/bad-annotation.rs:111:29
130+
|
131+
LL | #[rustc_on_unimplemented(on(_Self = "y", message = "y"))]
132+
| ^^^^^ expected one of `cause`, `from_desugaring`, `Self` or any generic parameter of the trait, not `_Self`
133+
134+
error[E0232]: invalid name in `on`-clause
135+
--> $DIR/bad-annotation.rs:116:29
136+
|
137+
LL | #[rustc_on_unimplemented(on(abc = "y", message = "y"))]
138+
| ^^^ expected one of `cause`, `from_desugaring`, `Self` or any generic parameter of the trait, not `abc`
139+
140+
error: aborting due to 20 previous errors
129141

130142
Some errors have detailed explanations: E0230, E0231, E0232.
131143
For more information about an error, try `rustc --explain E0230`.

‎tests/ui/on-unimplemented/on-trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![feature(rustc_attrs)]
44

55
pub mod Bar {
6-
#[rustc_on_unimplemented = "test error `{Self}` with `{Bar}` `{Baz}` `{Quux}` in `{Foo}`"]
6+
#[rustc_on_unimplemented = "test error `{Self}` with `{Bar}` `{Baz}` `{Quux}` in `{This}`"]
77
pub trait Foo<Bar, Baz, Quux> {}
88
}
99

0 commit comments

Comments
 (0)
This repository has been archived.