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

Implementing trait as returning self causes return type to become {unknown} #16798

Closed
tetrogem opened this issue Mar 10, 2024 · 1 comment
Closed
Labels
C-bug Category: bug

Comments

@tetrogem
Copy link

tetrogem commented Mar 10, 2024

rust-analyzer version: 0.4.1875-standalone (574e23e 2024-03-09)

rustc version: 1.77.0-nightly (d78329b92 2024-01-13)

relevant settings: n/a

repository link (if public, optional): n/a

code snippet to reproduce:

pub trait GetRef<T> {
    fn get(&self) -> &T;
}

impl<T> GetRef<T> for T {
    fn get(&self) -> &T {
        self
    }
}

fn print_u8(inner: impl GetRef<u8>) {
    let x = inner.get(); // ra says --> x: &{unknown}
    println!("Got: {}", x);
}

fn main() {
    print_u8(100);
}

This program, though RA says a type is unknown, compiles successfully and outputs the expected values:

Got: 100

Implementing get in a way that does not return self appears to fix the problem.

Edit: found an even more minimal reproducible example which changes what the bug appears to be, edited the title & code sample accordingly

@tetrogem tetrogem added the C-bug Category: bug label Mar 10, 2024
@tetrogem tetrogem changed the title Multiple trait implementations causing trait function return type to be {unknown} Implementing trait as returning self causes return type to become {unknown} Mar 10, 2024
@flodiebold
Copy link
Member

Duplicate of #5514

@flodiebold flodiebold marked this as a duplicate of #5514 Mar 10, 2024
@flodiebold flodiebold closed this as not planned Won't fix, can't repro, duplicate, stale Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants