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

RA not resolving type that depends on the value of a const expr. #17521

Open
Olle-Lukowski opened this issue Jun 30, 2024 · 0 comments
Open

RA not resolving type that depends on the value of a const expr. #17521

Olle-Lukowski opened this issue Jun 30, 2024 · 0 comments
Labels
C-bug Category: bug

Comments

@Olle-Lukowski
Copy link

rust-analyzer version: rust-analyzer 1.79.0 (129f3b99 2024-06-10)

rustc version: rustc 1.79.0 (129f3b996 2024-06-10)

editor or extension: NeoVim with LSP, RustRover, and VSCode all have the same issue.

More Info: RA seems to 'know' what the type is, but just doesn't display it. Because when I explicitly set the type of the variable to the wrong option (see example), it complains...

code snippet to reproduce:

pub trait Conditional<const CONDITION: bool> {
    type Type;
}

impl<T, F> Conditional<true> for (T, F) {
    type Type = T;
}

impl<T, F> Conditional<false> for (T, F) {
    type Type = F;
}

pub type If<const C: bool, T, F> = <(T, F) as Conditional<C>>::Type;

struct Foo;

#[derive(Default)]
struct Bar;

#[derive(Default)]
struct Baz;

trait Trait {
    type Out;
    fn foo() -> Self::Out;
}

impl Trait for Foo {
    type Out = If<
        {1 < 0},
        Bar,
        Baz
    >;
    fn foo() -> Self::Out {
        Default::default()
    }
}

fn main() {
    let _foo = Foo::foo(); // Unknown, according to RA, but rustc knows whats up.
    let _foo: Bar = Foo::foo(); // Both rustc and RA error here: "mismatched types"
}
@Olle-Lukowski Olle-Lukowski added the C-bug Category: bug label Jun 30, 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

1 participant