Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions crates/hir-def/src/expr_store/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2404,6 +2404,10 @@ impl<'db> ExprCollector<'db> {
statements: &mut Vec<Statement>,
mac: ast::MacroExpr,
) -> Option<ExprId> {
if !self.check_cfg(&ast::Expr::MacroExpr(mac.clone())) {
return None;
}

let mac_call = mac.macro_call()?;
let syntax_ptr = AstPtr::new(&ast::Expr::from(mac));
let macro_ptr = AstPtr::new(&mac_call);
Expand Down Expand Up @@ -2447,10 +2451,6 @@ impl<'db> ExprCollector<'db> {
}
ast::Stmt::ExprStmt(stmt) => {
let expr = stmt.expr();
match &expr {
Some(expr) if !self.check_cfg(expr) => return,
_ => (),
}
let has_semi = stmt.semicolon_token().is_some();
// Note that macro could be expanded to multiple statements
if let Some(ast::Expr::MacroExpr(mac)) = expr {
Expand Down
28 changes: 28 additions & 0 deletions crates/hir-def/src/expr_store/tests/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,3 +688,31 @@ fn foo() {
}"#]],
);
}

#[test]
fn foo() {
pretty_print(
r#"
macro_rules! foo {
() => {
1
};
}

fn foo() -> i64 {
#[cfg(true)]
{
5
}
#[cfg(false)]
foo!()
}
"#,
expect![[r#"
fn foo() {
{
5
}
}"#]],
);
}