Skip to content

Commit 9c05fb2

Browse files
committed
Merge PatKind::QPath into PatKind::Path in HIR
1 parent a397b60 commit 9c05fb2

File tree

16 files changed

+40
-55
lines changed

16 files changed

+40
-55
lines changed

src/librustc/cfg/construct.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
101101
match pat.node {
102102
PatKind::Binding(_, _, None) |
103103
PatKind::Path(..) |
104-
PatKind::QPath(..) |
105104
PatKind::Lit(..) |
106105
PatKind::Range(..) |
107106
PatKind::Wild => {

src/librustc/hir/fold.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -930,12 +930,11 @@ pub fn noop_fold_pat<T: Folder>(p: P<Pat>, folder: &mut T) -> P<Pat> {
930930
PatKind::TupleStruct(folder.fold_path(pth),
931931
pats.move_map(|x| folder.fold_pat(x)), ddpos)
932932
}
933-
PatKind::Path(pth) => {
934-
PatKind::Path(folder.fold_path(pth))
935-
}
936-
PatKind::QPath(qself, pth) => {
937-
let qself = QSelf { ty: folder.fold_ty(qself.ty), ..qself };
938-
PatKind::QPath(qself, folder.fold_path(pth))
933+
PatKind::Path(opt_qself, pth) => {
934+
let opt_qself = opt_qself.map(|qself| {
935+
QSelf { ty: folder.fold_ty(qself.ty), position: qself.position }
936+
});
937+
PatKind::Path(opt_qself, folder.fold_path(pth))
939938
}
940939
PatKind::Struct(pth, fields, etc) => {
941940
let pth = folder.fold_path(pth);

src/librustc/hir/intravisit.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -460,11 +460,10 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
460460
visitor.visit_path(path, pattern.id);
461461
walk_list!(visitor, visit_pat, children);
462462
}
463-
PatKind::Path(ref path) => {
464-
visitor.visit_path(path, pattern.id);
465-
}
466-
PatKind::QPath(ref qself, ref path) => {
467-
visitor.visit_ty(&qself.ty);
463+
PatKind::Path(ref opt_qself, ref path) => {
464+
if let Some(ref qself) = *opt_qself {
465+
visitor.visit_ty(&qself.ty);
466+
}
468467
visitor.visit_path(path, pattern.id)
469468
}
470469
PatKind::Struct(ref path, ref fields, _) => {

src/librustc/hir/lowering.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,8 @@ impl<'a> LoweringContext<'a> {
862862
respan(pth1.span, pth1.node.name),
863863
sub.as_ref().map(|x| this.lower_pat(x)))
864864
}
865-
_ => hir::PatKind::Path(hir::Path::from_name(pth1.span, pth1.node.name))
865+
_ => hir::PatKind::Path(None, hir::Path::from_name(pth1.span,
866+
pth1.node.name))
866867
}
867868
})
868869
}
@@ -872,15 +873,11 @@ impl<'a> LoweringContext<'a> {
872873
pats.iter().map(|x| self.lower_pat(x)).collect(),
873874
ddpos)
874875
}
875-
PatKind::Path(None, ref pth) => {
876-
hir::PatKind::Path(self.lower_path(pth))
877-
}
878-
PatKind::Path(Some(ref qself), ref pth) => {
879-
let qself = hir::QSelf {
880-
ty: self.lower_ty(&qself.ty),
881-
position: qself.position,
882-
};
883-
hir::PatKind::QPath(qself, self.lower_path(pth))
876+
PatKind::Path(ref opt_qself, ref path) => {
877+
let opt_qself = opt_qself.map(|qself| {
878+
hir::QSelf { ty: self.lower_ty(&qself.ty), position: qself.position }
879+
});
880+
hir::PatKind::Path(opt_qself, self.lower_path(path))
884881
}
885882
PatKind::Struct(ref pth, ref fields, etc) => {
886883
let pth = self.lower_path(pth);
@@ -1831,7 +1828,7 @@ impl<'a> LoweringContext<'a> {
18311828
-> P<hir::Pat> {
18321829
let def = self.resolver.resolve_generated_global_path(&path, true);
18331830
let pt = if subpats.is_empty() {
1834-
hir::PatKind::Path(path)
1831+
hir::PatKind::Path(None, path)
18351832
} else {
18361833
hir::PatKind::TupleStruct(path, subpats, None)
18371834
};

src/librustc/hir/mod.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,7 @@ impl Pat {
487487
PatKind::Lit(_) |
488488
PatKind::Range(_, _) |
489489
PatKind::Binding(..) |
490-
PatKind::Path(..) |
491-
PatKind::QPath(_, _) => {
490+
PatKind::Path(..) => {
492491
true
493492
}
494493
}
@@ -538,15 +537,9 @@ pub enum PatKind {
538537
/// 0 <= position <= subpats.len()
539538
TupleStruct(Path, HirVec<P<Pat>>, Option<usize>),
540539

541-
/// A path pattern.
540+
/// A possibly qualified path pattern.
542541
/// Such pattern can be resolved to a unit struct/variant or a constant.
543-
Path(Path),
544-
545-
/// An associated const named using the qualified path `<T>::CONST` or
546-
/// `<T as Trait>::CONST`. Associated consts from inherent impls can be
547-
/// referred to as simply `T::CONST`, in which case they will end up as
548-
/// PatKind::Path, and the resolver will have to sort that out.
549-
QPath(QSelf, Path),
542+
Path(Option<QSelf>, Path),
550543

551544
/// A tuple pattern `(a, b)`.
552545
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.

src/librustc/hir/pat_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<T: ExactSizeIterator> EnumerateAndAdjustIterator for T {
5353

5454
pub fn pat_is_refutable(dm: &DefMap, pat: &hir::Pat) -> bool {
5555
match pat.node {
56-
PatKind::Lit(_) | PatKind::Range(_, _) | PatKind::QPath(..) => true,
56+
PatKind::Lit(_) | PatKind::Range(_, _) | PatKind::Path(Some(..), _) => true,
5757
PatKind::TupleStruct(..) |
5858
PatKind::Path(..) |
5959
PatKind::Struct(..) => {
@@ -69,7 +69,7 @@ pub fn pat_is_refutable(dm: &DefMap, pat: &hir::Pat) -> bool {
6969

7070
pub fn pat_is_const(dm: &DefMap, pat: &hir::Pat) -> bool {
7171
match pat.node {
72-
PatKind::Path(..) | PatKind::QPath(..) => {
72+
PatKind::Path(..) => {
7373
match dm.get(&pat.id).map(|d| d.full_def()) {
7474
Some(Def::Const(..)) | Some(Def::AssociatedConst(..)) => true,
7575
_ => false

src/librustc/hir/print.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,10 +1750,10 @@ impl<'a> State<'a> {
17501750
}
17511751
try!(self.pclose());
17521752
}
1753-
PatKind::Path(ref path) => {
1753+
PatKind::Path(None, ref path) => {
17541754
self.print_path(path, true, 0)?;
17551755
}
1756-
PatKind::QPath(ref qself, ref path) => {
1756+
PatKind::Path(Some(ref qself), ref path) => {
17571757
self.print_qpath(path, qself, false)?;
17581758
}
17591759
PatKind::Struct(ref path, ref fields, etc) => {

src/librustc/middle/mem_categorization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
11931193
}
11941194
}
11951195

1196-
PatKind::Path(..) | PatKind::QPath(..) | PatKind::Binding(_, _, None) |
1196+
PatKind::Path(..) | PatKind::Binding(_, _, None) |
11971197
PatKind::Lit(..) | PatKind::Range(..) | PatKind::Wild => {
11981198
// always ok
11991199
}

src/librustc_const_eval/check_match.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ impl<'map> IdVisitingOperation for RenamingRecorder<'map> {
489489
impl<'a, 'tcx> Folder for StaticInliner<'a, 'tcx> {
490490
fn fold_pat(&mut self, pat: P<Pat>) -> P<Pat> {
491491
return match pat.node {
492-
PatKind::Path(..) | PatKind::QPath(..) => {
492+
PatKind::Path(..) => {
493493
match self.tcx.expect_def(pat.id) {
494494
Def::AssociatedConst(did) | Def::Const(did) => {
495495
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,
583583
PatKind::TupleStruct(def_to_path(cx.tcx, v.did), pats.collect(), None)
584584
}
585585
VariantKind::Unit => {
586-
PatKind::Path(def_to_path(cx.tcx, v.did))
586+
PatKind::Path(None, def_to_path(cx.tcx, v.did))
587587
}
588588
}
589589
}
@@ -784,7 +784,7 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat,
784784
left_ty: Ty, max_slice_length: usize) -> Vec<Constructor> {
785785
let pat = raw_pat(p);
786786
match pat.node {
787-
PatKind::Struct(..) | PatKind::TupleStruct(..) | PatKind::Path(..) | PatKind::QPath(..) =>
787+
PatKind::Struct(..) | PatKind::TupleStruct(..) | PatKind::Path(..) =>
788788
match cx.tcx.expect_def(pat.id) {
789789
Def::Variant(_, id) => vec![Variant(id)],
790790
Def::Struct(..) | Def::TyAlias(..) | Def::AssociatedTy(..) => vec![Single],
@@ -895,7 +895,7 @@ pub fn specialize<'a, 'b, 'tcx>(
895895
PatKind::Binding(..) | PatKind::Wild =>
896896
Some(vec![dummy_pat; arity]),
897897

898-
PatKind::Path(..) | PatKind::QPath(..) => {
898+
PatKind::Path(..) => {
899899
match cx.tcx.expect_def(pat_id) {
900900
Def::Const(..) | Def::AssociatedConst(..) =>
901901
span_bug!(pat_span, "const pattern should've \

src/librustc_const_eval/eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ pub fn const_expr_to_pat<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
323323

324324
hir::ExprPath(_, ref path) => {
325325
match tcx.expect_def(expr.id) {
326-
Def::Struct(..) | Def::Variant(..) => PatKind::Path(path.clone()),
326+
Def::Struct(..) | Def::Variant(..) => PatKind::Path(None, path.clone()),
327327
Def::Const(def_id) | Def::AssociatedConst(def_id) => {
328328
let substs = Some(tcx.node_id_item_substs(expr.id).substs);
329329
let (expr, _ty) = lookup_const_by_id(tcx, def_id, substs).unwrap();

0 commit comments

Comments
 (0)