rust-analyzer
rust-analyzer copied to clipboard
RA not resolving type that depends on the value of a const expr.
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"
}