Open
Description
The new stable Rust feature to use Ok(ok) = infallible_result;
is great, though I noticed that rust-analyzer does not always work along it.
I found two ways to wrap the error and cause this issue but there may be more.
rust-analyzer version:
- extension release version
0.3.2146-standalone (d7628c0a8 2024-10-12)
- extension pre-release version
0.4.2149-standalone (a439ed8b8 2024-10-16)
rustc version: 1.82.0 (f6e511eec 2024-10-15) stable
editor or extension: VSCode
relevant settings: -
repository link (if public, optional): -
code snippet to reproduce:
This code compiles but rust-analyzer detects non-exhaustive pattern
for the latter two functions:
use std::convert::Infallible;
trait Foo {
type Bar;
}
struct Wrapper<T> {
error: T,
}
struct FooWrapper<T: Foo> {
error: T::Bar,
}
// these three work
fn works1<T: Foo<Bar = Infallible>>(result: Result<T, T::Bar>) -> T {
let Ok(ok) = result;
ok
}
fn works2<T: Foo<Bar = Infallible>>(result: Result<T, (T::Bar,)>) -> T {
let Ok(ok) = result;
ok
}
fn works3<T: Foo<Bar = Infallible>>(result: Result<T, Wrapper<T::Bar>>) -> T {
let Ok(ok) = result;
ok
}
// these two do not
fn fails1<T: Foo<Bar = Infallible>>(result: Result<T, FooWrapper<T>>) -> T {
let Ok(ok) = result;
ok
}
fn fails2<T: Foo<Bar = Infallible>>(result: Result<T, [T::Bar; 1]>) -> T {
let Ok(ok) = result;
ok
}