Skip to content

Commit a42e21d

Browse files
committed
Auto merge of #27297 - mitaa:cleanup_E0005, r=alexcrichton
This does two things: * removes ast::LocalSource, where only one variant was used because for-loop expansion has changed. One reason that this slipped into here is because the code in `check_local` which checks for `LocalSource::LocalFor` would report the same error as in `check_exhaustive` while using the wrong error code (E0005 instead of E0297). * silences the warning about already used diagnostic code E0005 (fixes #27279) passes `make check` locally.
2 parents a5c12f4 + 19512be commit a42e21d

File tree

6 files changed

+22
-36
lines changed

6 files changed

+22
-36
lines changed

src/librustc/middle/check_match.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,18 +1016,8 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
10161016
fn check_local(cx: &mut MatchCheckCtxt, loc: &ast::Local) {
10171017
visit::walk_local(cx, loc);
10181018

1019-
let name = match loc.source {
1020-
ast::LocalLet => "local",
1021-
ast::LocalFor => "`for` loop"
1022-
};
1023-
1024-
let mut static_inliner = StaticInliner::new(cx.tcx, None);
1025-
is_refutable(cx, &*static_inliner.fold_pat(loc.pat.clone()), |pat| {
1026-
span_err!(cx.tcx.sess, loc.pat.span, E0005,
1027-
"refutable pattern in {} binding: `{}` not covered",
1028-
name, pat_to_string(pat)
1029-
);
1030-
});
1019+
let pat = StaticInliner::new(cx.tcx, None).fold_pat(loc.pat.clone());
1020+
check_irrefutable(cx, &pat, false);
10311021

10321022
// Check legality of move bindings and `@` patterns.
10331023
check_legality_of_move_bindings(cx, false, slice::ref_slice(&loc.pat));
@@ -1048,17 +1038,28 @@ fn check_fn(cx: &mut MatchCheckCtxt,
10481038
visit::walk_fn(cx, kind, decl, body, sp);
10491039

10501040
for input in &decl.inputs {
1051-
is_refutable(cx, &*input.pat, |pat| {
1052-
span_err!(cx.tcx.sess, input.pat.span, E0005,
1053-
"refutable pattern in function argument: `{}` not covered",
1054-
pat_to_string(pat)
1055-
);
1056-
});
1041+
check_irrefutable(cx, &input.pat, true);
10571042
check_legality_of_move_bindings(cx, false, slice::ref_slice(&input.pat));
10581043
check_legality_of_bindings_in_at_patterns(cx, &*input.pat);
10591044
}
10601045
}
10611046

1047+
fn check_irrefutable(cx: &MatchCheckCtxt, pat: &Pat, is_fn_arg: bool) {
1048+
let origin = if is_fn_arg {
1049+
"function argument"
1050+
} else {
1051+
"local binding"
1052+
};
1053+
1054+
is_refutable(cx, pat, |uncovered_pat| {
1055+
span_err!(cx.tcx.sess, pat.span, E0005,
1056+
"refutable pattern in {}: `{}` not covered",
1057+
origin,
1058+
pat_to_string(uncovered_pat),
1059+
);
1060+
});
1061+
}
1062+
10621063
fn is_refutable<A, F>(cx: &MatchCheckCtxt, pat: &Pat, refutable: F) -> Option<A> where
10631064
F: FnOnce(&Pat) -> A,
10641065
{

src/libsyntax/ast.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ pub use self::Item_::*;
2929
pub use self::KleeneOp::*;
3030
pub use self::Lit_::*;
3131
pub use self::LitIntType::*;
32-
pub use self::LocalSource::*;
3332
pub use self::Mac_::*;
3433
pub use self::MacStmtStyle::*;
3534
pub use self::MetaItem_::*;
@@ -756,14 +755,6 @@ pub enum MacStmtStyle {
756755
MacStmtWithoutBraces,
757756
}
758757

759-
/// Where a local declaration came from: either a true `let ... =
760-
/// ...;`, or one desugared from the pattern of a for loop.
761-
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
762-
pub enum LocalSource {
763-
LocalLet,
764-
LocalFor,
765-
}
766-
767758
// FIXME (pending discussion of #1697, #2178...): local should really be
768759
// a refinement on pat.
769760
/// Local represents a `let` statement, e.g., `let <pat>:<ty> = <expr>;`
@@ -775,7 +766,6 @@ pub struct Local {
775766
pub init: Option<P<Expr>>,
776767
pub id: NodeId,
777768
pub span: Span,
778-
pub source: LocalSource,
779769
}
780770

781771
pub type Decl = Spanned<Decl_>;

src/libsyntax/ext/build.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,6 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
538538
init: Some(ex),
539539
id: ast::DUMMY_NODE_ID,
540540
span: sp,
541-
source: ast::LocalLet,
542541
});
543542
let decl = respan(sp, ast::DeclLocal(local));
544543
P(respan(sp, ast::StmtDecl(P(decl), ast::DUMMY_NODE_ID)))
@@ -562,7 +561,6 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
562561
init: Some(ex),
563562
id: ast::DUMMY_NODE_ID,
564563
span: sp,
565-
source: ast::LocalLet,
566564
});
567565
let decl = respan(sp, ast::DeclLocal(local));
568566
P(respan(sp, ast::StmtDecl(P(decl), ast::DUMMY_NODE_ID)))

src/libsyntax/ext/expand.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ fn expand_non_macro_stmt(Spanned {node, span: stmt_span}: Stmt, fld: &mut MacroE
911911
StmtDecl(decl, node_id) => decl.and_then(|Spanned {node: decl, span}| match decl {
912912
DeclLocal(local) => {
913913
// take it apart:
914-
let rewritten_local = local.map(|Local {id, pat, ty, init, source, span}| {
914+
let rewritten_local = local.map(|Local {id, pat, ty, init, span}| {
915915
// expand the ty since TyFixedLengthVec contains an Expr
916916
// and thus may have a macro use
917917
let expanded_ty = ty.map(|t| fld.fold_ty(t));
@@ -941,7 +941,6 @@ fn expand_non_macro_stmt(Spanned {node, span: stmt_span}: Stmt, fld: &mut MacroE
941941
pat: rewritten_pat,
942942
// also, don't forget to expand the init:
943943
init: init.map(|e| fld.fold_expr(e)),
944-
source: source,
945944
span: span
946945
}
947946
});

src/libsyntax/fold.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,12 +515,11 @@ pub fn noop_fold_parenthesized_parameter_data<T: Folder>(data: ParenthesizedPara
515515
}
516516

517517
pub fn noop_fold_local<T: Folder>(l: P<Local>, fld: &mut T) -> P<Local> {
518-
l.map(|Local {id, pat, ty, init, source, span}| Local {
518+
l.map(|Local {id, pat, ty, init, span}| Local {
519519
id: fld.new_id(id),
520520
ty: ty.map(|t| fld.fold_ty(t)),
521521
pat: fld.fold_pat(pat),
522522
init: init.map(|e| fld.fold_expr(e)),
523-
source: source,
524523
span: fld.new_span(span)
525524
})
526525
}

src/libsyntax/parse/parser.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use ast::{ItemMac, ItemMod, ItemStruct, ItemTrait, ItemTy, ItemDefaultImpl};
3535
use ast::{ItemExternCrate, ItemUse};
3636
use ast::{LifetimeDef, Lit, Lit_};
3737
use ast::{LitBool, LitChar, LitByte, LitBinary};
38-
use ast::{LitStr, LitInt, Local, LocalLet};
38+
use ast::{LitStr, LitInt, Local};
3939
use ast::{MacStmtWithBraces, MacStmtWithSemicolon, MacStmtWithoutBraces};
4040
use ast::{MutImmutable, MutMutable, Mac_, MacInvocTT, MatchSource};
4141
use ast::{MutTy, BiMul, Mutability};
@@ -3432,7 +3432,6 @@ impl<'a> Parser<'a> {
34323432
init: init,
34333433
id: ast::DUMMY_NODE_ID,
34343434
span: mk_sp(lo, self.last_span.hi),
3435-
source: LocalLet,
34363435
}))
34373436
}
34383437

0 commit comments

Comments
 (0)