From 49713c0c20840ea42ebf15398ef8aa217acaea46 Mon Sep 17 00:00:00 2001 From: maxcabrajac Date: Tue, 12 Nov 2024 13:44:46 -0300 Subject: [PATCH 1/3] Add visit_coroutine_kind --- compiler/rustc_ast/src/visit.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index 2f8115441de..ddcb0cef3d1 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -268,8 +268,8 @@ pub trait Visitor<'ast>: Sized { fn visit_fn_ret_ty(&mut self, ret_ty: &'ast FnRetTy) -> Self::Result { walk_fn_ret_ty(self, ret_ty) } - fn visit_fn_header(&mut self, _header: &'ast FnHeader) -> Self::Result { - Self::Result::output() + fn visit_fn_header(&mut self, header: &'ast FnHeader) -> Self::Result { + walk_fn_header(self, header) } fn visit_expr_field(&mut self, f: &'ast ExprField) -> Self::Result { walk_expr_field(self, f) @@ -292,6 +292,9 @@ pub trait Visitor<'ast>: Sized { fn visit_capture_by(&mut self, _capture_by: &'ast CaptureBy) -> Self::Result { Self::Result::output() } + fn visit_coroutine_kind(&mut self, _coroutine_kind: &'ast CoroutineKind) -> Self::Result { + Self::Result::output() + } } pub fn walk_crate<'a, V: Visitor<'a>>(visitor: &mut V, krate: &'a Crate) -> V::Result { @@ -817,6 +820,15 @@ pub fn walk_fn_ret_ty<'a, V: Visitor<'a>>(visitor: &mut V, ret_ty: &'a FnRetTy) V::Result::output() } +pub fn walk_fn_header<'a, V: Visitor<'a>>( + visitor: &mut V, + fn_header: &'a FnHeader +) -> V::Result { + let FnHeader { safety: _, coroutine_kind, constness: _, ext: _ } = fn_header; + visit_opt!(visitor, visit_coroutine_kind, coroutine_kind.as_ref()); + V::Result::output() +} + pub fn walk_fn_decl<'a, V: Visitor<'a>>( visitor: &mut V, FnDecl { inputs, output }: &'a FnDecl, @@ -834,8 +846,9 @@ pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) -> V::Resu try_visit!(walk_fn_decl(visitor, decl)); visit_opt!(visitor, visit_block, body); } - FnKind::Closure(binder, _coroutine_kind, decl, body) => { + FnKind::Closure(binder, coroutine_kind, decl, body) => { try_visit!(visitor.visit_closure_binder(binder)); + visit_opt!(visitor, visit_coroutine_kind, coroutine_kind.as_ref()); try_visit!(walk_fn_decl(visitor, decl)); try_visit!(visitor.visit_expr(body)); } From 71786ee619cf451599ac28e608393e214d9c2148 Mon Sep 17 00:00:00 2001 From: maxcabrajac Date: Tue, 12 Nov 2024 13:50:03 -0300 Subject: [PATCH 2/3] Change rustc_lint --- compiler/rustc_lint/src/early.rs | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_lint/src/early.rs b/compiler/rustc_lint/src/early.rs index acccff77a10..ef9b3dbd13b 100644 --- a/compiler/rustc_lint/src/early.rs +++ b/compiler/rustc_lint/src/early.rs @@ -68,6 +68,10 @@ impl<'a, T: EarlyLintPass> EarlyContextAndPass<'a, T> { } impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T> { + fn visit_coroutine_kind(&mut self, coroutine_kind: &'a ast::CoroutineKind) -> Self::Result { + self.check_id(coroutine_kind.closure_id()); + } + fn visit_param(&mut self, param: &'a ast::Param) { self.with_lint_attrs(param.id, ¶m.attrs, |cx| { lint_callback!(cx, check_param, param); @@ -111,17 +115,6 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T> self.with_lint_attrs(e.id, &e.attrs, |cx| { lint_callback!(cx, check_expr, e); ast_visit::walk_expr(cx, e); - // Explicitly check for lints associated with 'closure_id', since - // it does not have a corresponding AST node - match e.kind { - ast::ExprKind::Closure(box ast::Closure { - coroutine_kind: Some(coroutine_kind), - .. - }) => { - cx.check_id(coroutine_kind.closure_id()); - } - _ => {} - } lint_callback!(cx, check_expr_post, e); }) } @@ -156,14 +149,6 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T> lint_callback!(self, check_fn, fk, span, id); self.check_id(id); ast_visit::walk_fn(self, fk); - - // Explicitly check for lints associated with 'closure_id', since - // it does not have a corresponding AST node - if let ast_visit::FnKind::Fn(_, _, sig, _, _, _) = fk { - if let Some(coroutine_kind) = sig.header.coroutine_kind { - self.check_id(coroutine_kind.closure_id()); - } - } } fn visit_variant_data(&mut self, s: &'a ast::VariantData) { From a7ac8bfc22b441004bfb96311677ea807f3a5613 Mon Sep 17 00:00:00 2001 From: maxcabrajac Date: Tue, 12 Nov 2024 21:57:25 -0300 Subject: [PATCH 3/3] format --- compiler/rustc_ast/src/visit.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index ddcb0cef3d1..a4105009d86 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -820,10 +820,7 @@ pub fn walk_fn_ret_ty<'a, V: Visitor<'a>>(visitor: &mut V, ret_ty: &'a FnRetTy) V::Result::output() } -pub fn walk_fn_header<'a, V: Visitor<'a>>( - visitor: &mut V, - fn_header: &'a FnHeader -) -> V::Result { +pub fn walk_fn_header<'a, V: Visitor<'a>>(visitor: &mut V, fn_header: &'a FnHeader) -> V::Result { let FnHeader { safety: _, coroutine_kind, constness: _, ext: _ } = fn_header; visit_opt!(visitor, visit_coroutine_kind, coroutine_kind.as_ref()); V::Result::output()