match pat.node {
PatKind::Binding(_, _, None) |
PatKind::Path(..) |
- PatKind::QPath(..) |
PatKind::Lit(..) |
PatKind::Range(..) |
PatKind::Wild => {
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);
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, _) => {
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))
}
})
}
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);
-> 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)
};
PatKind::Lit(_) |
PatKind::Range(_, _) |
PatKind::Binding(..) |
- PatKind::Path(..) |
- PatKind::QPath(_, _) => {
+ PatKind::Path(..) => {
true
}
}
/// 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.
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(..) => {
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
}
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) => {
}
}
- PatKind::Path(..) | PatKind::QPath(..) | PatKind::Binding(_, _, None) |
+ PatKind::Path(..) | PatKind::Binding(_, _, None) |
PatKind::Lit(..) | PatKind::Range(..) | PatKind::Wild => {
// always ok
}
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);
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))
}
}
}
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],
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 \
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();
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",
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();
cleanup_scope)
});
}
- PatKind::Path(..) | PatKind::QPath(..) | PatKind::Wild |
+ PatKind::Path(..) | PatKind::Wild |
PatKind::Lit(..) | PatKind::Range(..) => ()
}
return bcx;
}
}
- PatKind::Path(..) | PatKind::QPath(..) => {
+ PatKind::Path(..) => {
scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
}
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);
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, .. }|