diff --git a/crates/ide/src/rename.rs b/crates/ide/src/rename.rs index 96bd07708c8..4f5f2c935c2 100644 --- a/crates/ide/src/rename.rs +++ b/crates/ide/src/rename.rs @@ -1716,6 +1716,25 @@ impl Foo for () { ); } + #[test] + fn test_rename_trait_method_prefix_of_second() { + check( + "qux", + r#" +trait Foo { + fn foo$0() {} + fn foobar() {} +} +"#, + r#" +trait Foo { + fn qux() {} + fn foobar() {} +} +"#, + ); + } + #[test] fn test_rename_trait_const() { let res = r" diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs index a840e06a604..baed5e88082 100644 --- a/crates/ide_db/src/search.rs +++ b/crates/ide_db/src/search.rs @@ -544,7 +544,9 @@ impl<'a> FindUsages<'a> { let trait_ = mod_def .as_assoc_item(self.sema.db)? .containing_trait_or_trait_impl(self.sema.db)?; - (trait_ == this_trait).then(|| { + (trait_ == this_trait + && self.def.name(self.sema.db) == mod_def.name(self.sema.db)) + .then(|| { let FileRange { file_id, range } = self.sema.original_range(name.syntax()); let reference = FileReference { range,