diff options
| author | Jade <software@lfcode.ca> | 2021-05-25 06:27:41 -0700 |
|---|---|---|
| committer | Jade <software@lfcode.ca> | 2021-05-25 06:27:41 -0700 |
| commit | 0292efd363584fc4be50b1b1240fbbe990e2ebf1 (patch) | |
| tree | 9b952f814b4733f287ea9f5fb3f9bc412514a923 | |
| parent | f3cfd8afb6db1ee0a8449655703172a0c8cf5411 (diff) | |
| download | rust-0292efd363584fc4be50b1b1240fbbe990e2ebf1.tar.gz rust-0292efd363584fc4be50b1b1240fbbe990e2ebf1.zip | |
Also do goto implementation on assoc consts
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.
| -rw-r--r-- | crates/ide/src/goto_implementation.rs | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/crates/ide/src/goto_implementation.rs b/crates/ide/src/goto_implementation.rs index 5a8d3c3f98f..43356a94edf 100644 --- a/crates/ide/src/goto_implementation.rs +++ b/crates/ide/src/goto_implementation.rs @@ -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, @@ -306,4 +312,22 @@ impl Tr for S { "#, ); } + + #[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; + //^ +} +"#, + ); + } } |
