From 9fc5ceff0eaec7cfeacce0b5fc6bea36b056083c Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 16 Dec 2024 13:17:59 +0100 Subject: fix: Fix path qualified auto-importing completions not working with re-exports Prior to this commit we used to generate import paths, then zipped them with the existing qualifier to check if they agree on the path to import. This is brittle when re-exports come into play causing items to have multiple applicable paths that refer to them. This commit instead rewrites this logic by generating the import path for the qualifier, verifying that the rest of the qualifier resolves and then doing a final lookup on that resolution result for the final segment instead. --- .../crates/ide-completion/src/tests/flyimport.rs | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/tools/rust-analyzer/crates/ide-completion') diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/tests/flyimport.rs b/src/tools/rust-analyzer/crates/ide-completion/src/tests/flyimport.rs index 4b949e0d657..f31b0d4910a 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/tests/flyimport.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/tests/flyimport.rs @@ -1720,3 +1720,45 @@ fn function() { "#]], ); } + +#[test] +fn intrinsics() { + check( + r#" + //- /core.rs crate:core + pub mod intrinsics { + extern "rust-intrinsic" { + pub fn transmute(src: Src) -> Dst; + } + } + pub mod mem { + pub use crate::intrinsics::transmute; + } + //- /main.rs crate:main deps:core + fn function() { + transmute$0 + } + "#, + expect![[r#" + fn transmute(…) (use core::mem::transmute) unsafe fn(Src) -> Dst + "#]], + ); + check( + r#" +//- /core.rs crate:core +pub mod intrinsics { + extern "rust-intrinsic" { + pub fn transmute(src: Src) -> Dst; + } +} +pub mod mem { + pub use crate::intrinsics::transmute; +} +//- /main.rs crate:main deps:core +fn function() { + mem::transmute$0 +} +"#, + expect![""], + ); +} -- cgit 1.4.1-3-g733a5