Skip to content

Commit dfc0797

Browse files
committed
fix: don't qualify macro names in pattern bindings
1 parent c585d26 commit dfc0797

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src/tools/rust-analyzer/crates/ide-db/src/path_transform.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -538,14 +538,6 @@ impl Ctx<'_> {
538538
editor: &mut SyntaxEditor,
539539
ident_pat: &ast::IdentPat,
540540
) -> Option<()> {
541-
// Check if IdentPat is inside a function parameter.
542-
// Parameter names are bindings, not references, thus should not be qualified.
543-
for ancestor in ident_pat.syntax().ancestors() {
544-
if ast::Param::can_cast(ancestor.kind()) {
545-
return None;
546-
}
547-
}
548-
549541
let name = ident_pat.name()?;
550542

551543
let temp_path = make::path_from_text(&name.text());
@@ -554,7 +546,9 @@ impl Ctx<'_> {
554546

555547
match resolution {
556548
hir::PathResolution::Def(def) if def.as_assoc_item(self.source_scope.db).is_none() => {
557-
// Don't qualify macros - they can't be used in pattern position
549+
// Macros cannot be used in pattern position, and identifiers that happen
550+
// to have the same name as macros (like parameter names `vec`, `format`, etc.)
551+
// are bindings, not references. Don't qualify them.
558552
if matches!(def, hir::ModuleDef::Macro(_)) {
559553
return None;
560554
}

0 commit comments

Comments
 (0)