Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compiler/rustc_mir_build/src/thir/pattern/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,11 @@ fn non_exhaustive_match<'p, 'tcx>(
));
}
}
if let ty::Ref(_, sub_ty, _) = scrut_ty.kind() {
if cx.tcx.is_ty_uninhabited_from(cx.module, sub_ty, cx.param_env) {
err.note("references are always considered inhabited");
}
}
err.emit();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LL | match uninhab_ref() {
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
= note: the matched value is of type `&!`
= note: references are always considered inhabited

error[E0004]: non-exhaustive patterns: type `Foo` is non-empty
--> $DIR/always-inhabited-union-ref.rs:27:11
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
enum A {}
//~^ NOTE `A` defined here

fn f(a: &A) {
match a {}
//~^ ERROR non-exhaustive patterns: type `&A` is non-empty
//~| NOTE the matched value is of type `&A`
//~| NOTE references are always considered inhabited
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error[E0004]: non-exhaustive patterns: type `&A` is non-empty
--> $DIR/issue-78123-non-exhaustive-reference.rs:5:11
|
LL | enum A {}
| --------- `A` defined here
...
LL | match a {}
| ^
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
= note: the matched value is of type `&A`
= note: references are always considered inhabited

error: aborting due to previous error

For more information about this error, try `rustc --explain E0004`.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ LL | let _ = match x {};
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
= note: the matched value is of type `&Void`
= note: references are always considered inhabited

error[E0004]: non-exhaustive patterns: type `(Void,)` is non-empty
--> $DIR/uninhabited-matches-feature-gated.rs:18:19
Expand Down