Skip to content

Commit

Permalink
add fn visit_capture_by to MutVisitor and fix pprust-expr-roundtrip.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
dnbln committed Nov 4, 2023
1 parent df85b28 commit 54ce034
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ pub trait MutVisitor: Sized {
fn visit_format_args(&mut self, fmt: &mut FormatArgs) {
noop_visit_format_args(fmt, self)
}

fn visit_capture_by(&mut self, capture_by: &mut CaptureBy) {
noop_visit_capture_by(capture_by, self)
}
}

/// Use a map-style function (`FnOnce(T) -> T`) to overwrite a `&mut T`. Useful
Expand Down Expand Up @@ -1562,6 +1566,15 @@ pub fn noop_visit_vis<T: MutVisitor>(visibility: &mut Visibility, vis: &mut T) {
vis.visit_span(&mut visibility.span);
}

pub fn noop_visit_capture_by<T: MutVisitor>(capture_by: &mut CaptureBy, vis: &mut T) {
match capture_by {
CaptureBy::Ref => {}
CaptureBy::Value { move_kw } => {
vis.visit_span(move_kw);
}
}
}

/// Some value for the AST node that is valid but possibly meaningless.
pub trait DummyAstNode {
fn dummy() -> Self;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui-fulldeps/pprust-expr-roundtrip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) {
iter_exprs(depth - 1, &mut |e| {
g(ExprKind::Closure(Box::new(Closure {
binder: ClosureBinder::NotPresent,
capture_clause: CaptureBy::Value,
capture_clause: CaptureBy::Value { move_kw: DUMMY_SP },
constness: Const::No,
asyncness: Async::No,
movability: Movability::Movable,
Expand Down

0 comments on commit 54ce034

Please sign in to comment.