From 71d816caf5e66b2f2980188543a8fb7417cbbb39 Mon Sep 17 00:00:00 2001 From: Arthur Baars Date: Fri, 13 Sep 2024 13:53:16 +0200 Subject: [PATCH] Fix ambiguity --- rust/extractor/src/translate.rs | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/rust/extractor/src/translate.rs b/rust/extractor/src/translate.rs index f7848290ba09f..a6ad8dcbac1a6 100644 --- a/rust/extractor/src/translate.rs +++ b/rust/extractor/src/translate.rs @@ -8,7 +8,8 @@ use ra_ap_hir::TypeRef; use ra_ap_hir::{Crate, Module, ModuleDef}; use ra_ap_hir_def::body::{Body, BodySourceMap}; use ra_ap_hir_def::hir::{ - CaptureBy, ExprId, LabelId, MatchArm, PatId, RecordFieldPat, RecordLitField, Statement, + BindingAnnotation, CaptureBy, ExprId, LabelId, MatchArm, PatId, RecordFieldPat, RecordLitField, + Statement, }; use ra_ap_hir_def::path::Path; use ra_ap_ide_db::line_index::LineIndex; @@ -310,6 +311,7 @@ impl CrateTranslator<'_> { suffix, }) } + ra_ap_hir_def::hir::Pat::Path(path) => { let path = self.emit_path(path, location); self.trap.emit(generated::PathPat { @@ -327,13 +329,24 @@ impl CrateTranslator<'_> { }) } ra_ap_hir_def::hir::Pat::Bind { id, subpat } => { - let subpat = subpat.map(|pat| self.emit_pat(pat, body, source_map)); - self.trap.emit(generated::IdentPat { - id: TrapId::Star, - location, - subpat, - binding_id: body.bindings[*id].name.as_str().into(), - }) + let binding = &body.bindings[*id]; + if binding.mode == BindingAnnotation::Unannotated && subpat.is_none() { + let name = binding.name.to_owned(); + let path = self.emit_path(&name.into(), location); + self.trap.emit(generated::PathPat { + id: TrapId::Star, + location, + path, + }) + } else { + let subpat = subpat.map(|pat| self.emit_pat(pat, body, source_map)); + self.trap.emit(generated::IdentPat { + id: TrapId::Star, + location, + subpat, + binding_id: binding.name.as_str().into(), + }) + } } ra_ap_hir_def::hir::Pat::TupleStruct { path,