Skip to content

Commit d146c5d

Browse files
committed
fix ICE on stable related to attrs on macros
1 parent 7f9f26b commit d146c5d

File tree

6 files changed

+48
-7
lines changed

6 files changed

+48
-7
lines changed

compiler/rustc_attr_parsing/src/parser.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,8 @@ fn expr_to_lit(
362362
// the error because an earlier error will have already
363363
// been reported.
364364
let msg = "attribute value must be a literal";
365-
let mut err = psess.dcx().struct_span_err(span, msg);
366-
if let ExprKind::Err(_) = expr.kind {
367-
err.downgrade_to_delayed_bug();
368-
}
369-
370-
should_emit.emit_err_or_delay(err);
365+
let err = psess.dcx().struct_span_err(span, msg);
366+
should_emit.maybe_emit_err(err);
371367
None
372368
}
373369
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//@ check-pass
2+
#[deprecated = concat !()]
3+
macro_rules! a {
4+
() => {};
5+
}
6+
fn main() {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![deny(unused)]
2+
3+
#[crate_name = concat !()]
4+
//~^ ERROR crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]
5+
macro_rules! a {
6+
//~^ ERROR unused macro definition
7+
() => {};
8+
}
9+
fn main() {}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error: unused macro definition: `a`
2+
--> $DIR/concat-in-crate-name-issue-137687.rs:5:14
3+
|
4+
LL | macro_rules! a {
5+
| ^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/concat-in-crate-name-issue-137687.rs:1:9
9+
|
10+
LL | #![deny(unused)]
11+
| ^^^^^^
12+
= note: `#[deny(unused_macros)]` implied by `#[deny(unused)]`
13+
14+
error: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
15+
--> $DIR/concat-in-crate-name-issue-137687.rs:3:1
16+
|
17+
LL | #[crate_name = concat !()]
18+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
19+
|
20+
= note: `#[deny(unused_attributes)]` implied by `#[deny(unused)]`
21+
22+
error: aborting due to 2 previous errors
23+

tests/ui/resolve/path-attr-in-const-block.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ fn main() {
55
const {
66
#![path = foo!()]
77
//~^ ERROR: cannot find macro `foo` in this scope
8+
//~| ERROR: attribute value must be a literal
89
}
910
}

tests/ui/resolve/path-attr-in-const-block.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,11 @@ error: cannot find macro `foo` in this scope
44
LL | #![path = foo!()]
55
| ^^^
66

7-
error: aborting due to 1 previous error
7+
error: attribute value must be a literal
8+
--> $DIR/path-attr-in-const-block.rs:6:19
9+
|
10+
LL | #![path = foo!()]
11+
| ^^^^^^
12+
13+
error: aborting due to 2 previous errors
814

0 commit comments

Comments
 (0)