Skip to content

Commit 35db5e9

Browse files
bors[bot]lf-
andauthored
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 <[email protected]>
2 parents 33fdd51 + 0292efd commit 35db5e9

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

crates/ide/src/goto_implementation.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@ pub(crate) fn goto_implementation(
5353
let assoc = f.as_assoc_item(sema.db)?;
5454
let name = assoc.name(sema.db)?;
5555
let trait_ = assoc.containing_trait(sema.db)?;
56-
impls_for_trait_fn(&sema, trait_, name)
56+
impls_for_trait_item(&sema, trait_, name)
57+
}
58+
hir::ModuleDef::Const(c) => {
59+
let assoc = c.as_assoc_item(sema.db)?;
60+
let name = assoc.name(sema.db)?;
61+
let trait_ = assoc.containing_trait(sema.db)?;
62+
impls_for_trait_item(&sema, trait_, name)
5763
}
5864
_ => return None,
5965
};
@@ -71,7 +77,7 @@ fn impls_for_trait(sema: &Semantics<RootDatabase>, trait_: hir::Trait) -> Vec<Na
7177
.collect()
7278
}
7379

74-
fn impls_for_trait_fn(
80+
fn impls_for_trait_item(
7581
sema: &Semantics<RootDatabase>,
7682
trait_: hir::Trait,
7783
fun_name: hir::Name,
@@ -303,6 +309,24 @@ impl Tr for S {
303309
println!("Hello, world!");
304310
}
305311
}
312+
"#,
313+
);
314+
}
315+
316+
#[test]
317+
fn goto_implementation_trait_assoc_const() {
318+
check(
319+
r#"
320+
trait Tr {
321+
const C$0: usize;
322+
}
323+
324+
struct S;
325+
326+
impl Tr for S {
327+
const C: usize = 4;
328+
//^
329+
}
306330
"#,
307331
);
308332
}

0 commit comments

Comments
 (0)