Skip to content

Commit b37696d

Browse files
Merge pull request rust-lang#20905 from ShoyuVanilla/array-inhabit
fix: Fix a bug on inhabitedness checks for arrays
2 parents f01c69f + 1555750 commit b37696d

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

src/tools/rust-analyzer/crates/hir-ty/src/inhabitedness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl<'db> TypeVisitor<DbInterner<'db>> for UninhabitedFrom<'_, 'db> {
9090
TyKind::Tuple(..) => ty.super_visit_with(self),
9191
TyKind::Array(item_ty, len) => match try_const_usize(self.infcx.interner.db, len) {
9292
Some(0) | None => CONTINUE_OPAQUELY_INHABITED,
93-
Some(1..) => item_ty.super_visit_with(self),
93+
Some(1..) => item_ty.visit_with(self),
9494
},
9595
_ => CONTINUE_OPAQUELY_INHABITED,
9696
};

src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/non_exhaustive_let.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,58 @@ impl<T> Deref for Foo<T> {
152152
fn test(x: Foo<(i32, bool)>) {
153153
let (_a, _b): &(i32, bool) = &x;
154154
}
155+
"#,
156+
);
157+
}
158+
159+
#[test]
160+
fn uninhabited_variants() {
161+
check_diagnostics(
162+
r#"
163+
//- minicore: result
164+
enum Infallible {}
165+
166+
trait Foo {
167+
type Bar;
168+
}
169+
170+
struct Wrapper<T> {
171+
error: T,
172+
}
173+
174+
struct FooWrapper<T: Foo> {
175+
error: T::Bar,
176+
}
177+
178+
fn foo<T: Foo<Bar = Infallible>>(result: Result<T, T::Bar>) -> T {
179+
let Ok(ok) = result;
180+
ok
181+
}
182+
183+
fn bar<T: Foo<Bar = Infallible>>(result: Result<T, (T::Bar,)>) -> T {
184+
let Ok(ok) = result;
185+
ok
186+
}
187+
188+
fn baz<T: Foo<Bar = Infallible>>(result: Result<T, Wrapper<T::Bar>>) -> T {
189+
let Ok(ok) = result;
190+
ok
191+
}
192+
193+
fn qux<T: Foo<Bar = Infallible>>(result: Result<T, FooWrapper<T>>) -> T {
194+
let Ok(ok) = result;
195+
ok
196+
}
197+
198+
fn quux<T: Foo<Bar = Infallible>>(result: Result<T, [T::Bar; 1]>) -> T {
199+
let Ok(ok) = result;
200+
ok
201+
}
202+
203+
fn corge<T: Foo<Bar = Infallible>>(result: Result<T, (i32, T::Bar)>) -> T {
204+
let Ok(ok) = result;
205+
ok
206+
}
155207
"#,
156208
);
157209
}

0 commit comments

Comments
 (0)