Rollup merge of #34368 - petrochenkov:astqpath, r=Manishearth

The AST part of https://github.com/rust-lang/rust/pull/34365

plugin-[breaking-change] cc https://github.com/rust-lang/rust/issues/31645
This commit is contained in:
Jeffrey Seyfried 2016-06-25 22:26:47 +00:00
commit 4e2e31c118
10 changed files with 24 additions and 46 deletions

View File

@ -867,10 +867,10 @@ impl<'a> LoweringContext<'a> {
pats.iter().map(|x| self.lower_pat(x)).collect(), pats.iter().map(|x| self.lower_pat(x)).collect(),
ddpos) ddpos)
} }
PatKind::Path(ref pth) => { PatKind::Path(None, ref pth) => {
hir::PatKind::Path(self.lower_path(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 { let qself = hir::QSelf {
ty: self.lower_ty(&qself.ty), ty: self.lower_ty(&qself.ty),
position: qself.position, position: qself.position,

View File

@ -2333,8 +2333,8 @@ impl<'a> Resolver<'a> {
}, "variant or struct"); }, "variant or struct");
} }
PatKind::Path(ref path) => { PatKind::Path(ref qself, ref path) => {
self.resolve_pattern_path(pat.id, None, path, ValueNS, |def| { self.resolve_pattern_path(pat.id, qself.as_ref(), path, ValueNS, |def| {
match def { match def {
Def::Struct(..) | Def::Variant(..) | Def::Struct(..) | Def::Variant(..) |
Def::Const(..) | Def::AssociatedConst(..) | Def::Err => true, Def::Const(..) | Def::AssociatedConst(..) | Def::Err => true,
@ -2343,15 +2343,6 @@ impl<'a> Resolver<'a> {
}, "variant, struct or constant"); }, "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, _, _) => { PatKind::Struct(ref path, _, _) => {
self.resolve_pattern_path(pat.id, None, path, TypeNS, |def| { self.resolve_pattern_path(pat.id, None, path, TypeNS, |def| {
match def { match def {

View File

@ -699,8 +699,7 @@ impl<'v> Visitor<'v> for PathCollector {
ast::Mutability::Mutable, recorder::TypeRef)); ast::Mutability::Mutable, recorder::TypeRef));
} }
PatKind::TupleStruct(ref path, _, _) | PatKind::TupleStruct(ref path, _, _) |
PatKind::Path(ref path) | PatKind::Path(_, ref path) => {
PatKind::QPath(_, ref path) => {
self.collected_paths.push((p.id, path.clone(), self.collected_paths.push((p.id, path.clone(),
ast::Mutability::Mutable, recorder::VarRef)); ast::Mutability::Mutable, recorder::VarRef));
} }

View File

@ -611,7 +611,6 @@ impl Pat {
PatKind::Range(_, _) | PatKind::Range(_, _) |
PatKind::Ident(_, _, _) | PatKind::Ident(_, _, _) |
PatKind::Path(..) | PatKind::Path(..) |
PatKind::QPath(_, _) |
PatKind::Mac(_) => { PatKind::Mac(_) => {
true true
} }
@ -659,15 +658,11 @@ pub enum PatKind {
/// 0 <= position <= subpats.len() /// 0 <= position <= subpats.len()
TupleStruct(Path, Vec<P<Pat>>, Option<usize>), TupleStruct(Path, Vec<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. /// Unquailfied path patterns `A::B::C` can legally refer to variants, structs, constants
Path(Path), /// or associated constants. Quailfied path patterns `<A>::B::C`/`<A as Trait>::B::C` can
/// only legally refer to associated constants.
/// An associated const named using the qualified path `<T>::CONST` or Path(Option<QSelf>, Path),
/// `<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 tuple pattern `(a, b)`. /// A tuple pattern `(a, b)`.
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position. /// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.

View File

@ -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> { fn pat_enum(&self, span: Span, path: ast::Path, subpats: Vec<P<ast::Pat>>) -> P<ast::Pat> {
let pat = if subpats.is_empty() { let pat = if subpats.is_empty() {
PatKind::Path(path) PatKind::Path(None, path)
} else { } else {
PatKind::TupleStruct(path, subpats, None) PatKind::TupleStruct(path, subpats, None)
}; };

View File

@ -1091,12 +1091,11 @@ pub fn noop_fold_pat<T: Folder>(p: P<Pat>, folder: &mut T) -> P<Pat> {
PatKind::TupleStruct(folder.fold_path(pth), PatKind::TupleStruct(folder.fold_path(pth),
pats.move_map(|x| folder.fold_pat(x)), ddpos) pats.move_map(|x| folder.fold_pat(x)), ddpos)
} }
PatKind::Path(pth) => { PatKind::Path(opt_qself, pth) => {
PatKind::Path(folder.fold_path(pth)) let opt_qself = opt_qself.map(|qself| {
} QSelf { ty: folder.fold_ty(qself.ty), position: qself.position }
PatKind::QPath(qself, pth) => { });
let qself = QSelf {ty: folder.fold_ty(qself.ty), .. qself}; PatKind::Path(opt_qself, folder.fold_path(pth))
PatKind::QPath(qself, folder.fold_path(pth))
} }
PatKind::Struct(pth, fields, etc) => { PatKind::Struct(pth, fields, etc) => {
let pth = folder.fold_path(pth); let pth = folder.fold_path(pth);

View File

@ -3740,12 +3740,7 @@ impl<'a> Parser<'a> {
pat = PatKind::TupleStruct(path, fields, ddpos) pat = PatKind::TupleStruct(path, fields, ddpos)
} }
_ => { _ => {
pat = match qself { pat = PatKind::Path(qself, path);
// Parse qualified path
Some(qself) => PatKind::QPath(qself, path),
// Parse nullary enum
None => PatKind::Path(path)
};
} }
} }
} }

View File

@ -2494,10 +2494,10 @@ impl<'a> State<'a> {
} }
try!(self.pclose()); try!(self.pclose());
} }
PatKind::Path(ref path) => { PatKind::Path(None, ref path) => {
try!(self.print_path(path, true, 0)); 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)); try!(self.print_qpath(path, qself, false));
} }
PatKind::Struct(ref path, ref fields, etc) => { PatKind::Struct(ref path, ref fields, etc) => {

View File

@ -409,11 +409,10 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
visitor.visit_path(path, pattern.id); visitor.visit_path(path, pattern.id);
walk_list!(visitor, visit_pat, children); walk_list!(visitor, visit_pat, children);
} }
PatKind::Path(ref path) => { PatKind::Path(ref opt_qself, ref path) => {
visitor.visit_path(path, pattern.id); if let Some(ref qself) = *opt_qself {
} visitor.visit_ty(&qself.ty);
PatKind::QPath(ref qself, ref path) => { }
visitor.visit_ty(&qself.ty);
visitor.visit_path(path, pattern.id) visitor.visit_path(path, pattern.id)
} }
PatKind::Struct(ref path, ref fields, _) => { PatKind::Struct(ref path, ref fields, _) => {

View File

@ -19,6 +19,6 @@ impl MyTrait for Foo {}
fn main() { fn main() {
match 0u32 { match 0u32 {
<Foo as MyTrait>::trait_bar => {} <Foo as MyTrait>::trait_bar => {}
//~^ ERROR expected associated constant, found method `trait_bar` //~^ ERROR expected variant, struct or constant, found method `trait_bar`
} }
} }