Skip to content

Type inference breaks for types with generic lifetimes and generic type parameters with default values #17515

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
Veetaha opened this issue Jun 30, 2024 · 2 comments
Labels
C-bug Category: bug

Comments

@Veetaha
Copy link
Contributor

Veetaha commented Jun 30, 2024

rust-analyzer version: 0.3.2011-standalone
rustc version: rustc 1.78.0 (9b00956e5 2024-04-29)
extension: VSCode extension v0.3.2011

Reproduction

Paste the following code into main.rs

struct Blackjack<'a, T = bool> {
    state: &'a T,
}

impl<'a, T> Blackjack<'a, T> {
    fn method(self) {
        let _ = self.state;
    }
}

fn make_blackjack<'a>() -> Blackjack<'a> {
    Blackjack { state: &true }
}

fn main() {
    let blackjack = make_blackjack();
    blackjack.method();
}

Expected

I expected rust-analyzer to resolve the .method() invocation correctly and highlight it as yellow according to my semantic tokens highlighting config.

Actual

You may see that method() method symbol is unresolved. Here is how it looks in my VSCode. I configured unresolved symbols semantic token type to be displayed in pale-red. You may see that the lifetime parameter of the struct is inferred to be {unknown}. I suppose this is the reason why .method() is unresolved.

Well-formed variation

If you remove the T = bool default value of the generic parameter on the struct definition and pass bool explicitly then all is fine.

@Veetaha Veetaha added the C-bug Category: bug label Jun 30, 2024
@flodiebold
Copy link
Member

Hm, this works in older RA versions, so I guess it might have been broken with the lifetime inference work. @dfireBird

@Veykril
Copy link
Member

Veykril commented Jun 30, 2024

This is #17075, I'm already looking into it

@Veykril Veykril closed this as completed Jun 30, 2024
bors added a commit that referenced this issue Jul 2, 2024
fix: Fix lifetime parameters moving parameter defaults

Fixes #17075, #17515

We were incorrectly filling the default params due to our odd order of lifetime parameters vs type/const params. So this needs some special handling so that we don't shift the defaults around.
bors added a commit that referenced this issue Jul 2, 2024
fix: Fix lifetime parameters moving parameter defaults

Fixes #17075, #17515

We were incorrectly filling the default params due to our odd order of lifetime parameters vs type/const params. So this needs some special handling so that we don't shift the defaults around.
bors added a commit that referenced this issue Jul 2, 2024
fix: Fix lifetime parameters moving parameter defaults

Fixes #17075, #17515

We were incorrectly filling the default params due to our odd order of lifetime parameters vs type/const params. So this needs some special handling so that we don't shift the defaults around.
lnicola pushed a commit to lnicola/rust that referenced this issue Jul 11, 2024
fix: Fix lifetime parameters moving parameter defaults

Fixes rust-lang/rust-analyzer#17075, rust-lang/rust-analyzer#17515

We were incorrectly filling the default params due to our odd order of lifetime parameters vs type/const params. So this needs some special handling so that we don't shift the defaults around.
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

3 participants