Skip to content

shadowed trait in a generic argument causes incorrect name resolution. #10707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jhgg opened this issue Nov 5, 2021 · 3 comments · Fixed by #11914
Closed

shadowed trait in a generic argument causes incorrect name resolution. #10707

jhgg opened this issue Nov 5, 2021 · 3 comments · Fixed by #11914
Labels
A-nameres name, path and module resolution C-bug Category: bug S-unactionable Issue requires feedback, design decisions or is blocked on other work

Comments

@jhgg
Copy link
Contributor

jhgg commented Nov 5, 2021

Consider this code:

trait A {
    fn woop(&self);
}
trait B {
    const X: usize;
    fn woop(&self);
}

impl<A> B for A
where
    A: B,
{
    const X: usize = 1;

    fn woop(&self) {
        println!("{}", A::X);
        //             ^ this is considered as `trait A` not the generic param `A` by r-a.
    }
}

fn main() {}

See:

image

This also impacts rename, which gets a tad confused:

2021-11-05_14-40-02

Rustc however does resolve this properly and the program provided compiles fine.

@lnicola
Copy link
Member

lnicola commented Nov 7, 2021

The might be two issues here:

@lnicola lnicola added A-nameres name, path and module resolution C-bug Category: bug S-unactionable Issue requires feedback, design decisions or is blocked on other work labels Nov 7, 2021
@jhgg
Copy link
Contributor Author

jhgg commented Nov 7, 2021

  • we don't support const generics much outside of parsing

This occurs if you were to do:

     fn woop(&self) {
        println!("{}", A::woot());
        //             ^ this is considered as `trait A` not the generic param `A` by r-a.
    }

As well, so probably not related to const generic 🤔 I believe the issue here is neither (but I'm no expert.) It looks to prefer to resolve A in that context to the trait A rather than the generic parameter A (from impl<A> B for A).

@flodiebold
Copy link
Member

A::X gets correctly resolved, so this seems to be a problem purely in the IDE layer name resolution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-nameres name, path and module resolution C-bug Category: bug S-unactionable Issue requires feedback, design decisions or is blocked on other work
Projects
None yet
3 participants