Stream: t-compiler/rust-analyzer

Topic: Impl to ModuleDef or similar?

Kirill Bulatov (Feb 23 2021 at 20:25, on Zulip):

I'm working on and considering the following case:

mod foo {
    pub struct Item;
    impl Item {
        pub const TEST_ASSOC: usize = 3;

fn main() {

I look up items for TEST_A and get the assoc item as a ModuleDef.
If I try to get the ModPath for this def, I get None, which is expected.

There's a method on that assoc item, returning AssocItemContainer that's either a Trait or an Impl.
Trait is trivial, but how can I get from that Impl to a struct that it belongs to?

Jonas Schievink [he/him] (Feb 23 2021 at 20:27, on Zulip):

Does .target_ty().as_adt() help here?

Kirill Bulatov (Feb 23 2021 at 20:28, on Zulip):

Oh, I was really close, had missed that method somehow :smile:
Thank you, that helped.

Last update: Jul 26 2021 at 13:45UTC