fix: Fix a bug on inhabitedness checks for arrays
This commit is contained in:
parent
efeb398cbf
commit
15557506eb
2 changed files with 53 additions and 1 deletions
|
|
@ -90,7 +90,7 @@ impl<'db> TypeVisitor<DbInterner<'db>> for UninhabitedFrom<'_, 'db> {
|
|||
TyKind::Tuple(..) => ty.super_visit_with(self),
|
||||
TyKind::Array(item_ty, len) => match try_const_usize(self.infcx.interner.db, len) {
|
||||
Some(0) | None => CONTINUE_OPAQUELY_INHABITED,
|
||||
Some(1..) => item_ty.super_visit_with(self),
|
||||
Some(1..) => item_ty.visit_with(self),
|
||||
},
|
||||
_ => CONTINUE_OPAQUELY_INHABITED,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -152,6 +152,58 @@ impl<T> Deref for Foo<T> {
|
|||
fn test(x: Foo<(i32, bool)>) {
|
||||
let (_a, _b): &(i32, bool) = &x;
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uninhabited_variants() {
|
||||
check_diagnostics(
|
||||
r#"
|
||||
//- minicore: result
|
||||
enum Infallible {}
|
||||
|
||||
trait Foo {
|
||||
type Bar;
|
||||
}
|
||||
|
||||
struct Wrapper<T> {
|
||||
error: T,
|
||||
}
|
||||
|
||||
struct FooWrapper<T: Foo> {
|
||||
error: T::Bar,
|
||||
}
|
||||
|
||||
fn foo<T: Foo<Bar = Infallible>>(result: Result<T, T::Bar>) -> T {
|
||||
let Ok(ok) = result;
|
||||
ok
|
||||
}
|
||||
|
||||
fn bar<T: Foo<Bar = Infallible>>(result: Result<T, (T::Bar,)>) -> T {
|
||||
let Ok(ok) = result;
|
||||
ok
|
||||
}
|
||||
|
||||
fn baz<T: Foo<Bar = Infallible>>(result: Result<T, Wrapper<T::Bar>>) -> T {
|
||||
let Ok(ok) = result;
|
||||
ok
|
||||
}
|
||||
|
||||
fn qux<T: Foo<Bar = Infallible>>(result: Result<T, FooWrapper<T>>) -> T {
|
||||
let Ok(ok) = result;
|
||||
ok
|
||||
}
|
||||
|
||||
fn quux<T: Foo<Bar = Infallible>>(result: Result<T, [T::Bar; 1]>) -> T {
|
||||
let Ok(ok) = result;
|
||||
ok
|
||||
}
|
||||
|
||||
fn corge<T: Foo<Bar = Infallible>>(result: Result<T, (i32, T::Bar)>) -> T {
|
||||
let Ok(ok) = result;
|
||||
ok
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue