diff options
| author | Dinu Blanovschi <git@dnbln.dev> | 2023-11-04 20:39:15 +0100 |
|---|---|---|
| committer | Dinu Blanovschi <git@dnbln.dev> | 2023-11-04 20:39:15 +0100 |
| commit | df85b28b7261801e10867e15e7292df60f7a9bf7 (patch) | |
| tree | 4cf6afd565b4c0494893e5d4151e766caa82a5aa | |
| parent | a6b41aa6baa1eb9011732c341dadde4fc3c422d9 (diff) | |
| download | rust-df85b28b7261801e10867e15e7292df60f7a9bf7.tar.gz rust-df85b28b7261801e10867e15e7292df60f7a9bf7.zip | |
fixes for rustfmt + ast visitor
| -rw-r--r-- | compiler/rustc_ast/src/visit.rs | 6 | ||||
| -rw-r--r-- | src/tools/rustfmt/src/closures.rs | 2 | ||||
| -rw-r--r-- | src/tools/rustfmt/src/expr.rs | 2 |
3 files changed, 7 insertions, 3 deletions
diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index e091961a144..1caa39e2dd9 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -251,6 +251,9 @@ pub trait Visitor<'ast>: Sized { fn visit_inline_asm_sym(&mut self, sym: &'ast InlineAsmSym) { walk_inline_asm_sym(self, sym) } + fn visit_capture_by(&mut self, _capture_by: &'ast CaptureBy) { + // Nothing to do + } } #[macro_export] @@ -857,7 +860,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) { } ExprKind::Closure(box Closure { binder, - capture_clause: _, + capture_clause, asyncness: _, constness: _, movability: _, @@ -866,6 +869,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) { fn_decl_span: _, fn_arg_span: _, }) => { + visitor.visit_capture_by(capture_clause); visitor.visit_fn(FnKind::Closure(binder, fn_decl, body), expression.span, expression.id) } ExprKind::Block(block, opt_label) => { diff --git a/src/tools/rustfmt/src/closures.rs b/src/tools/rustfmt/src/closures.rs index 16b8ce7a916..8a4089a56f0 100644 --- a/src/tools/rustfmt/src/closures.rs +++ b/src/tools/rustfmt/src/closures.rs @@ -264,7 +264,7 @@ fn rewrite_closure_fn_decl( "" }; let is_async = if asyncness.is_async() { "async " } else { "" }; - let mover = if capture == ast::CaptureBy::Value { + let mover = if matches!(capture, ast::CaptureBy::Value { .. }) { "move " } else { "" diff --git a/src/tools/rustfmt/src/expr.rs b/src/tools/rustfmt/src/expr.rs index 8c2262fde81..fa941e6146a 100644 --- a/src/tools/rustfmt/src/expr.rs +++ b/src/tools/rustfmt/src/expr.rs @@ -368,7 +368,7 @@ pub(crate) fn format_expr( } } ast::ExprKind::Gen(capture_by, ref block, ref kind) => { - let mover = if capture_by == ast::CaptureBy::Value { + let mover = if matches!(capture_by, ast::CaptureBy::Value { .. }) { "move " } else { "" |
