-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Port #[crate_name] to the new attribute parsing infrastructure
#137729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
3bf6144
4b35cde
59ceb02
48a4e2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| //@ check-pass | ||
| #[deprecated = concat !()] | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. regression test for a new case of #137687
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| macro_rules! a { | ||
| () => {}; | ||
| } | ||
| fn main() {} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #![deny(unused)] | ||
|
|
||
| #[crate_name = concat !()] | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. regression test for #137687 (ICEs on stable currently: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=fc3557244535c7ed2a625b5741cc6e5f) |
||
| //~^ ERROR crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo] | ||
| macro_rules! a { | ||
| //~^ ERROR unused macro definition | ||
| () => {}; | ||
| } | ||
| fn main() {} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| error: unused macro definition: `a` | ||
| --> $DIR/concat-in-crate-name-issue-137687.rs:5:14 | ||
| | | ||
| LL | macro_rules! a { | ||
| | ^ | ||
| | | ||
| note: the lint level is defined here | ||
| --> $DIR/concat-in-crate-name-issue-137687.rs:1:9 | ||
| | | ||
| LL | #![deny(unused)] | ||
| | ^^^^^^ | ||
| = note: `#[deny(unused_macros)]` implied by `#[deny(unused)]` | ||
|
|
||
| error: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]` | ||
| --> $DIR/concat-in-crate-name-issue-137687.rs:3:1 | ||
| | | ||
| LL | #[crate_name = concat !()] | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = note: `#[deny(unused_attributes)]` implied by `#[deny(unused)]` | ||
|
|
||
| error: aborting due to 2 previous errors | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,5 +4,11 @@ error: cannot find macro `foo` in this scope | |
| LL | #![path = foo!()] | ||
| | ^^^ | ||
|
|
||
| error: aborting due to 1 previous error | ||
| error: attribute value must be a literal | ||
| --> $DIR/path-attr-in-const-block.rs:6:19 | ||
| | | ||
| LL | #![path = foo!()] | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extra error, but this is correct/expected. bonus! |
||
| | ^^^^^^ | ||
|
|
||
| error: aborting due to 2 previous errors | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's a subtle bug in this version, fixed in my last commit. When an expression in an attribute is a macro, and the macro expands to a literal, and we parse an attribute with ShouldEmit::Nothing, we would delay that as a bug expecting a second parse to emit the error. However, when the macro then expands to a literal, we don't hit the same codepath and we never emit an error about this. The delayed bug turns into an ICE.
A very similar problem was happening in February already (#137687) which was recognized and even a backport was made for it. However, in later versions it still made it to stable.
The last commit of this PR adds tests for these cases and fixes this by, when we expect a literal, but have ShouldEmit::Nothing, we don't delay a bug, instead we do nothing. This is correct because if the macro indeed turns into a literal, the second parse might very well be correct. We shouldn't have delayed a bug at all.
Specifically for crate_name, we parse with ShouldEmit::EarlyFatal so when it cares about this being a literal, it will error about it as it should.