Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/hir-def/src/macro_expansion_tests/proc_macros.rs19
-rw-r--r--crates/hir-expand/src/cfg_process.rs24
2 files changed, 28 insertions, 15 deletions
diff --git a/crates/hir-def/src/macro_expansion_tests/proc_macros.rs b/crates/hir-def/src/macro_expansion_tests/proc_macros.rs
index 5216246910..6f30ca04af 100644
--- a/crates/hir-def/src/macro_expansion_tests/proc_macros.rs
+++ b/crates/hir-def/src/macro_expansion_tests/proc_macros.rs
@@ -341,3 +341,22 @@ struct Foo;
#[helper_should_be_ignored] struct Foo;"#]],
);
}
+
+#[test]
+fn attribute_macro_stripping_with_cfg() {
+ check(
+ r#"
+//- proc_macros: generate_suffixed_type
+#[cfg(all())]
+#[proc_macros::generate_suffixed_type]
+struct S;
+"#,
+ expect![[r#"
+#[cfg(all())]
+#[proc_macros::generate_suffixed_type]
+struct S;
+
+struct S;
+struct SSuffix;"#]],
+ );
+}
diff --git a/crates/hir-expand/src/cfg_process.rs b/crates/hir-expand/src/cfg_process.rs
index 227a62ff9f..a0de36548e 100644
--- a/crates/hir-expand/src/cfg_process.rs
+++ b/crates/hir-expand/src/cfg_process.rs
@@ -162,25 +162,19 @@ fn macro_input_callback(
}
}
Meta::TokenTree { path, tt } => {
- if path.segments.len() != 1
+ if path.is1("cfg") {
+ let cfg_expr = CfgExpr::parse_from_ast(
+ &mut TokenTreeChildren::new(&tt).peekable(),
+ );
+ if cfg_options().check(&cfg_expr) == Some(false) {
+ return ControlFlow::Break(ItemIsCfgedOut);
+ }
+ strip_current_attr = true;
+ } else if path.segments.len() != 1
|| !is_item_tree_filtered_attr(path.segments[0].text())
{
strip_current_attr = should_strip_attr();
}
-
- if path.segments.len() == 1 {
- let name = path.segments[0].text();
-
- if name == "cfg" {
- let cfg_expr = CfgExpr::parse_from_ast(
- &mut TokenTreeChildren::new(&tt).peekable(),
- );
- if cfg_options().check(&cfg_expr) == Some(false) {
- return ControlFlow::Break(ItemIsCfgedOut);
- }
- strip_current_attr = true;
- }
- }
}
Meta::Path { path } => {
if path.segments.len() != 1