From a20c177827deb7687856e48dbbace63a22408a07 Mon Sep 17 00:00:00 2001 From: Michael Lamparski Date: Mon, 11 Jun 2018 19:26:53 -0400 Subject: [PATCH] add fold::Folder::fold_qpath --- src/libsyntax/fold.rs | 49 +++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 2f209b347a4b6..1056b3dad1739 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -168,6 +168,10 @@ pub trait Folder : Sized { noop_fold_path(p, self) } + fn fold_qpath(&mut self, qs: Option, p: Path) -> (Option, Path) { + noop_fold_qpath(qs, p, self) + } + fn fold_path_parameters(&mut self, p: PathParameters) -> PathParameters { noop_fold_path_parameters(p, self) } @@ -370,14 +374,8 @@ pub fn noop_fold_ty(t: P, fld: &mut T) -> P { TyKind::Tup(tys) => TyKind::Tup(tys.move_map(|ty| fld.fold_ty(ty))), TyKind::Paren(ty) => TyKind::Paren(fld.fold_ty(ty)), TyKind::Path(qself, path) => { - let qself = qself.map(|QSelf { ty, path_span, position }| { - QSelf { - ty: fld.fold_ty(ty), - path_span: fld.new_span(path_span), - position, - } - }); - TyKind::Path(qself, fld.fold_path(path)) + let (qself, path) = fld.fold_qpath(qself, path); + TyKind::Path(qself, path) } TyKind::Array(ty, length) => { TyKind::Array(fld.fold_ty(ty), fld.fold_anon_const(length)) @@ -442,6 +440,19 @@ pub fn noop_fold_path(Path { segments, span }: Path, fld: &mut T) -> } } +pub fn noop_fold_qpath(qself: Option, + path: Path, + fld: &mut T) -> (Option, Path) { + let qself = qself.map(|QSelf { ty, path_span, position }| { + QSelf { + ty: fld.fold_ty(ty), + path_span: fld.new_span(path_span), + position, + } + }); + (qself, fld.fold_path(path)) +} + pub fn noop_fold_path_parameters(path_parameters: PathParameters, fld: &mut T) -> PathParameters { @@ -1097,15 +1108,9 @@ 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(opt_qself, pth) => { - let opt_qself = opt_qself.map(|qself| { - QSelf { - ty: folder.fold_ty(qself.ty), - path_span: folder.new_span(qself.path_span), - position: qself.position, - } - }); - PatKind::Path(opt_qself, folder.fold_path(pth)) + PatKind::Path(qself, pth) => { + let (qself, pth) = folder.fold_qpath(qself, pth); + PatKind::Path(qself, pth) } PatKind::Struct(pth, fields, etc) => { let pth = folder.fold_path(pth); @@ -1267,14 +1272,8 @@ pub fn noop_fold_expr(Expr {id, node, span, attrs}: Expr, folder: &mu lim) } ExprKind::Path(qself, path) => { - let qself = qself.map(|QSelf { ty, path_span, position }| { - QSelf { - ty: folder.fold_ty(ty), - path_span: folder.new_span(path_span), - position, - } - }); - ExprKind::Path(qself, folder.fold_path(path)) + let (qself, path) = folder.fold_qpath(qself, path); + ExprKind::Path(qself, path) } ExprKind::Break(opt_label, opt_expr) => { ExprKind::Break(opt_label.map(|label| folder.fold_label(label)),