-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
expand: Preserve order of inert attributes during expansion #82419
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// aux-build:test-macros.rs | ||
|
||
#![dummy] //~ ERROR cannot find attribute `dummy` in this scope | ||
|
||
#[macro_use] | ||
extern crate test_macros; | ||
|
||
#[derive(Empty)] //~ ERROR cannot determine resolution for the attribute macro `derive` | ||
#[empty_helper] //~ ERROR cannot find attribute `empty_helper` in this scope | ||
struct Foo {} | ||
|
||
fn main() {} |
22 changes: 22 additions & 0 deletions
22
src/test/ui/proc-macro/derive-helper-legacy-spurious.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
error: cannot find attribute `dummy` in this scope | ||
--> $DIR/derive-helper-legacy-spurious.rs:3:4 | ||
| | ||
LL | #![dummy] | ||
| ^^^^^ | ||
|
||
error: cannot determine resolution for the attribute macro `derive` | ||
--> $DIR/derive-helper-legacy-spurious.rs:8:3 | ||
| | ||
LL | #[derive(Empty)] | ||
| ^^^^^^ | ||
| | ||
= note: import resolution is stuck, try simplifying macro imports | ||
|
||
error: cannot find attribute `empty_helper` in this scope | ||
--> $DIR/derive-helper-legacy-spurious.rs:9:3 | ||
| | ||
LL | #[empty_helper] | ||
| ^^^^^^^^^^^^ | ||
|
||
error: aborting due to 3 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Order of inert attributes, both built-in and custom is preserved during expansion. | ||
|
||
// check-pass | ||
// compile-flags: -Z span-debug | ||
// aux-build:test-macros.rs | ||
|
||
#![no_std] // Don't load unnecessary hygiene information from std | ||
extern crate std; | ||
|
||
#[macro_use] | ||
extern crate test_macros; | ||
|
||
/// 1 | ||
#[rustfmt::attr2] | ||
#[doc = "3"] | ||
#[print_attr(nodebug)] | ||
#[doc = "4"] | ||
#[rustfmt::attr5] | ||
/// 6 | ||
#[print_attr(nodebug)] | ||
struct S; | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
PRINT-ATTR INPUT (DISPLAY): /// 1 | ||
#[rustfmt :: attr2] #[doc = "3"] #[doc = "4"] #[rustfmt :: attr5] /// 6 | ||
#[print_attr(nodebug)] struct S ; | ||
PRINT-ATTR RE-COLLECTED (DISPLAY): #[doc = " 1"] #[rustfmt :: attr2] #[doc = "3"] #[doc = "4"] | ||
#[rustfmt :: attr5] #[doc = " 6"] #[print_attr(nodebug)] struct S ; | ||
PRINT-ATTR INPUT (DISPLAY): #[doc = " 1"] #[rustfmt :: attr2] #[doc = "3"] #[doc = "4"] | ||
#[rustfmt :: attr5] #[doc = " 6"] struct S ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is a subtle detail that I just noticed - since we perform cfg-stripping before invoking custom attributes (e.g.
#[my_attr] #[cfg(FALSE)] struct Foo {}
does nothing), we also expand#[cfg_attr]
. So, an attribute macro sees expanded#[cfg_attr]
attributes (e.g. the#[allow(dead_code)]
) at the 'top level' of the attribute target, but not anywhere else. For example, you can see#[cfg_attr(not(FALSE), allow(warnings))]
in the input below.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.
This is something I want to change, btw (and make the expansion order fully left-to-right).
It will certainly needs a crater run, but I think we'll be able to do this in practice, similarly to #79078.