Skip to content

Commit 765076f

Browse files
committed
Give better help for identifier patterns failing exhaustiveness check
1 parent 3386757 commit 765076f

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/librustc_const_eval/check_match.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,14 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
260260
"refutable pattern in {}: `{}` not covered",
261261
origin, pattern_string
262262
);
263-
diag.span_label(pat.span, format!("pattern `{}` not covered", pattern_string));
263+
let label_msg = match pat.node {
264+
PatKind::Path(hir::QPath::Resolved(None, ref path))
265+
if path.segments.len() == 1 && path.segments[0].parameters.is_none() => {
266+
format!("interpreted as a {} pattern, not new variable", path.def.kind_name())
267+
}
268+
_ => format!("pattern `{}` not covered", pattern_string),
269+
};
270+
diag.span_label(pat.span, label_msg);
264271
diag.emit();
265272
});
266273
}

src/test/ui/const-pattern-irrefutable.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ error[E0005]: refutable pattern in local binding: `_` not covered
22
--> $DIR/const-pattern-irrefutable.rs:22:9
33
|
44
22 | let a = 4; //~ ERROR refutable pattern in local binding: `_` not covered
5-
| ^ pattern `_` not covered
5+
| ^ interpreted as a constant pattern, not new variable
66

77
error[E0005]: refutable pattern in local binding: `_` not covered
88
--> $DIR/const-pattern-irrefutable.rs:23:9
99
|
1010
23 | let c = 4; //~ ERROR refutable pattern in local binding: `_` not covered
11-
| ^ pattern `_` not covered
11+
| ^ interpreted as a constant pattern, not new variable
1212

1313
error[E0005]: refutable pattern in local binding: `_` not covered
1414
--> $DIR/const-pattern-irrefutable.rs:24:9
1515
|
1616
24 | let d = 4; //~ ERROR refutable pattern in local binding: `_` not covered
17-
| ^ pattern `_` not covered
17+
| ^ interpreted as a constant pattern, not new variable
1818

1919
error: aborting due to 3 previous errors
2020

0 commit comments

Comments
 (0)