mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 01:17:27 +00:00
Merge #8990
8990: feat: Also do goto implementation on assoc consts r=lnicola a=lf- I forgot to put this into #8988, sorry. Goto implementation on a const on the trait will go to the implementations with their respective definitions of the const, if present. Co-authored-by: Jade <software@lfcode.ca>
This commit is contained in:
commit
35db5e99f6
1 changed files with 26 additions and 2 deletions
|
@ -53,7 +53,13 @@ pub(crate) fn goto_implementation(
|
|||
let assoc = f.as_assoc_item(sema.db)?;
|
||||
let name = assoc.name(sema.db)?;
|
||||
let trait_ = assoc.containing_trait(sema.db)?;
|
||||
impls_for_trait_fn(&sema, trait_, name)
|
||||
impls_for_trait_item(&sema, trait_, name)
|
||||
}
|
||||
hir::ModuleDef::Const(c) => {
|
||||
let assoc = c.as_assoc_item(sema.db)?;
|
||||
let name = assoc.name(sema.db)?;
|
||||
let trait_ = assoc.containing_trait(sema.db)?;
|
||||
impls_for_trait_item(&sema, trait_, name)
|
||||
}
|
||||
_ => return None,
|
||||
};
|
||||
|
@ -71,7 +77,7 @@ fn impls_for_trait(sema: &Semantics<RootDatabase>, trait_: hir::Trait) -> Vec<Na
|
|||
.collect()
|
||||
}
|
||||
|
||||
fn impls_for_trait_fn(
|
||||
fn impls_for_trait_item(
|
||||
sema: &Semantics<RootDatabase>,
|
||||
trait_: hir::Trait,
|
||||
fun_name: hir::Name,
|
||||
|
@ -303,6 +309,24 @@ impl Tr for S {
|
|||
println!("Hello, world!");
|
||||
}
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn goto_implementation_trait_assoc_const() {
|
||||
check(
|
||||
r#"
|
||||
trait Tr {
|
||||
const C$0: usize;
|
||||
}
|
||||
|
||||
struct S;
|
||||
|
||||
impl Tr for S {
|
||||
const C: usize = 4;
|
||||
//^
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue