rollup merge of #20039: barosl/if-let-friendly-error

Fixes #19991.
This commit is contained in:
Alex Crichton 2014-12-21 00:04:13 -08:00
commit eb47e1e446
10 changed files with 64 additions and 24 deletions

View file

@ -1157,9 +1157,9 @@ impl LintPass for UnusedParens {
ast::ExprIf(ref cond, _, _) => (cond, "`if` condition", true),
ast::ExprWhile(ref cond, _, _) => (cond, "`while` condition", true),
ast::ExprMatch(ref head, _, source) => match source {
ast::MatchNormal => (head, "`match` head expression", true),
ast::MatchIfLetDesugar => (head, "`if let` head expression", true),
ast::MatchWhileLetDesugar => (head, "`while let` head expression", true),
ast::MatchSource::Normal => (head, "`match` head expression", true),
ast::MatchSource::IfLetDesugar { .. } => (head, "`if let` head expression", true),
ast::MatchSource::WhileLetDesugar => (head, "`while let` head expression", true),
},
ast::ExprRet(Some(ref value)) => (value, "`return` value", false),
ast::ExprAssign(_, ref value) => (value, "assigned value", false),

View file

@ -307,7 +307,7 @@ fn check_arms(cx: &MatchCheckCtxt,
match is_useful(cx, &seen, v.as_slice(), LeaveOutWitness) {
NotUseful => {
match source {
ast::MatchIfLetDesugar => {
ast::MatchSource::IfLetDesugar { .. } => {
if printed_if_let_err {
// we already printed an irrefutable if-let pattern error.
// We don't want two, that's just confusing.
@ -321,7 +321,7 @@ fn check_arms(cx: &MatchCheckCtxt,
}
},
ast::MatchWhileLetDesugar => {
ast::MatchSource::WhileLetDesugar => {
// find the first arm pattern so we can use its span
let &(ref first_arm_pats, _) = &arms[0];
let first_pat = &first_arm_pats[0];
@ -329,7 +329,7 @@ fn check_arms(cx: &MatchCheckCtxt,
span_err!(cx.tcx.sess, span, E0165, "irrefutable while-let pattern");
},
ast::MatchNormal => {
ast::MatchSource::Normal => {
span_err!(cx.tcx.sess, pat.span, E0001, "unreachable pattern")
},
}

View file

@ -93,8 +93,9 @@ pub fn explain_region_and_span(cx: &ctxt, region: ty::Region)
ast::ExprMethodCall(..) => {
explain_span(cx, "method call", expr.span)
},
ast::ExprMatch(_, _, ast::MatchIfLetDesugar) => explain_span(cx, "if let", expr.span),
ast::ExprMatch(_, _, ast::MatchWhileLetDesugar) => {
ast::ExprMatch(_, _, ast::MatchSource::IfLetDesugar { .. }) =>
explain_span(cx, "if let", expr.span),
ast::ExprMatch(_, _, ast::MatchSource::WhileLetDesugar) => {
explain_span(cx, "while let", expr.span)
},
ast::ExprMatch(..) => explain_span(cx, "match", expr.span),