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

No completions for impl blocks on dyn traits with lifetimes #7683

Closed
MaikKlein opened this issue Feb 15, 2021 · 4 comments · Fixed by #7732
Closed

No completions for impl blocks on dyn traits with lifetimes #7683

MaikKlein opened this issue Feb 15, 2021 · 4 comments · Fixed by #7732
Labels
A-completion autocompletion A-ty type system / type inference / traits / method resolution S-actionable Someone could pick this issue up and work on it right now

Comments

@MaikKlein
Copy link

Follow up with #6777 because I noticed that it doesn't work in our internal project. After a quick investigation I noticed that lifetimes on impl blocks cause problems.

For example this code doesn't have any completions with the latest release

trait Foo {
    fn foo_dyn(&self, s: &str);
}

impl dyn Foo + '_ {
    pub fn foo<T: AsRef<str>>(&self, s: T) {
        self.foo_dyn(s.as_ref())
    }
}

impl Foo for u32 {
    fn foo_dyn(&self, s: &str) {
        println!("{} {}", self, s);
    }
}

fn completion(f: &dyn Foo) {
    // No completion
    f.foo("Hello");
}

fn main() {}

No completions if the impl block has a lifetime like this

impl dyn Foo + '_ {
impl<'a> dyn Foo + 'a {
impl dyn Foo + 'static {
@Veykril Veykril added A-completion autocompletion A-ty type system / type inference / traits / method resolution S-actionable Someone could pick this issue up and work on it right now labels Feb 15, 2021
@Veykril
Copy link
Member

Veykril commented Feb 20, 2021

Okay I think I found the problem, in https://github.com/rust-analyzer/rust-analyzer/blob/ba3a5c518a4e20ddacad05d7a8a67704ca2b2a9a/crates/hir_ty/src/lower.rs#L708-L709 the TraitRef::from_type_bound call returns None when we check the lifetime bound as we haven't implemented lifetime generic predicates. Due to that the None gets mapped to a GenericPredicate::Error which then bubbles up to the method resolution stuff which then causes the impl to not match roughly speaking.

@MaikKlein
Copy link
Author

Thanks a lot for looking into these issues <3

@Veykril
Copy link
Member

Veykril commented Feb 21, 2021

I hope it will work for you this time 😄

@MaikKlein
Copy link
Author

I hope it will work for you this time

I can confirm that it works on nightly :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-completion autocompletion A-ty type system / type inference / traits / method resolution S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants