mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
Auto merge of #16812 - ShoyuVanilla:issue-3739, r=Veykril
fix: Goto implementation to impls inside blocks Fixes #3739
This commit is contained in:
commit
e03df77d04
2 changed files with 97 additions and 1 deletions
|
@ -3628,16 +3628,41 @@ impl Impl {
|
||||||
.filter(filter),
|
.filter(filter),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(block) =
|
||||||
|
ty.adt_id(Interner).and_then(|def| def.0.module(db.upcast()).containing_block())
|
||||||
|
{
|
||||||
|
if let Some(inherent_impls) = db.inherent_impls_in_block(block) {
|
||||||
|
all.extend(
|
||||||
|
inherent_impls.for_self_ty(&ty).iter().cloned().map(Self::from).filter(filter),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if let Some(trait_impls) = db.trait_impls_in_block(block) {
|
||||||
|
all.extend(
|
||||||
|
trait_impls
|
||||||
|
.for_self_ty_without_blanket_impls(fp)
|
||||||
|
.map(Self::from)
|
||||||
|
.filter(filter),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
all
|
all
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn all_for_trait(db: &dyn HirDatabase, trait_: Trait) -> Vec<Impl> {
|
pub fn all_for_trait(db: &dyn HirDatabase, trait_: Trait) -> Vec<Impl> {
|
||||||
let krate = trait_.module(db).krate();
|
let module = trait_.module(db);
|
||||||
|
let krate = module.krate();
|
||||||
let mut all = Vec::new();
|
let mut all = Vec::new();
|
||||||
for Crate { id } in krate.transitive_reverse_dependencies(db) {
|
for Crate { id } in krate.transitive_reverse_dependencies(db) {
|
||||||
let impls = db.trait_impls_in_crate(id);
|
let impls = db.trait_impls_in_crate(id);
|
||||||
all.extend(impls.for_trait(trait_.id).map(Self::from))
|
all.extend(impls.for_trait(trait_.id).map(Self::from))
|
||||||
}
|
}
|
||||||
|
if let Some(block) = module.id.containing_block() {
|
||||||
|
if let Some(trait_impls) = db.trait_impls_in_block(block) {
|
||||||
|
all.extend(trait_impls.for_trait(trait_.id).map(Self::from));
|
||||||
|
}
|
||||||
|
}
|
||||||
all
|
all
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -337,6 +337,77 @@ impl Tr for S {
|
||||||
const C: usize = 4;
|
const C: usize = 4;
|
||||||
//^
|
//^
|
||||||
}
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn goto_adt_implementation_inside_block() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
//- minicore: copy, derive
|
||||||
|
trait Bar {}
|
||||||
|
|
||||||
|
fn test() {
|
||||||
|
#[derive(Copy)]
|
||||||
|
//^^^^^^^^^^^^^^^
|
||||||
|
struct Foo$0;
|
||||||
|
|
||||||
|
impl Foo {}
|
||||||
|
//^^^
|
||||||
|
|
||||||
|
trait Baz {}
|
||||||
|
|
||||||
|
impl Bar for Foo {}
|
||||||
|
//^^^
|
||||||
|
|
||||||
|
impl Baz for Foo {}
|
||||||
|
//^^^
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn goto_trait_implementation_inside_block() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
struct Bar;
|
||||||
|
|
||||||
|
fn test() {
|
||||||
|
trait Foo$0 {}
|
||||||
|
|
||||||
|
struct Baz;
|
||||||
|
|
||||||
|
impl Foo for Bar {}
|
||||||
|
//^^^
|
||||||
|
|
||||||
|
impl Foo for Baz {}
|
||||||
|
//^^^
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
struct Bar;
|
||||||
|
|
||||||
|
fn test() {
|
||||||
|
trait Foo {
|
||||||
|
fn foo$0() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Baz;
|
||||||
|
|
||||||
|
impl Foo for Bar {
|
||||||
|
fn foo() {}
|
||||||
|
//^^^
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Foo for Baz {
|
||||||
|
fn foo() {}
|
||||||
|
//^^^
|
||||||
|
}
|
||||||
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue