Skip to content

Commit 16b5c2c

Browse files
committed
rustc: desugar UFCS as much as possible during HIR lowering.
1 parent 34d1352 commit 16b5c2c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+637
-486
lines changed

src/librustc/cfg/construct.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
100100
fn pat(&mut self, pat: &hir::Pat, pred: CFGIndex) -> CFGIndex {
101101
match pat.node {
102102
PatKind::Binding(.., None) |
103-
PatKind::Path(..) |
103+
PatKind::Path(_) |
104104
PatKind::Lit(..) |
105105
PatKind::Range(..) |
106106
PatKind::Wild => {
@@ -361,7 +361,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
361361

362362
hir::ExprClosure(..) |
363363
hir::ExprLit(..) |
364-
hir::ExprPath(..) => {
364+
hir::ExprPath(_) => {
365365
self.straightline(expr, pred, None::<hir::Expr>.iter())
366366
}
367367
}

src/librustc/hir/intravisit.rs

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ pub trait Visitor<'v> : Sized {
244244
fn visit_lifetime_def(&mut self, lifetime: &'v LifetimeDef) {
245245
walk_lifetime_def(self, lifetime)
246246
}
247+
fn visit_qpath(&mut self, qpath: &'v QPath, id: NodeId, span: Span) {
248+
walk_qpath(self, qpath, id, span)
249+
}
247250
fn visit_path(&mut self, path: &'v Path, _id: NodeId) {
248251
walk_path(self, path)
249252
}
@@ -481,11 +484,8 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
481484
walk_fn_decl(visitor, &function_declaration.decl);
482485
walk_list!(visitor, visit_lifetime_def, &function_declaration.lifetimes);
483486
}
484-
TyPath(ref maybe_qself, ref path) => {
485-
if let Some(ref qself) = *maybe_qself {
486-
visitor.visit_ty(&qself.ty);
487-
}
488-
visitor.visit_path(path, typ.id);
487+
TyPath(ref qpath) => {
488+
visitor.visit_qpath(qpath, typ.id, typ.span);
489489
}
490490
TyObjectSum(ref ty, ref bounds) => {
491491
visitor.visit_ty(ty);
@@ -508,6 +508,21 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
508508
}
509509
}
510510

511+
pub fn walk_qpath<'v, V: Visitor<'v>>(visitor: &mut V, qpath: &'v QPath, id: NodeId, span: Span) {
512+
match *qpath {
513+
QPath::Resolved(ref maybe_qself, ref path) => {
514+
if let Some(ref qself) = *maybe_qself {
515+
visitor.visit_ty(qself);
516+
}
517+
visitor.visit_path(path, id)
518+
}
519+
QPath::TypeRelative(ref qself, ref segment) => {
520+
visitor.visit_ty(qself);
521+
visitor.visit_path_segment(span, segment);
522+
}
523+
}
524+
}
525+
511526
pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) {
512527
for segment in &path.segments {
513528
visitor.visit_path_segment(path.span, segment);
@@ -555,18 +570,15 @@ pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(visitor: &mut V,
555570
pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
556571
visitor.visit_id(pattern.id);
557572
match pattern.node {
558-
PatKind::TupleStruct(ref path, ref children, _) => {
559-
visitor.visit_path(path, pattern.id);
573+
PatKind::TupleStruct(ref qpath, ref children, _) => {
574+
visitor.visit_qpath(qpath, pattern.id, pattern.span);
560575
walk_list!(visitor, visit_pat, children);
561576
}
562-
PatKind::Path(ref opt_qself, ref path) => {
563-
if let Some(ref qself) = *opt_qself {
564-
visitor.visit_ty(&qself.ty);
565-
}
566-
visitor.visit_path(path, pattern.id)
577+
PatKind::Path(ref qpath) => {
578+
visitor.visit_qpath(qpath, pattern.id, pattern.span);
567579
}
568-
PatKind::Struct(ref path, ref fields, _) => {
569-
visitor.visit_path(path, pattern.id);
580+
PatKind::Struct(ref qpath, ref fields, _) => {
581+
visitor.visit_qpath(qpath, pattern.id, pattern.span);
570582
for field in fields {
571583
visitor.visit_name(field.span, field.node.name);
572584
visitor.visit_pat(&field.node.pat)
@@ -840,8 +852,8 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
840852
visitor.visit_expr(element);
841853
visitor.visit_expr(count)
842854
}
843-
ExprStruct(ref path, ref fields, ref optional_base) => {
844-
visitor.visit_path(path, expression.id);
855+
ExprStruct(ref qpath, ref fields, ref optional_base) => {
856+
visitor.visit_qpath(qpath, expression.id, expression.span);
845857
for field in fields {
846858
visitor.visit_name(field.name.span, field.name.node);
847859
visitor.visit_expr(&field.expr)
@@ -917,11 +929,8 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
917929
visitor.visit_expr(main_expression);
918930
visitor.visit_expr(index_expression)
919931
}
920-
ExprPath(ref maybe_qself, ref path) => {
921-
if let Some(ref qself) = *maybe_qself {
922-
visitor.visit_ty(&qself.ty);
923-
}
924-
visitor.visit_path(path, expression.id)
932+
ExprPath(ref qpath) => {
933+
visitor.visit_qpath(qpath, expression.id, expression.span);
925934
}
926935
ExprBreak(ref opt_sp_name, ref opt_expr) => {
927936
walk_opt_sp_name(visitor, opt_sp_name);

0 commit comments

Comments
 (0)