Skip to content

Commit

Permalink
builtin_macros: Make #[derive(A, B, ...)] cfg-eval its input only for…
Browse files Browse the repository at this point in the history
… `A, B, ...`
  • Loading branch information
petrochenkov committed Sep 24, 2021
1 parent f06f9bb commit c993984
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/derive.rs
Expand Up @@ -26,7 +26,7 @@ impl MultiItemModifier for Expander {
return ExpandResult::Ready(vec![item]);
}

let item = cfg_eval(ecx, item);
let configured_item = cfg_eval(ecx, item.clone());

let result =
ecx.resolver.resolve_derives(ecx.current_expansion.id, ecx.force_mode, &|| {
Expand Down Expand Up @@ -56,7 +56,7 @@ impl MultiItemModifier for Expander {
report_path_args(sess, &meta);
meta.path
})
.map(|path| (path, item.clone(), None))
.map(|path| (path, configured_item.clone(), None))
.collect()
});

Expand Down
48 changes: 46 additions & 2 deletions src/test/ui/proc-macro/attribute-after-derive.stdout
Expand Up @@ -130,7 +130,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
span: $DIR/attribute-after-derive.rs:25:24: 28:2 (#0),
},
]
PRINT-ATTR INPUT (DISPLAY): struct DeriveAttribute { }
PRINT-ATTR INPUT (DISPLAY): struct DeriveAttribute { #[cfg(FALSE)] field : u8, }
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "struct",
Expand All @@ -142,7 +142,51 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
},
Group {
delimiter: Brace,
stream: TokenStream [],
stream: TokenStream [
Punct {
ch: '#',
spacing: Alone,
span: $DIR/attribute-after-derive.rs:26:5: 26:6 (#0),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "cfg",
span: $DIR/attribute-after-derive.rs:26:7: 26:10 (#0),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "FALSE",
span: $DIR/attribute-after-derive.rs:26:11: 26:16 (#0),
},
],
span: $DIR/attribute-after-derive.rs:26:10: 26:17 (#0),
},
],
span: $DIR/attribute-after-derive.rs:26:6: 26:18 (#0),
},
Ident {
ident: "field",
span: $DIR/attribute-after-derive.rs:27:5: 27:10 (#0),
},
Punct {
ch: ':',
spacing: Alone,
span: $DIR/attribute-after-derive.rs:27:10: 27:11 (#0),
},
Ident {
ident: "u8",
span: $DIR/attribute-after-derive.rs:27:12: 27:14 (#0),
},
Punct {
ch: ',',
spacing: Alone,
span: $DIR/attribute-after-derive.rs:27:14: 27:15 (#0),
},
],
span: $DIR/attribute-after-derive.rs:25:24: 28:2 (#0),
},
]

0 comments on commit c993984

Please sign in to comment.