Run cfg-stripping on generic parameters before invoking derive macros
Fixes #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.
This commit is contained in:
parent
85fbf49ce0
commit
a97dcfa375
@ -403,10 +403,6 @@ impl<'a> StripUnconfigured<'a> {
|
|||||||
items.flat_map_in_place(|item| self.configure(item));
|
items.flat_map_in_place(|item| self.configure(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn configure_generic_params(&mut self, params: &mut Vec<ast::GenericParam>) {
|
|
||||||
params.flat_map_in_place(|param| self.configure(param));
|
|
||||||
}
|
|
||||||
|
|
||||||
fn configure_variant_data(&mut self, vdata: &mut ast::VariantData) {
|
fn configure_variant_data(&mut self, vdata: &mut ast::VariantData) {
|
||||||
match vdata {
|
match vdata {
|
||||||
ast::VariantData::Struct(fields, ..) | ast::VariantData::Tuple(fields, _) => {
|
ast::VariantData::Struct(fields, ..) | ast::VariantData::Tuple(fields, _) => {
|
||||||
@ -496,6 +492,13 @@ impl<'a> MutVisitor for StripUnconfigured<'a> {
|
|||||||
Some(expr)
|
Some(expr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn flat_map_generic_param(
|
||||||
|
&mut self,
|
||||||
|
param: ast::GenericParam,
|
||||||
|
) -> SmallVec<[ast::GenericParam; 1]> {
|
||||||
|
noop_flat_map_generic_param(configure!(self, param), self)
|
||||||
|
}
|
||||||
|
|
||||||
fn flat_map_stmt(&mut self, stmt: ast::Stmt) -> SmallVec<[ast::Stmt; 1]> {
|
fn flat_map_stmt(&mut self, stmt: ast::Stmt) -> SmallVec<[ast::Stmt; 1]> {
|
||||||
noop_flat_map_stmt(configure!(self, stmt), self)
|
noop_flat_map_stmt(configure!(self, stmt), self)
|
||||||
}
|
}
|
||||||
|
30
src/test/ui/proc-macro/issue-75930-derive-cfg.rs
Normal file
30
src/test/ui/proc-macro/issue-75930-derive-cfg.rs
Normal file
@ -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() {}
|
221
src/test/ui/proc-macro/issue-75930-derive-cfg.stdout
Normal file
221
src/test/ui/proc-macro/issue-75930-derive-cfg.stdout
Normal file
@ -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),
|
||||||
|
},
|
||||||
|
]
|
Loading…
x
Reference in New Issue
Block a user