]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/middle/check_match.rs
Auto merge of #30341 - pnkfelix:call-site-scope, r=nikomatsakis
[rust.git] / src / librustc / middle / check_match.rs
index f46e55e24414081edb708232852dbe98d5502ff9..ba4bdccb20b805583d50c4eaa19adc45fac2067c 100644 (file)
@@ -33,7 +33,7 @@
 
 use rustc_front::hir;
 use rustc_front::hir::Pat;
-use rustc_front::visit::{self, Visitor, FnKind};
+use rustc_front::intravisit::{self, Visitor, FnKind};
 use rustc_front::util as front_util;
 use rustc_back::slice;
 
@@ -155,15 +155,15 @@ fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v hir::FnDecl,
 }
 
 pub fn check_crate(tcx: &ty::ctxt) {
-    visit::walk_crate(&mut MatchCheckCtxt {
+    tcx.map.krate().visit_all_items(&mut MatchCheckCtxt {
         tcx: tcx,
         param_env: tcx.empty_parameter_environment(),
-    }, tcx.map.krate());
+    });
     tcx.sess.abort_if_errors();
 }
 
 fn check_expr(cx: &mut MatchCheckCtxt, ex: &hir::Expr) {
-    visit::walk_expr(cx, ex);
+    intravisit::walk_expr(cx, ex);
     match ex.node {
         hir::ExprMatch(ref scrut, ref arms, source) => {
             for arm in arms {
@@ -247,17 +247,18 @@ fn check_for_bindings_named_the_same_as_variants(cx: &MatchCheckCtxt, pat: &Pat)
                     let def = cx.tcx.def_map.borrow().get(&p.id).map(|d| d.full_def());
                     if let Some(DefLocal(..)) = def {
                         if edef.variants.iter().any(|variant|
-                            variant.name == ident.node.name
+                            variant.name == ident.node.unhygienic_name
                                 && variant.kind() == VariantKind::Unit
                         ) {
+                            let ty_path = cx.tcx.item_path_str(edef.did);
                             span_warn!(cx.tcx.sess, p.span, E0170,
                                 "pattern binding `{}` is named the same as one \
                                  of the variants of the type `{}`",
-                                ident.node, pat_ty);
+                                ident.node, ty_path);
                             fileline_help!(cx.tcx.sess, p.span,
                                 "if you meant to match on a variant, \
                                  consider making the path in the pattern qualified: `{}::{}`",
-                                pat_ty, ident.node);
+                                ty_path, ident.node);
                         }
                     }
                 }
@@ -409,7 +410,8 @@ fn const_val_to_expr(value: &ConstVal) -> P<hir::Expr> {
     P(hir::Expr {
         id: 0,
         node: hir::ExprLit(P(Spanned { node: node, span: DUMMY_SP })),
-        span: DUMMY_SP
+        span: DUMMY_SP,
+        attrs: None,
     })
 }
 
@@ -485,11 +487,7 @@ fn record_renamings(const_expr: &hir::Expr,
                 renaming_map: renaming_map,
             };
 
-            let mut id_visitor = front_util::IdVisitor {
-                operation: &mut renaming_recorder,
-                pass_through_items: true,
-                visited_outermost: false,
-            };
+            let mut id_visitor = front_util::IdVisitor::new(&mut renaming_recorder);
 
             id_visitor.visit_expr(const_expr);
         }
@@ -983,14 +981,14 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
         }
     };
     head.map(|mut head| {
-        head.push_all(&r[..col]);
-        head.push_all(&r[col + 1..]);
+        head.extend_from_slice(&r[..col]);
+        head.extend_from_slice(&r[col + 1..]);
         head
     })
 }
 
 fn check_local(cx: &mut MatchCheckCtxt, loc: &hir::Local) {
-    visit::walk_local(cx, loc);
+    intravisit::walk_local(cx, loc);
 
     let pat = StaticInliner::new(cx.tcx, None).fold_pat(loc.pat.clone());
     check_irrefutable(cx, &pat, false);
@@ -1011,7 +1009,7 @@ fn check_fn(cx: &mut MatchCheckCtxt,
         _ => cx.param_env = ParameterEnvironment::for_item(cx.tcx, fn_id),
     }
 
-    visit::walk_fn(cx, kind, decl, body, sp);
+    intravisit::walk_fn(cx, kind, decl, body, sp);
 
     for input in &decl.inputs {
         check_irrefutable(cx, &input.pat, true);
@@ -1191,10 +1189,10 @@ fn visit_pat(&mut self, pat: &Pat) {
             hir::PatIdent(_, _, Some(_)) => {
                 let bindings_were_allowed = self.bindings_allowed;
                 self.bindings_allowed = false;
-                visit::walk_pat(self, pat);
+                intravisit::walk_pat(self, pat);
                 self.bindings_allowed = bindings_were_allowed;
             }
-            _ => visit::walk_pat(self, pat),
+            _ => intravisit::walk_pat(self, pat),
         }
     }
 }