Skip to content

Merge PatKind::QPath into PatKind::Path in AST #34368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
@@ -866,10 +866,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,
13 changes: 2 additions & 11 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
@@ -2332,8 +2332,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,
@@ -2342,15 +2342,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 {
3 changes: 1 addition & 2 deletions src/librustc_save_analysis/lib.rs
Original file line number Diff line number Diff line change
@@ -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));
}
15 changes: 5 additions & 10 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
@@ -579,7 +579,6 @@ impl Pat {
PatKind::Range(_, _) |
PatKind::Ident(_, _, _) |
PatKind::Path(..) |
PatKind::QPath(_, _) |
PatKind::Mac(_) => {
true
}
@@ -627,15 +626,11 @@ pub enum PatKind {
/// 0 <= position <= subpats.len()
TupleStruct(Path, Vec<P<Pat>>, Option<usize>),

/// 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 `<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),
/// A possibly qualified path pattern.
/// Unquailfied path patterns `A::B::C` can legally refer to variants, structs, constants
/// or associated constants. Quailfied path patterns `<A>::B::C`/`<A as Trait>::B::C` can
/// only legally refer to associated constants.
Path(Option<QSelf>, Path),

/// A tuple pattern `(a, b)`.
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
2 changes: 1 addition & 1 deletion src/libsyntax/ext/build.rs
Original file line number Diff line number Diff line change
@@ -830,7 +830,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
}
fn pat_enum(&self, span: Span, path: ast::Path, subpats: Vec<P<ast::Pat>>) -> P<ast::Pat> {
let pat = if subpats.is_empty() {
PatKind::Path(path)
PatKind::Path(None, path)
} else {
PatKind::TupleStruct(path, subpats, None)
};
11 changes: 5 additions & 6 deletions src/libsyntax/fold.rs
Original file line number Diff line number Diff line change
@@ -1088,12 +1088,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);
7 changes: 1 addition & 6 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
@@ -3715,12 +3715,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);
}
}
}
4 changes: 2 additions & 2 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
@@ -2483,10 +2483,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) => {
9 changes: 4 additions & 5 deletions src/libsyntax/visit.rs
Original file line number Diff line number Diff line change
@@ -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, _) => {
2 changes: 1 addition & 1 deletion src/test/compile-fail/method-resolvable-path-in-pattern.rs
Original file line number Diff line number Diff line change
@@ -19,6 +19,6 @@ impl MyTrait for Foo {}
fn main() {
match 0u32 {
<Foo as MyTrait>::trait_bar => {}
//~^ ERROR expected associated constant, found method `trait_bar`
//~^ ERROR expected variant, struct or constant, found method `trait_bar`
}
}