Skip to content

Commit 75273e2

Browse files
committed
Warn instead of error for some ructs_on_unimplemented errors
1 parent f468cef commit 75273e2

3 files changed

Lines changed: 90 additions & 112 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,14 @@ fn parse_directive_items<'p, S: Stage>(
150150
let span = item.span();
151151

152152
macro malformed() {{
153-
if matches!(mode, Mode::RustcOnUnimplemented) {
154-
cx.emit_err(NoValueInOnUnimplemented { span: item.span() });
155-
} else {
156-
cx.emit_lint(
157-
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
158-
AttributeLintKind::MalFormedDiagnosticAttribute {
159-
attribute: mode.as_str(),
160-
span,
161-
},
153+
cx.emit_lint(
154+
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
155+
AttributeLintKind::MalFormedDiagnosticAttribute {
156+
attribute: mode.as_str(),
162157
span,
163-
);
164-
}
158+
},
159+
span,
160+
);
165161
continue;
166162
}}
167163

@@ -175,19 +171,15 @@ fn parse_directive_items<'p, S: Stage>(
175171
}}
176172

177173
macro duplicate($name: ident, $($first_span:tt)*) {{
178-
if matches!(mode, Mode::RustcOnUnimplemented) {
179-
cx.emit_err(NoValueInOnUnimplemented { span: item.span() });
180-
} else {
181-
cx.emit_lint(
182-
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
183-
AttributeLintKind::IgnoredDiagnosticOption {
184-
first_span: $($first_span)*,
185-
later_span: span,
186-
option_name: $name,
187-
},
188-
span,
189-
);
190-
}
174+
cx.emit_lint(
175+
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
176+
AttributeLintKind::IgnoredDiagnosticOption {
177+
first_span: $($first_span)*,
178+
later_span: span,
179+
option_name: $name,
180+
},
181+
span,
182+
);
191183
}}
192184

193185
let item: &MetaItemParser = or_malformed!(item.meta_item()?);
@@ -566,15 +558,6 @@ pub(crate) enum InvalidOnClause {
566558
},
567559
}
568560

569-
#[derive(Diagnostic)]
570-
#[diag("this attribute must have a value", code = E0232)]
571-
#[note("e.g. `#[rustc_on_unimplemented(message=\"foo\")]`")]
572-
pub(crate) struct NoValueInOnUnimplemented {
573-
#[primary_span]
574-
#[label("expected value here")]
575-
pub span: Span,
576-
}
577-
578561
#[derive(Diagnostic)]
579562
#[diag(
580563
"using multiple `rustc_on_unimplemented` (or mixing it with `diagnostic::on_unimplemented`) is not supported"

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

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,19 @@ trait ParameterNotPresent<A, B> {}
2727
trait NoPositionalArgs<A, B> {}
2828

2929
#[rustc_on_unimplemented(lorem = "")]
30-
//~^ ERROR this attribute must have a value
31-
//~^^ NOTE e.g. `#[rustc_on_unimplemented(message="foo")]`
32-
//~^^^ NOTE expected value here
30+
//~^WARN malformed `rustc_on_unimplemented` attribute
31+
//~|NOTE invalid option found here
3332
trait EmptyMessage {}
3433

3534
#[rustc_on_unimplemented(lorem(ipsum(dolor)))]
36-
//~^ ERROR this attribute must have a value
37-
//~^^ NOTE e.g. `#[rustc_on_unimplemented(message="foo")]`
38-
//~^^^ NOTE expected value here
35+
//~^WARN malformed `rustc_on_unimplemented` attribute
36+
//~|NOTE invalid option found here
3937
trait Invalid {}
4038

4139
#[rustc_on_unimplemented(message = "x", message = "y")]
42-
//~^ ERROR this attribute must have a value
43-
//~^^ NOTE e.g. `#[rustc_on_unimplemented(message="foo")]`
44-
//~^^^ NOTE expected value here
40+
//~^WARN `message` is ignored due to previous definition of `message`
41+
//~|NOTE `message` is first declared here
42+
//~|NOTE `message` is later redundantly declared here
4543
trait DuplicateMessage {}
4644

4745
#[rustc_on_unimplemented(message = "x", on(desugared, message = "y"))]
@@ -55,21 +53,18 @@ trait OnInWrongPosition {}
5553
trait EmptyOn {}
5654

5755
#[rustc_on_unimplemented(on = "x", message = "y")]
58-
//~^ ERROR this attribute must have a value
59-
//~^^ NOTE e.g. `#[rustc_on_unimplemented(message="foo")]`
60-
//~^^^ NOTE expected value here
56+
//~^WARN malformed `rustc_on_unimplemented` attribute
57+
//~|NOTE invalid option found here
6158
trait ExpectedPredicateInOn {}
6259

6360
#[rustc_on_unimplemented(on(Self = "y"), message = "y")]
64-
//~^ ERROR this attribute must have a value
65-
//~| NOTE expected value here
66-
//~| NOTE e.g. `#[rustc_on_unimplemented(message="foo")]`
61+
//~^WARN malformed `rustc_on_unimplemented` attribute
62+
//~|NOTE invalid option found here
6763
trait OnWithoutDirectives {}
6864

6965
#[rustc_on_unimplemented(on(from_desugaring, on(from_desugaring, message = "x")), message = "y")]
70-
//~^ ERROR this attribute must have a value
71-
//~^^ NOTE e.g. `#[rustc_on_unimplemented(message="foo")]`
72-
//~^^^ NOTE expected value here
66+
//~^WARN malformed `rustc_on_unimplemented` attribute
67+
//~|NOTE invalid option found here
7368
trait NestedOn {}
7469

7570
#[rustc_on_unimplemented(on("y", message = "y"))]
Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,59 @@
1-
error[E0232]: this attribute must have a value
2-
--> $DIR/bad-annotation.rs:29:26
3-
|
4-
LL | #[rustc_on_unimplemented(lorem = "")]
5-
| ^^^^^^^^^^ expected value here
6-
|
7-
= note: e.g. `#[rustc_on_unimplemented(message="foo")]`
8-
9-
error[E0232]: this attribute must have a value
10-
--> $DIR/bad-annotation.rs:35:26
11-
|
12-
LL | #[rustc_on_unimplemented(lorem(ipsum(dolor)))]
13-
| ^^^^^^^^^^^^^^^^^^^ expected value here
14-
|
15-
= note: e.g. `#[rustc_on_unimplemented(message="foo")]`
16-
17-
error[E0232]: this attribute must have a value
18-
--> $DIR/bad-annotation.rs:41:41
19-
|
20-
LL | #[rustc_on_unimplemented(message = "x", message = "y")]
21-
| ^^^^^^^^^^^^^ expected value here
22-
|
23-
= note: e.g. `#[rustc_on_unimplemented(message="foo")]`
24-
251
error[E0232]: invalid flag in `on`-clause
26-
--> $DIR/bad-annotation.rs:47:44
2+
--> $DIR/bad-annotation.rs:45:44
273
|
284
LL | #[rustc_on_unimplemented(message = "x", on(desugared, message = "y"))]
295
| ^^^^^^^^^ expected one of the `crate_local`, `direct` or `from_desugaring` flags, not `desugared`
306

317
error[E0232]: empty `on`-clause in `#[rustc_on_unimplemented]`
32-
--> $DIR/bad-annotation.rs:52:26
8+
--> $DIR/bad-annotation.rs:50:26
339
|
3410
LL | #[rustc_on_unimplemented(on(), message = "y")]
3511
| ^^^^ empty `on`-clause here
3612

37-
error[E0232]: this attribute must have a value
38-
--> $DIR/bad-annotation.rs:57:26
39-
|
40-
LL | #[rustc_on_unimplemented(on = "x", message = "y")]
41-
| ^^^^^^^^ expected value here
42-
|
43-
= note: e.g. `#[rustc_on_unimplemented(message="foo")]`
44-
45-
error[E0232]: this attribute must have a value
46-
--> $DIR/bad-annotation.rs:63:26
47-
|
48-
LL | #[rustc_on_unimplemented(on(Self = "y"), message = "y")]
49-
| ^^^^^^^^^^^^^^ expected value here
50-
|
51-
= note: e.g. `#[rustc_on_unimplemented(message="foo")]`
52-
53-
error[E0232]: this attribute must have a value
54-
--> $DIR/bad-annotation.rs:69:46
55-
|
56-
LL | #[rustc_on_unimplemented(on(from_desugaring, on(from_desugaring, message = "x")), message = "y")]
57-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected value here
58-
|
59-
= note: e.g. `#[rustc_on_unimplemented(message="foo")]`
60-
6113
error[E0232]: literals inside `on`-clauses are not supported
62-
--> $DIR/bad-annotation.rs:75:29
14+
--> $DIR/bad-annotation.rs:70:29
6315
|
6416
LL | #[rustc_on_unimplemented(on("y", message = "y"))]
6517
| ^^^ unexpected literal here
6618

6719
error[E0232]: literals inside `on`-clauses are not supported
68-
--> $DIR/bad-annotation.rs:80:29
20+
--> $DIR/bad-annotation.rs:75:29
6921
|
7022
LL | #[rustc_on_unimplemented(on(42, message = "y"))]
7123
| ^^ unexpected literal here
7224

7325
error[E0232]: expected a single predicate in `not(..)`
74-
--> $DIR/bad-annotation.rs:85:32
26+
--> $DIR/bad-annotation.rs:80:32
7527
|
7628
LL | #[rustc_on_unimplemented(on(not(a, b), message = "y"))]
7729
| ^^^^^^ unexpected quantity of predicates here
7830

7931
error[E0232]: expected a single predicate in `not(..)`
80-
--> $DIR/bad-annotation.rs:90:32
32+
--> $DIR/bad-annotation.rs:85:32
8133
|
8234
LL | #[rustc_on_unimplemented(on(not(), message = "y"))]
8335
| ^^ unexpected quantity of predicates here
8436

8537
error[E0232]: expected an identifier inside this `on`-clause
86-
--> $DIR/bad-annotation.rs:95:29
38+
--> $DIR/bad-annotation.rs:90:29
8739
|
8840
LL | #[rustc_on_unimplemented(on(thing::What, message = "y"))]
8941
| ^^^^^^^^^^^ expected an identifier here, not `thing::What`
9042

9143
error[E0232]: expected an identifier inside this `on`-clause
92-
--> $DIR/bad-annotation.rs:100:29
44+
--> $DIR/bad-annotation.rs:95:29
9345
|
9446
LL | #[rustc_on_unimplemented(on(thing::What = "value", message = "y"))]
9547
| ^^^^^^^^^^^ expected an identifier here, not `thing::What`
9648

9749
error[E0232]: this predicate is invalid
98-
--> $DIR/bad-annotation.rs:105:29
50+
--> $DIR/bad-annotation.rs:100:29
9951
|
10052
LL | #[rustc_on_unimplemented(on(aaaaaaaaaaaaaa(a, b), message = "y"))]
10153
| ^^^^^^^^^^^^^^ expected one of `any`, `all` or `not` here, not `aaaaaaaaaaaaaa`
10254

10355
error[E0232]: invalid flag in `on`-clause
104-
--> $DIR/bad-annotation.rs:110:29
56+
--> $DIR/bad-annotation.rs:105:29
10557
|
10658
LL | #[rustc_on_unimplemented(on(something, message = "y"))]
10759
| ^^^^^^^^^ expected one of the `crate_local`, `direct` or `from_desugaring` flags, not `something`
@@ -115,13 +67,13 @@ LL | #[rustc_on_unimplemented(label = "Unimplemented error on `{Self}` with para
11567
= note: `#[warn(malformed_diagnostic_format_literals)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default
11668

11769
warning: there is no parameter `_Self` on trait `InvalidName`
118-
--> $DIR/bad-annotation.rs:115:29
70+
--> $DIR/bad-annotation.rs:110:29
11971
|
12072
LL | #[rustc_on_unimplemented(on(_Self = "y", message = "y"))]
12173
| ^^^^^^^^^^^
12274

12375
warning: there is no parameter `abc` on trait `InvalidName2`
124-
--> $DIR/bad-annotation.rs:119:29
76+
--> $DIR/bad-annotation.rs:114:29
12577
|
12678
LL | #[rustc_on_unimplemented(on(abc = "y", message = "y"))]
12779
| ^^^^^^^^^
@@ -143,6 +95,54 @@ LL | #[rustc_on_unimplemented(label = "Unimplemented error on `{Self}` with para
14395
|
14496
= help: only named format arguments with the name of one of the generic types are allowed in this context
14597

146-
error: aborting due to 16 previous errors; 5 warnings emitted
98+
warning: malformed `rustc_on_unimplemented` attribute
99+
--> $DIR/bad-annotation.rs:29:26
100+
|
101+
LL | #[rustc_on_unimplemented(lorem = "")]
102+
| ^^^^^^^^^^ invalid option found here
103+
|
104+
= help: only `message`, `note` and `label` are allowed as options
105+
106+
warning: malformed `rustc_on_unimplemented` attribute
107+
--> $DIR/bad-annotation.rs:34:26
108+
|
109+
LL | #[rustc_on_unimplemented(lorem(ipsum(dolor)))]
110+
| ^^^^^^^^^^^^^^^^^^^ invalid option found here
111+
|
112+
= help: only `message`, `note` and `label` are allowed as options
113+
114+
warning: `message` is ignored due to previous definition of `message`
115+
--> $DIR/bad-annotation.rs:39:41
116+
|
117+
LL | #[rustc_on_unimplemented(message = "x", message = "y")]
118+
| ------------- ^^^^^^^^^^^^^ `message` is later redundantly declared here
119+
| |
120+
| `message` is first declared here
121+
122+
warning: malformed `rustc_on_unimplemented` attribute
123+
--> $DIR/bad-annotation.rs:55:26
124+
|
125+
LL | #[rustc_on_unimplemented(on = "x", message = "y")]
126+
| ^^^^^^^^ invalid option found here
127+
|
128+
= help: only `message`, `note` and `label` are allowed as options
129+
130+
warning: malformed `rustc_on_unimplemented` attribute
131+
--> $DIR/bad-annotation.rs:60:26
132+
|
133+
LL | #[rustc_on_unimplemented(on(Self = "y"), message = "y")]
134+
| ^^^^^^^^^^^^^^ invalid option found here
135+
|
136+
= help: only `message`, `note` and `label` are allowed as options
137+
138+
warning: malformed `rustc_on_unimplemented` attribute
139+
--> $DIR/bad-annotation.rs:65:46
140+
|
141+
LL | #[rustc_on_unimplemented(on(from_desugaring, on(from_desugaring, message = "x")), message = "y")]
142+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid option found here
143+
|
144+
= help: only `message`, `note` and `label` are allowed as options
145+
146+
error: aborting due to 10 previous errors; 11 warnings emitted
147147

148148
For more information about this error, try `rustc --explain E0232`.

0 commit comments

Comments
 (0)