Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/ide-assists/src/handlers/add_missing_impl_members.rs80
-rw-r--r--crates/ide-db/src/path_transform.rs5
2 files changed, 85 insertions, 0 deletions
diff --git a/crates/ide-assists/src/handlers/add_missing_impl_members.rs b/crates/ide-assists/src/handlers/add_missing_impl_members.rs
index 65ca1ceae1..afdced4215 100644
--- a/crates/ide-assists/src/handlers/add_missing_impl_members.rs
+++ b/crates/ide-assists/src/handlers/add_missing_impl_members.rs
@@ -2537,4 +2537,84 @@ impl Test for () {
"#,
);
}
+
+ #[test]
+ fn test_param_name_not_qualified() {
+ check_assist(
+ add_missing_impl_members,
+ r#"
+mod ptr {
+ pub struct NonNull<T>(T);
+}
+mod alloc {
+ use super::ptr::NonNull;
+ pub trait Allocator {
+ unsafe fn deallocate(&self, ptr: NonNull<u8>);
+ }
+}
+
+struct System;
+
+unsafe impl alloc::Allocator for System {
+ $0
+}
+"#,
+ r#"
+mod ptr {
+ pub struct NonNull<T>(T);
+}
+mod alloc {
+ use super::ptr::NonNull;
+ pub trait Allocator {
+ unsafe fn deallocate(&self, ptr: NonNull<u8>);
+ }
+}
+
+struct System;
+
+unsafe impl alloc::Allocator for System {
+ unsafe fn deallocate(&self, ptr: ptr::NonNull<u8>) {
+ ${0:todo!()}
+ }
+}
+"#,
+ );
+ }
+
+ #[test]
+ fn test_param_name_shadows_module() {
+ check_assist(
+ add_missing_impl_members,
+ r#"
+mod m { }
+use m as p;
+
+pub trait Allocator {
+ fn deallocate(&self, p: u8);
+}
+
+struct System;
+
+impl Allocator for System {
+ $0
+}
+"#,
+ r#"
+mod m { }
+use m as p;
+
+pub trait Allocator {
+ fn deallocate(&self, p: u8);
+}
+
+struct System;
+
+impl Allocator for System {
+ fn deallocate(&self, p: u8) {
+ ${0:todo!()}
+ }
+}
+"#,
+ );
+ }
}
diff --git a/crates/ide-db/src/path_transform.rs b/crates/ide-db/src/path_transform.rs
index 48305c2082..d0a28e7d2f 100644
--- a/crates/ide-db/src/path_transform.rs
+++ b/crates/ide-db/src/path_transform.rs
@@ -553,6 +553,11 @@ impl Ctx<'_> {
return None;
}
+ // Similarly, modules cannot be used in pattern position.
+ if matches!(def, hir::ModuleDef::Module(_)) {
+ return None;
+ }
+
let cfg = FindPathConfig {
prefer_no_std: false,
prefer_prelude: true,