Skip to content

Commit 4fd1cdb

Browse files
authored
Merge pull request #19937 from Veykril/push-rvnylnlnxxyr
fix: Record macro calls for fields in `ChildBySource` impls
2 parents cad9cc9 + 8e217cc commit 4fd1cdb

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

crates/hir/src/semantics/child_by_source.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ impl ChildBySource for VariantId {
191191
Either::Right(source) => res[keys::RECORD_FIELD].insert(AstPtr::new(&source), id),
192192
}
193193
}
194+
let (_, sm) = db.variant_fields_with_source_map(*self);
195+
sm.expansions().for_each(|(ast, &exp_id)| res[keys::MACRO_CALL].insert(ast.value, exp_id));
194196
}
195197
}
196198

@@ -209,11 +211,10 @@ impl ChildBySource for EnumId {
209211
.insert(ast_id_map.get(tree[variant.lookup(db).id.value].ast_id), variant);
210212
});
211213
let (_, source_map) = db.enum_signature_with_source_map(*self);
212-
source_map.expansions().filter(|(ast, _)| ast.file_id == file_id).for_each(
213-
|(ast, &exp_id)| {
214-
res[keys::MACRO_CALL].insert(ast.value, exp_id);
215-
},
216-
);
214+
source_map
215+
.expansions()
216+
.filter(|(ast, _)| ast.file_id == file_id)
217+
.for_each(|(ast, &exp_id)| res[keys::MACRO_CALL].insert(ast.value, exp_id));
217218
}
218219
}
219220

@@ -274,11 +275,10 @@ impl ChildBySource for GenericDefId {
274275
}
275276
}
276277

277-
source_map.expansions().filter(|(ast, _)| ast.file_id == file_id).for_each(
278-
|(ast, &exp_id)| {
279-
res[keys::MACRO_CALL].insert(ast.value, exp_id);
280-
},
281-
);
278+
source_map
279+
.expansions()
280+
.filter(|(ast, _)| ast.file_id == file_id)
281+
.for_each(|(ast, &exp_id)| res[keys::MACRO_CALL].insert(ast.value, exp_id));
282282
}
283283
}
284284

crates/ide/src/expand_macro.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,4 +844,21 @@ impl<const C: foo$0!()> Trait for () {}
844844
Trait"#]],
845845
);
846846
}
847+
848+
#[test]
849+
fn works_in_fields() {
850+
check(
851+
r#"
852+
macro_rules! foo {
853+
() => { u32 };
854+
}
855+
struct S {
856+
field: foo$0!(),
857+
}
858+
"#,
859+
expect![[r#"
860+
foo!
861+
u32"#]],
862+
);
863+
}
847864
}

crates/rust-analyzer/tests/slow-tests/ratoml.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ assist.emitMustUse = true"#,
439439
}
440440

441441
#[test]
442+
#[ignore = "flaky test that tends to hang"]
442443
fn ratoml_inherit_config_from_ws_root() {
443444
if skip_slow_tests() {
444445
return;

0 commit comments

Comments
 (0)