diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs
index 05c7a326d0430..374d0c69aaad3 100644
--- a/src/librustc/hir/lowering.rs
+++ b/src/librustc/hir/lowering.rs
@@ -867,10 +867,10 @@ impl<'a> LoweringContext<'a> {
pats.iter().map(|x| self.lower_pat(x)).collect(),
ddpos)
}
- PatKind::Path(ref pth) => {
+ PatKind::Path(None, ref pth) => {
hir::PatKind::Path(self.lower_path(pth))
}
- PatKind::QPath(ref qself, ref pth) => {
+ PatKind::Path(Some(ref qself), ref pth) => {
let qself = hir::QSelf {
ty: self.lower_ty(&qself.ty),
position: qself.position,
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index d5c5707284f9d..688e46dca3eaf 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -2333,8 +2333,8 @@ impl<'a> Resolver<'a> {
}, "variant or struct");
}
- PatKind::Path(ref path) => {
- self.resolve_pattern_path(pat.id, None, path, ValueNS, |def| {
+ PatKind::Path(ref qself, ref path) => {
+ self.resolve_pattern_path(pat.id, qself.as_ref(), path, ValueNS, |def| {
match def {
Def::Struct(..) | Def::Variant(..) |
Def::Const(..) | Def::AssociatedConst(..) | Def::Err => true,
@@ -2343,15 +2343,6 @@ impl<'a> Resolver<'a> {
}, "variant, struct or constant");
}
- PatKind::QPath(ref qself, ref path) => {
- self.resolve_pattern_path(pat.id, Some(qself), path, ValueNS, |def| {
- match def {
- Def::AssociatedConst(..) | Def::Err => true,
- _ => false,
- }
- }, "associated constant");
- }
-
PatKind::Struct(ref path, _, _) => {
self.resolve_pattern_path(pat.id, None, path, TypeNS, |def| {
match def {
diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs
index 3335133816043..c45aecd07e11e 100644
--- a/src/librustc_save_analysis/lib.rs
+++ b/src/librustc_save_analysis/lib.rs
@@ -699,8 +699,7 @@ impl<'v> Visitor<'v> for PathCollector {
ast::Mutability::Mutable, recorder::TypeRef));
}
PatKind::TupleStruct(ref path, _, _) |
- PatKind::Path(ref path) |
- PatKind::QPath(_, ref path) => {
+ PatKind::Path(_, ref path) => {
self.collected_paths.push((p.id, path.clone(),
ast::Mutability::Mutable, recorder::VarRef));
}
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 64680ff4d8abe..b2aafca40a3db 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -611,7 +611,6 @@ impl Pat {
PatKind::Range(_, _) |
PatKind::Ident(_, _, _) |
PatKind::Path(..) |
- PatKind::QPath(_, _) |
PatKind::Mac(_) => {
true
}
@@ -659,15 +658,11 @@ pub enum PatKind {
/// 0 <= position <= subpats.len()
TupleStruct(Path, Vec
>, Option),
- /// A 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),
+ /// A possibly qualified path pattern.
+ /// Unquailfied path patterns `A::B::C` can legally refer to variants, structs, constants
+ /// or associated constants. Quailfied path patterns `::B::C`/`::B::C` can
+ /// only legally refer to associated constants.
+ Path(Option, Path),
/// A tuple pattern `(a, b)`.
/// If the `..` pattern fragment is present, then `Option` denotes its position.
diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs
index 3a1cdae9bfbd0..1d27cf5b0a19e 100644
--- a/src/libsyntax/ext/build.rs
+++ b/src/libsyntax/ext/build.rs
@@ -830,7 +830,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
}
fn pat_enum(&self, span: Span, path: ast::Path, subpats: Vec>) -> P {
let pat = if subpats.is_empty() {
- PatKind::Path(path)
+ PatKind::Path(None, path)
} else {
PatKind::TupleStruct(path, subpats, None)
};
diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs
index c44d5f368fe86..18661f3dc01ed 100644
--- a/src/libsyntax/fold.rs
+++ b/src/libsyntax/fold.rs
@@ -1091,12 +1091,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/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index fafe16192f087..de41ab5e1893e 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -3740,12 +3740,7 @@ impl<'a> Parser<'a> {
pat = PatKind::TupleStruct(path, fields, ddpos)
}
_ => {
- pat = match qself {
- // Parse qualified path
- Some(qself) => PatKind::QPath(qself, path),
- // Parse nullary enum
- None => PatKind::Path(path)
- };
+ pat = PatKind::Path(qself, path);
}
}
}
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index fb1c9679c8f74..1fefc53af6320 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -2494,10 +2494,10 @@ impl<'a> State<'a> {
}
try!(self.pclose());
}
- PatKind::Path(ref path) => {
+ PatKind::Path(None, ref path) => {
try!(self.print_path(path, true, 0));
}
- PatKind::QPath(ref qself, ref path) => {
+ PatKind::Path(Some(ref qself), ref path) => {
try!(self.print_qpath(path, qself, false));
}
PatKind::Struct(ref path, ref fields, etc) => {
diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs
index db911fc667bf9..5ec4c3eef3189 100644
--- a/src/libsyntax/visit.rs
+++ b/src/libsyntax/visit.rs
@@ -409,11 +409,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/test/compile-fail/method-resolvable-path-in-pattern.rs b/src/test/compile-fail/method-resolvable-path-in-pattern.rs
index 1cba64ccf2cde..3ae792f9c0f37 100644
--- a/src/test/compile-fail/method-resolvable-path-in-pattern.rs
+++ b/src/test/compile-fail/method-resolvable-path-in-pattern.rs
@@ -19,6 +19,6 @@ impl MyTrait for Foo {}
fn main() {
match 0u32 {
::trait_bar => {}
- //~^ ERROR expected associated constant, found method `trait_bar`
+ //~^ ERROR expected variant, struct or constant, found method `trait_bar`
}
}