Skip to content
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

rust-analyzer seems to be getting confused between trait methods and inherent methods #17233

Open
TDplai opened this issue May 14, 2024 · 2 comments
Labels
A-chalk chalk related issue A-ty type system / type inference / traits / method resolution C-bug Category: bug

Comments

@TDplai
Copy link

TDplai commented May 14, 2024

rust-analyzer version: rust-analyzer 1.78.0 (9b00956 2024-04-29)

Can also reproduce with rust-analyzer 1.80.0-nightly (ab14f94 2024-05-13)

rustc version: rustc 1.78.0 (9b00956e5 2024-04-29)

editor or extension: Neovim 0.9.5

relevant settings:

  • CARGO_HOME is set to $HOME/.local/share/cargo
  • RUSTUP_HOME is set to $HOME/.local/share/rustup

code snippet to reproduce:

pub trait A {
    // Removing this associated type makes everything work
    type X: B;
}
// Making `B` not a subtrait of `A` makes everything work
pub trait B: A {
    // Changing this to take `&self` makes everything work
    fn confused_name(self, _: i32);
}

pub struct Foo;
impl Foo {
    // Changing this to take `self` by value makes everything work
    pub fn confused_name(&self) {}
}

pub fn repro<T: A>() {
    // rust-analyzer reports "expected 1 argument, found 0"
    Foo.confused_name();
}

Note that the above code does compile.

@TDplai TDplai added the C-bug Category: bug label May 14, 2024
@Veykril Veykril added the A-ty type system / type inference / traits / method resolution label May 15, 2024
@dfireBird
Copy link
Contributor

dfireBird commented May 18, 2024

This seems like a problem with chalk, I traced it to this trait_solve_query call:

if db.trait_solve(krate, block, goal.cast(Interner)).is_none() {

Which here should return None but returns a Some and it correctly returns None if any of the changes mentioned in the example code. I'm not sure what more info should I add here, if there is anything needed please ask.

EDIT: The goal that's sent to chalk: (UCanonical { canonical: Canonical { value: InEnvironment { environment: Env([for<> FromEnv(!0_1: TraitId(0))]), goal: Implemented(AdtId(StructId(StructId(0)))<[]>: TraitId(1)) }, binders: [] }, universes: 1 })

@flodiebold
Copy link
Member

flodiebold commented May 19, 2024

Probably rust-lang/chalk#750 or rust-lang/chalk#727.

@flodiebold flodiebold added the A-chalk chalk related issue label May 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-chalk chalk related issue A-ty type system / type inference / traits / method resolution C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

4 participants