forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#76010 - Aaron1011:fix/cfg-generic-param, r=pe…
…trochenkov Run cfg-stripping on generic parameters before invoking derive macros Fixes rust-lang#75930 This changes the tokens seen by a proc-macro. However, ising a `#[cfg]` attribute on a generic paramter is unusual, and combining it with a proc-macro derive is probably even more unusual. I don't expect this to cause any breakage.
- Loading branch information
Showing
3 changed files
with
258 additions
and
4 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// check-pass | ||
// compile-flags: -Z span-debug | ||
// aux-build:test-macros.rs | ||
|
||
// Regression test for issue #75930 | ||
// Tests that we cfg-strip all targets before invoking | ||
// a derive macro | ||
|
||
#[macro_use] | ||
extern crate test_macros; | ||
|
||
#[derive(Print)] | ||
struct Foo<#[cfg(FALSE)] A, B> { | ||
#[cfg(FALSE)] first: String, | ||
second: bool, | ||
third: [u8; { | ||
#[cfg(FALSE)] struct Bar; | ||
#[cfg(not(FALSE))] struct Inner; | ||
#[cfg(FALSE)] let a = 25; | ||
match true { | ||
#[cfg(FALSE)] true => {}, | ||
false => {}, | ||
_ => {} | ||
}; | ||
0 | ||
}], | ||
fourth: B | ||
} | ||
|
||
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,221 @@ | ||
PRINT-DERIVE INPUT (DISPLAY): struct Foo < B > | ||
{ | ||
second : bool, third : | ||
[u8 ; | ||
{ | ||
#[cfg(not(FALSE))] struct Inner ; match true | ||
{ false => { } _ => { } } ; 0 | ||
}], fourth : B, | ||
} | ||
PRINT-DERIVE INPUT (DEBUG): TokenStream [ | ||
Ident { | ||
ident: "struct", | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Ident { | ||
ident: "Foo", | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Punct { | ||
ch: '<', | ||
spacing: Alone, | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Ident { | ||
ident: "B", | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Punct { | ||
ch: '>', | ||
spacing: Alone, | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Group { | ||
delimiter: Brace, | ||
stream: TokenStream [ | ||
Ident { | ||
ident: "second", | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Punct { | ||
ch: ':', | ||
spacing: Alone, | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Ident { | ||
ident: "bool", | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Punct { | ||
ch: ',', | ||
spacing: Alone, | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Ident { | ||
ident: "third", | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Punct { | ||
ch: ':', | ||
spacing: Alone, | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Group { | ||
delimiter: Bracket, | ||
stream: TokenStream [ | ||
Ident { | ||
ident: "u8", | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Punct { | ||
ch: ';', | ||
spacing: Alone, | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Group { | ||
delimiter: Brace, | ||
stream: TokenStream [ | ||
Punct { | ||
ch: '#', | ||
spacing: Alone, | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Group { | ||
delimiter: Bracket, | ||
stream: TokenStream [ | ||
Ident { | ||
ident: "cfg", | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Group { | ||
delimiter: Parenthesis, | ||
stream: TokenStream [ | ||
Ident { | ||
ident: "not", | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Group { | ||
delimiter: Parenthesis, | ||
stream: TokenStream [ | ||
Ident { | ||
ident: "FALSE", | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
], | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
], | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
], | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Ident { | ||
ident: "struct", | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Ident { | ||
ident: "Inner", | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Punct { | ||
ch: ';', | ||
spacing: Alone, | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Ident { | ||
ident: "match", | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Ident { | ||
ident: "true", | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Group { | ||
delimiter: Brace, | ||
stream: TokenStream [ | ||
Ident { | ||
ident: "false", | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Punct { | ||
ch: '=', | ||
spacing: Joint, | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Punct { | ||
ch: '>', | ||
spacing: Alone, | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Group { | ||
delimiter: Brace, | ||
stream: TokenStream [], | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Ident { | ||
ident: "_", | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Punct { | ||
ch: '=', | ||
spacing: Joint, | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Punct { | ||
ch: '>', | ||
spacing: Alone, | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Group { | ||
delimiter: Brace, | ||
stream: TokenStream [], | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
], | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Punct { | ||
ch: ';', | ||
spacing: Alone, | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Literal { | ||
kind: Integer, | ||
symbol: "0", | ||
suffix: None, | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
], | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
], | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Punct { | ||
ch: ',', | ||
spacing: Alone, | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Ident { | ||
ident: "fourth", | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Punct { | ||
ch: ':', | ||
spacing: Alone, | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Ident { | ||
ident: "B", | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
Punct { | ||
ch: ',', | ||
spacing: Alone, | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
], | ||
span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), | ||
}, | ||
] |