Skip to content

Commit

Permalink
Merge PatKind::QPath into PatKind::Path in HIR
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Jul 8, 2016
1 parent a397b60 commit 9c05fb2
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 55 deletions.
1 change: 0 additions & 1 deletion src/librustc/cfg/construct.rs
Expand Up @@ -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 => {
Expand Down
11 changes: 5 additions & 6 deletions src/librustc/hir/fold.rs
Expand Up @@ -930,12 +930,11 @@ pub fn noop_fold_pat<T: Folder>(p: P<Pat>, folder: &mut T) -> P<Pat> {
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);
Expand Down
9 changes: 4 additions & 5 deletions src/librustc/hir/intravisit.rs
Expand Up @@ -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, _) => {
Expand Down
19 changes: 8 additions & 11 deletions src/librustc/hir/lowering.rs
Expand Up @@ -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))
}
})
}
Expand All @@ -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);
Expand Down Expand Up @@ -1831,7 +1828,7 @@ impl<'a> LoweringContext<'a> {
-> P<hir::Pat> {
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)
};
Expand Down
13 changes: 3 additions & 10 deletions src/librustc/hir/mod.rs
Expand Up @@ -487,8 +487,7 @@ impl Pat {
PatKind::Lit(_) |
PatKind::Range(_, _) |
PatKind::Binding(..) |
PatKind::Path(..) |
PatKind::QPath(_, _) => {
PatKind::Path(..) => {
true
}
}
Expand Down Expand Up @@ -538,15 +537,9 @@ pub enum PatKind {
/// 0 <= position <= subpats.len()
TupleStruct(Path, HirVec<P<Pat>>, Option<usize>),

/// 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 `<T>::CONST` or
/// `<T as Trait>::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<QSelf>, Path),

/// A tuple pattern `(a, b)`.
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/hir/pat_util.rs
Expand Up @@ -53,7 +53,7 @@ impl<T: ExactSizeIterator> 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(..) => {
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/hir/print.rs
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/mem_categorization.rs
Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_const_eval/check_match.rs
Expand Up @@ -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<Pat>) -> P<Pat> {
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);
Expand Down Expand Up @@ -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))
}
}
}
Expand Down Expand Up @@ -784,7 +784,7 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat,
left_ty: Ty, max_slice_length: usize) -> Vec<Constructor> {
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],
Expand Down Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_const_eval/eval.rs
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/bad_style.rs
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/hair/cx/pattern.rs
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/_match.rs
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/debuginfo/create_scope_map.rs
Expand Up @@ -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);
}

Expand Down
8 changes: 3 additions & 5 deletions src/librustc_typeck/check/_match.rs
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/clean/mod.rs
Expand Up @@ -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, .. }|
Expand Down

0 comments on commit 9c05fb2

Please sign in to comment.