Skip to content

Commit a20c177

Browse files
committed
add fold::Folder::fold_qpath
1 parent d0c59e2 commit a20c177

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

src/libsyntax/fold.rs

+24-25
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ pub trait Folder : Sized {
168168
noop_fold_path(p, self)
169169
}
170170

171+
fn fold_qpath(&mut self, qs: Option<QSelf>, p: Path) -> (Option<QSelf>, Path) {
172+
noop_fold_qpath(qs, p, self)
173+
}
174+
171175
fn fold_path_parameters(&mut self, p: PathParameters) -> PathParameters {
172176
noop_fold_path_parameters(p, self)
173177
}
@@ -370,14 +374,8 @@ pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> {
370374
TyKind::Tup(tys) => TyKind::Tup(tys.move_map(|ty| fld.fold_ty(ty))),
371375
TyKind::Paren(ty) => TyKind::Paren(fld.fold_ty(ty)),
372376
TyKind::Path(qself, path) => {
373-
let qself = qself.map(|QSelf { ty, path_span, position }| {
374-
QSelf {
375-
ty: fld.fold_ty(ty),
376-
path_span: fld.new_span(path_span),
377-
position,
378-
}
379-
});
380-
TyKind::Path(qself, fld.fold_path(path))
377+
let (qself, path) = fld.fold_qpath(qself, path);
378+
TyKind::Path(qself, path)
381379
}
382380
TyKind::Array(ty, length) => {
383381
TyKind::Array(fld.fold_ty(ty), fld.fold_anon_const(length))
@@ -442,6 +440,19 @@ pub fn noop_fold_path<T: Folder>(Path { segments, span }: Path, fld: &mut T) ->
442440
}
443441
}
444442

443+
pub fn noop_fold_qpath<T: Folder>(qself: Option<QSelf>,
444+
path: Path,
445+
fld: &mut T) -> (Option<QSelf>, Path) {
446+
let qself = qself.map(|QSelf { ty, path_span, position }| {
447+
QSelf {
448+
ty: fld.fold_ty(ty),
449+
path_span: fld.new_span(path_span),
450+
position,
451+
}
452+
});
453+
(qself, fld.fold_path(path))
454+
}
455+
445456
pub fn noop_fold_path_parameters<T: Folder>(path_parameters: PathParameters, fld: &mut T)
446457
-> PathParameters
447458
{
@@ -1097,15 +1108,9 @@ pub fn noop_fold_pat<T: Folder>(p: P<Pat>, folder: &mut T) -> P<Pat> {
10971108
PatKind::TupleStruct(folder.fold_path(pth),
10981109
pats.move_map(|x| folder.fold_pat(x)), ddpos)
10991110
}
1100-
PatKind::Path(opt_qself, pth) => {
1101-
let opt_qself = opt_qself.map(|qself| {
1102-
QSelf {
1103-
ty: folder.fold_ty(qself.ty),
1104-
path_span: folder.new_span(qself.path_span),
1105-
position: qself.position,
1106-
}
1107-
});
1108-
PatKind::Path(opt_qself, folder.fold_path(pth))
1111+
PatKind::Path(qself, pth) => {
1112+
let (qself, pth) = folder.fold_qpath(qself, pth);
1113+
PatKind::Path(qself, pth)
11091114
}
11101115
PatKind::Struct(pth, fields, etc) => {
11111116
let pth = folder.fold_path(pth);
@@ -1267,14 +1272,8 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span, attrs}: Expr, folder: &mu
12671272
lim)
12681273
}
12691274
ExprKind::Path(qself, path) => {
1270-
let qself = qself.map(|QSelf { ty, path_span, position }| {
1271-
QSelf {
1272-
ty: folder.fold_ty(ty),
1273-
path_span: folder.new_span(path_span),
1274-
position,
1275-
}
1276-
});
1277-
ExprKind::Path(qself, folder.fold_path(path))
1275+
let (qself, path) = folder.fold_qpath(qself, path);
1276+
ExprKind::Path(qself, path)
12781277
}
12791278
ExprKind::Break(opt_label, opt_expr) => {
12801279
ExprKind::Break(opt_label.map(|label| folder.fold_label(label)),

0 commit comments

Comments
 (0)