Skip to content

Commit 7f9cfa5

Browse files
committed
Bypass 'invalid meta item' error when an error already shown
1 parent 4b4f01d commit 7f9cfa5

File tree

3 files changed

+9
-60
lines changed

3 files changed

+9
-60
lines changed

compiler/rustc_attr/src/builtin.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,9 @@ fn insert_or_error(sess: &Session, meta: &MetaItem, item: &mut Option<Symbol>) -
330330
*item = Some(v);
331331
Some(())
332332
} else {
333-
sess.emit_err(session_diagnostics::IncorrectMetaItem { span: meta.span });
333+
if !matches!(meta.kind, MetaItemKind::NameValue(MetaItemLit { kind: LitKind::Err, .. })) {
334+
sess.emit_err(session_diagnostics::IncorrectMetaItem { span: meta.span });
335+
}
334336
None
335337
}
336338
}

tests/ui/stability-attribute/eager-expansion-fail.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,10 @@ macro_rules! not_a_literal {
1010

1111
macro_rules! m {
1212
() => {
13-
#[stable(feature = 1 + 1, since = "?")]
14-
//~^ expression in the value of this attribute must be a literal or macro call
15-
//~^^ incorrect meta item
16-
//~^^^ incorrect meta item
13+
#[stable(feature = 1 + 1, since = "?")] //~ expression in the value of this attribute must be a literal or macro call
1714
pub struct Math; //~ struct has missing stability attribute
1815

19-
#[stable(feature = not_a_literal!(), since = "?")]
20-
//~^ expression in the value of this attribute must be a literal or macro call
21-
//~^^ incorrect meta item
22-
//~^^^ incorrect meta item
16+
#[stable(feature = not_a_literal!(), since = "?")] //~ expression in the value of this attribute must be a literal or macro call
2317
pub struct NotLiteral; //~ struct has missing stability attribute
2418
};
2519
}

tests/ui/stability-attribute/eager-expansion-fail.stderr

+4-51
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LL | m!();
1010
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
1111

1212
error: expression in the value of this attribute must be a literal or macro call
13-
--> $DIR/eager-expansion-fail.rs:19:28
13+
--> $DIR/eager-expansion-fail.rs:16:28
1414
|
1515
LL | #[stable(feature = not_a_literal!(), since = "?")]
1616
| ^^^^^^^^^^^^^^^^
@@ -20,54 +20,8 @@ LL | m!();
2020
|
2121
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
2222

23-
error[E0539]: incorrect meta item
24-
--> $DIR/eager-expansion-fail.rs:13:18
25-
|
26-
LL | #[stable(feature = 1 + 1, since = "?")]
27-
| ^^^^^^^^^^^^^^^
28-
...
29-
LL | m!();
30-
| ---- in this macro invocation
31-
|
32-
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
33-
34-
error[E0539]: incorrect meta item
35-
--> $DIR/eager-expansion-fail.rs:13:18
36-
|
37-
LL | #[stable(feature = 1 + 1, since = "?")]
38-
| ^^^^^^^^^^^^^^^
39-
...
40-
LL | m!();
41-
| ---- in this macro invocation
42-
|
43-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
44-
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
45-
46-
error[E0539]: incorrect meta item
47-
--> $DIR/eager-expansion-fail.rs:19:18
48-
|
49-
LL | #[stable(feature = not_a_literal!(), since = "?")]
50-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
51-
...
52-
LL | m!();
53-
| ---- in this macro invocation
54-
|
55-
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
56-
57-
error[E0539]: incorrect meta item
58-
--> $DIR/eager-expansion-fail.rs:19:18
59-
|
60-
LL | #[stable(feature = not_a_literal!(), since = "?")]
61-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
62-
...
63-
LL | m!();
64-
| ---- in this macro invocation
65-
|
66-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
67-
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
68-
6923
error: struct has missing stability attribute
70-
--> $DIR/eager-expansion-fail.rs:17:9
24+
--> $DIR/eager-expansion-fail.rs:14:9
7125
|
7226
LL | pub struct Math;
7327
| ^^^^^^^^^^^^^^^^
@@ -78,7 +32,7 @@ LL | m!();
7832
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
7933

8034
error: struct has missing stability attribute
81-
--> $DIR/eager-expansion-fail.rs:23:9
35+
--> $DIR/eager-expansion-fail.rs:17:9
8236
|
8337
LL | pub struct NotLiteral;
8438
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -88,6 +42,5 @@ LL | m!();
8842
|
8943
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
9044

91-
error: aborting due to 8 previous errors
45+
error: aborting due to 4 previous errors
9246

93-
For more information about this error, try `rustc --explain E0539`.

0 commit comments

Comments
 (0)