mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Rollup merge of #39526 - canndrew:uninhabited-while-let-fix, r=arielb1
Uninhabited while-let pattern fix This fix makes it so while-let with an unsatisfiable pattern raises a correct warning rather than an incorrect error.
This commit is contained in:
commit
4e67bf92e3
@ -273,7 +273,7 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
|
||||
let mut seen = Matrix::empty();
|
||||
let mut catchall = None;
|
||||
let mut printed_if_let_err = false;
|
||||
for &(ref pats, guard) in arms {
|
||||
for (arm_index, &(ref pats, guard)) in arms.iter().enumerate() {
|
||||
for &(pat, hir_pat) in pats {
|
||||
let v = vec![pat];
|
||||
|
||||
@ -302,11 +302,28 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
|
||||
let &(ref first_arm_pats, _) = &arms[0];
|
||||
let first_pat = &first_arm_pats[0];
|
||||
let span = first_pat.0.span;
|
||||
|
||||
// check which arm we're on.
|
||||
match arm_index {
|
||||
// The arm with the user-specified pattern.
|
||||
0 => {
|
||||
let mut diagnostic = Diagnostic::new(Level::Warning,
|
||||
"unreachable pattern");
|
||||
diagnostic.set_span(pat.span);
|
||||
cx.tcx.sess.add_lint_diagnostic(
|
||||
lint::builtin::UNREACHABLE_PATTERNS,
|
||||
hir_pat.id, diagnostic);
|
||||
},
|
||||
// The arm with the wildcard pattern.
|
||||
1 => {
|
||||
struct_span_err!(cx.tcx.sess, span, E0165,
|
||||
"irrefutable while-let pattern")
|
||||
.span_label(span, &format!("irrefutable pattern"))
|
||||
.emit();
|
||||
},
|
||||
_ => bug!(),
|
||||
}
|
||||
},
|
||||
|
||||
hir::MatchSource::ForLoopDesugar |
|
||||
hir::MatchSource::Normal => {
|
||||
|
@ -24,6 +24,10 @@ struct NotSoSecretlyEmpty {
|
||||
_priv: !,
|
||||
}
|
||||
|
||||
fn foo() -> Option<NotSoSecretlyEmpty> {
|
||||
None
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x: &[!] = &[];
|
||||
|
||||
@ -45,5 +49,9 @@ fn main() {
|
||||
Err(Err(_y)) => (),
|
||||
Err(Ok(_y)) => (), //~ ERROR unreachable pattern
|
||||
}
|
||||
|
||||
while let Some(_y) = foo() {
|
||||
//~^ ERROR unreachable pattern
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user