From 9c05fb29d22a7275b7b7d52b2d5d577c0b505ad1 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 11 Jun 2016 18:47:47 +0300 Subject: [PATCH] Merge PatKind::QPath into PatKind::Path in HIR --- src/librustc/cfg/construct.rs | 1 - src/librustc/hir/fold.rs | 11 +++++------ src/librustc/hir/intravisit.rs | 9 ++++----- src/librustc/hir/lowering.rs | 19 ++++++++----------- src/librustc/hir/mod.rs | 13 +++---------- src/librustc/hir/pat_util.rs | 4 ++-- src/librustc/hir/print.rs | 4 ++-- src/librustc/middle/mem_categorization.rs | 2 +- src/librustc_const_eval/check_match.rs | 8 ++++---- src/librustc_const_eval/eval.rs | 2 +- src/librustc_lint/bad_style.rs | 2 +- src/librustc_mir/hair/cx/pattern.rs | 2 +- src/librustc_trans/_match.rs | 2 +- .../debuginfo/create_scope_map.rs | 2 +- src/librustc_typeck/check/_match.rs | 8 +++----- src/librustdoc/clean/mod.rs | 6 +++--- 16 files changed, 40 insertions(+), 55 deletions(-) diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index 18ea17f48162f..601d3866b02d4 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -101,7 +101,6 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { match pat.node { PatKind::Binding(_, _, None) | PatKind::Path(..) | - PatKind::QPath(..) | PatKind::Lit(..) | PatKind::Range(..) | PatKind::Wild => { diff --git a/src/librustc/hir/fold.rs b/src/librustc/hir/fold.rs index 78fd2bbbe0d25..5e0e6622185f8 100644 --- a/src/librustc/hir/fold.rs +++ b/src/librustc/hir/fold.rs @@ -930,12 +930,11 @@ pub fn noop_fold_pat(p: P, folder: &mut T) -> P { PatKind::TupleStruct(folder.fold_path(pth), pats.move_map(|x| folder.fold_pat(x)), ddpos) } - PatKind::Path(pth) => { - PatKind::Path(folder.fold_path(pth)) - } - PatKind::QPath(qself, pth) => { - let qself = QSelf { ty: folder.fold_ty(qself.ty), ..qself }; - PatKind::QPath(qself, folder.fold_path(pth)) + PatKind::Path(opt_qself, pth) => { + let opt_qself = opt_qself.map(|qself| { + QSelf { ty: folder.fold_ty(qself.ty), position: qself.position } + }); + PatKind::Path(opt_qself, folder.fold_path(pth)) } PatKind::Struct(pth, fields, etc) => { let pth = folder.fold_path(pth); diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 2d5c4ebf8d898..442c85af22a26 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -460,11 +460,10 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) { visitor.visit_path(path, pattern.id); walk_list!(visitor, visit_pat, children); } - PatKind::Path(ref path) => { - visitor.visit_path(path, pattern.id); - } - PatKind::QPath(ref qself, ref path) => { - visitor.visit_ty(&qself.ty); + PatKind::Path(ref opt_qself, ref path) => { + if let Some(ref qself) = *opt_qself { + visitor.visit_ty(&qself.ty); + } visitor.visit_path(path, pattern.id) } PatKind::Struct(ref path, ref fields, _) => { diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 2cc39412182dc..3e6a82ed47617 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -862,7 +862,8 @@ impl<'a> LoweringContext<'a> { respan(pth1.span, pth1.node.name), sub.as_ref().map(|x| this.lower_pat(x))) } - _ => hir::PatKind::Path(hir::Path::from_name(pth1.span, pth1.node.name)) + _ => hir::PatKind::Path(None, hir::Path::from_name(pth1.span, + pth1.node.name)) } }) } @@ -872,15 +873,11 @@ impl<'a> LoweringContext<'a> { pats.iter().map(|x| self.lower_pat(x)).collect(), ddpos) } - PatKind::Path(None, ref pth) => { - hir::PatKind::Path(self.lower_path(pth)) - } - PatKind::Path(Some(ref qself), ref pth) => { - let qself = hir::QSelf { - ty: self.lower_ty(&qself.ty), - position: qself.position, - }; - hir::PatKind::QPath(qself, self.lower_path(pth)) + PatKind::Path(ref opt_qself, ref path) => { + let opt_qself = opt_qself.map(|qself| { + hir::QSelf { ty: self.lower_ty(&qself.ty), position: qself.position } + }); + hir::PatKind::Path(opt_qself, self.lower_path(path)) } PatKind::Struct(ref pth, ref fields, etc) => { let pth = self.lower_path(pth); @@ -1831,7 +1828,7 @@ impl<'a> LoweringContext<'a> { -> P { let def = self.resolver.resolve_generated_global_path(&path, true); let pt = if subpats.is_empty() { - hir::PatKind::Path(path) + hir::PatKind::Path(None, path) } else { hir::PatKind::TupleStruct(path, subpats, None) }; diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index e1e681b7aff35..655f80ec07238 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -487,8 +487,7 @@ impl Pat { PatKind::Lit(_) | PatKind::Range(_, _) | PatKind::Binding(..) | - PatKind::Path(..) | - PatKind::QPath(_, _) => { + PatKind::Path(..) => { true } } @@ -538,15 +537,9 @@ pub enum PatKind { /// 0 <= position <= subpats.len() TupleStruct(Path, HirVec>, Option), - /// A path pattern. + /// A possibly qualified path pattern. /// Such pattern can be resolved to a unit struct/variant or a constant. - Path(Path), - - /// An associated const named using the qualified path `::CONST` or - /// `::CONST`. Associated consts from inherent impls can be - /// referred to as simply `T::CONST`, in which case they will end up as - /// PatKind::Path, and the resolver will have to sort that out. - QPath(QSelf, Path), + Path(Option, Path), /// A tuple pattern `(a, b)`. /// If the `..` pattern fragment is present, then `Option` denotes its position. diff --git a/src/librustc/hir/pat_util.rs b/src/librustc/hir/pat_util.rs index a26480114bcc0..593d10ef4f7c4 100644 --- a/src/librustc/hir/pat_util.rs +++ b/src/librustc/hir/pat_util.rs @@ -53,7 +53,7 @@ impl EnumerateAndAdjustIterator for T { pub fn pat_is_refutable(dm: &DefMap, pat: &hir::Pat) -> bool { match pat.node { - PatKind::Lit(_) | PatKind::Range(_, _) | PatKind::QPath(..) => true, + PatKind::Lit(_) | PatKind::Range(_, _) | PatKind::Path(Some(..), _) => true, PatKind::TupleStruct(..) | PatKind::Path(..) | PatKind::Struct(..) => { @@ -69,7 +69,7 @@ pub fn pat_is_refutable(dm: &DefMap, pat: &hir::Pat) -> bool { pub fn pat_is_const(dm: &DefMap, pat: &hir::Pat) -> bool { match pat.node { - PatKind::Path(..) | PatKind::QPath(..) => { + PatKind::Path(..) => { match dm.get(&pat.id).map(|d| d.full_def()) { Some(Def::Const(..)) | Some(Def::AssociatedConst(..)) => true, _ => false diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index bf6188faa2fbd..5f2fac5c01b30 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -1750,10 +1750,10 @@ impl<'a> State<'a> { } try!(self.pclose()); } - PatKind::Path(ref path) => { + PatKind::Path(None, ref path) => { self.print_path(path, true, 0)?; } - PatKind::QPath(ref qself, ref path) => { + PatKind::Path(Some(ref qself), ref path) => { self.print_qpath(path, qself, false)?; } PatKind::Struct(ref path, ref fields, etc) => { diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 3776a904923c9..28bfb460a14fa 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -1193,7 +1193,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { } } - PatKind::Path(..) | PatKind::QPath(..) | PatKind::Binding(_, _, None) | + PatKind::Path(..) | PatKind::Binding(_, _, None) | PatKind::Lit(..) | PatKind::Range(..) | PatKind::Wild => { // always ok } diff --git a/src/librustc_const_eval/check_match.rs b/src/librustc_const_eval/check_match.rs index b8283ccab24bd..866a91b4d9510 100644 --- a/src/librustc_const_eval/check_match.rs +++ b/src/librustc_const_eval/check_match.rs @@ -489,7 +489,7 @@ impl<'map> IdVisitingOperation for RenamingRecorder<'map> { impl<'a, 'tcx> Folder for StaticInliner<'a, 'tcx> { fn fold_pat(&mut self, pat: P) -> P { return match pat.node { - PatKind::Path(..) | PatKind::QPath(..) => { + PatKind::Path(..) => { match self.tcx.expect_def(pat.id) { Def::AssociatedConst(did) | Def::Const(did) => { let substs = Some(self.tcx.node_id_item_substs(pat.id).substs); @@ -583,7 +583,7 @@ fn construct_witness<'a,'tcx>(cx: &MatchCheckCtxt<'a,'tcx>, ctor: &Constructor, PatKind::TupleStruct(def_to_path(cx.tcx, v.did), pats.collect(), None) } VariantKind::Unit => { - PatKind::Path(def_to_path(cx.tcx, v.did)) + PatKind::Path(None, def_to_path(cx.tcx, v.did)) } } } @@ -784,7 +784,7 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat, left_ty: Ty, max_slice_length: usize) -> Vec { let pat = raw_pat(p); match pat.node { - PatKind::Struct(..) | PatKind::TupleStruct(..) | PatKind::Path(..) | PatKind::QPath(..) => + PatKind::Struct(..) | PatKind::TupleStruct(..) | PatKind::Path(..) => match cx.tcx.expect_def(pat.id) { Def::Variant(_, id) => vec![Variant(id)], Def::Struct(..) | Def::TyAlias(..) | Def::AssociatedTy(..) => vec![Single], @@ -895,7 +895,7 @@ pub fn specialize<'a, 'b, 'tcx>( PatKind::Binding(..) | PatKind::Wild => Some(vec![dummy_pat; arity]), - PatKind::Path(..) | PatKind::QPath(..) => { + PatKind::Path(..) => { match cx.tcx.expect_def(pat_id) { Def::Const(..) | Def::AssociatedConst(..) => span_bug!(pat_span, "const pattern should've \ diff --git a/src/librustc_const_eval/eval.rs b/src/librustc_const_eval/eval.rs index 6c37662206ce2..a3c707e82a0ff 100644 --- a/src/librustc_const_eval/eval.rs +++ b/src/librustc_const_eval/eval.rs @@ -323,7 +323,7 @@ pub fn const_expr_to_pat<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, hir::ExprPath(_, ref path) => { match tcx.expect_def(expr.id) { - Def::Struct(..) | Def::Variant(..) => PatKind::Path(path.clone()), + Def::Struct(..) | Def::Variant(..) => PatKind::Path(None, path.clone()), Def::Const(def_id) | Def::AssociatedConst(def_id) => { let substs = Some(tcx.node_id_item_substs(expr.id).substs); let (expr, _ty) = lookup_const_by_id(tcx, def_id, substs).unwrap(); diff --git a/src/librustc_lint/bad_style.rs b/src/librustc_lint/bad_style.rs index 7e9b6f561b984..15914838acf0d 100644 --- a/src/librustc_lint/bad_style.rs +++ b/src/librustc_lint/bad_style.rs @@ -360,7 +360,7 @@ impl LateLintPass for NonUpperCaseGlobals { fn check_pat(&mut self, cx: &LateContext, p: &hir::Pat) { // Lint for constants that look like binding identifiers (#7526) - if let PatKind::Path(ref path) = p.node { + if let PatKind::Path(None, ref path) = p.node { if !path.global && path.segments.len() == 1 && path.segments[0].parameters.is_empty() { if let Def::Const(..) = cx.tcx.expect_def(p.id) { NonUpperCaseGlobals::check_upper_case(cx, "constant in pattern", diff --git a/src/librustc_mir/hair/cx/pattern.rs b/src/librustc_mir/hair/cx/pattern.rs index 654108c14df87..c54c8bfb5981e 100644 --- a/src/librustc_mir/hair/cx/pattern.rs +++ b/src/librustc_mir/hair/cx/pattern.rs @@ -76,7 +76,7 @@ impl<'patcx, 'cx, 'gcx, 'tcx> PatCx<'patcx, 'cx, 'gcx, 'tcx> { PatternKind::Range { lo: lo, hi: hi } }, - PatKind::Path(..) | PatKind::QPath(..) => { + PatKind::Path(..) => { match self.cx.tcx.expect_def(pat.id) { Def::Const(def_id) | Def::AssociatedConst(def_id) => { let tcx = self.cx.tcx.global_tcx(); diff --git a/src/librustc_trans/_match.rs b/src/librustc_trans/_match.rs index d79278e99cb2e..08e894ffbcfd4 100644 --- a/src/librustc_trans/_match.rs +++ b/src/librustc_trans/_match.rs @@ -2003,7 +2003,7 @@ pub fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, cleanup_scope) }); } - PatKind::Path(..) | PatKind::QPath(..) | PatKind::Wild | + PatKind::Path(..) | PatKind::Wild | PatKind::Lit(..) | PatKind::Range(..) => () } return bcx; diff --git a/src/librustc_trans/debuginfo/create_scope_map.rs b/src/librustc_trans/debuginfo/create_scope_map.rs index 2b079e7dcc8d9..0b75402486812 100644 --- a/src/librustc_trans/debuginfo/create_scope_map.rs +++ b/src/librustc_trans/debuginfo/create_scope_map.rs @@ -313,7 +313,7 @@ fn walk_pattern(cx: &CrateContext, } } - PatKind::Path(..) | PatKind::QPath(..) => { + PatKind::Path(..) => { scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata); } diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index 4f7c8fbabdbd5..e4ed4c1c0b136 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -168,11 +168,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { PatKind::TupleStruct(ref path, ref subpats, ddpos) => { self.check_pat_tuple_struct(pat, path, &subpats, ddpos, expected); } - PatKind::Path(ref path) => { - self.check_pat_path(pat, None, path, expected); - } - PatKind::QPath(ref qself, ref path) => { - self.check_pat_path(pat, Some(self.to_ty(&qself.ty)), path, expected); + PatKind::Path(ref opt_qself, ref path) => { + let opt_qself_ty = opt_qself.as_ref().map(|qself| self.to_ty(&qself.ty)); + self.check_pat_path(pat, opt_qself_ty, path, expected); } PatKind::Struct(ref path, ref fields, etc) => { self.check_pat_struct(pat, path, fields, etc, expected); diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index b3b42b970ca84..c33e8159d19c4 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2578,9 +2578,9 @@ fn name_from_pat(p: &hir::Pat) -> String { match p.node { PatKind::Wild => "_".to_string(), PatKind::Binding(_, ref p, _) => p.node.to_string(), - PatKind::TupleStruct(ref p, _, _) | PatKind::Path(ref p) => path_to_string(p), - PatKind::QPath(..) => panic!("tried to get argument name from PatKind::QPath, \ - which is not allowed in function arguments"), + PatKind::TupleStruct(ref p, _, _) | PatKind::Path(None, ref p) => path_to_string(p), + PatKind::Path(..) => panic!("tried to get argument name from qualified PatKind::Path, \ + which is not allowed in function arguments"), PatKind::Struct(ref name, ref fields, etc) => { format!("{} {{ {}{} }}", path_to_string(name), fields.iter().map(|&Spanned { node: ref fp, .. }|