Skip to content

Commit 5892f87

Browse files
authored
Unrolled build for rust-lang#132956
Rollup merge of rust-lang#132956 - maxcabrajac:coroutine_kind, r=petrochenkov Add visit_coroutine_kind to ast::Visitor r? ``@petrochenkov`` related to rust-lang#128974
2 parents 917a50a + a7ac8bf commit 5892f87

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

compiler/rustc_ast/src/visit.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ pub trait Visitor<'ast>: Sized {
268268
fn visit_fn_ret_ty(&mut self, ret_ty: &'ast FnRetTy) -> Self::Result {
269269
walk_fn_ret_ty(self, ret_ty)
270270
}
271-
fn visit_fn_header(&mut self, _header: &'ast FnHeader) -> Self::Result {
272-
Self::Result::output()
271+
fn visit_fn_header(&mut self, header: &'ast FnHeader) -> Self::Result {
272+
walk_fn_header(self, header)
273273
}
274274
fn visit_expr_field(&mut self, f: &'ast ExprField) -> Self::Result {
275275
walk_expr_field(self, f)
@@ -292,6 +292,9 @@ pub trait Visitor<'ast>: Sized {
292292
fn visit_capture_by(&mut self, _capture_by: &'ast CaptureBy) -> Self::Result {
293293
Self::Result::output()
294294
}
295+
fn visit_coroutine_kind(&mut self, _coroutine_kind: &'ast CoroutineKind) -> Self::Result {
296+
Self::Result::output()
297+
}
295298
}
296299

297300
pub fn walk_crate<'a, V: Visitor<'a>>(visitor: &mut V, krate: &'a Crate) -> V::Result {
@@ -813,6 +816,12 @@ pub fn walk_fn_ret_ty<'a, V: Visitor<'a>>(visitor: &mut V, ret_ty: &'a FnRetTy)
813816
V::Result::output()
814817
}
815818

819+
pub fn walk_fn_header<'a, V: Visitor<'a>>(visitor: &mut V, fn_header: &'a FnHeader) -> V::Result {
820+
let FnHeader { safety: _, coroutine_kind, constness: _, ext: _ } = fn_header;
821+
visit_opt!(visitor, visit_coroutine_kind, coroutine_kind.as_ref());
822+
V::Result::output()
823+
}
824+
816825
pub fn walk_fn_decl<'a, V: Visitor<'a>>(
817826
visitor: &mut V,
818827
FnDecl { inputs, output }: &'a FnDecl,
@@ -830,8 +839,9 @@ pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) -> V::Resu
830839
try_visit!(walk_fn_decl(visitor, decl));
831840
visit_opt!(visitor, visit_block, body);
832841
}
833-
FnKind::Closure(binder, _coroutine_kind, decl, body) => {
842+
FnKind::Closure(binder, coroutine_kind, decl, body) => {
834843
try_visit!(visitor.visit_closure_binder(binder));
844+
visit_opt!(visitor, visit_coroutine_kind, coroutine_kind.as_ref());
835845
try_visit!(walk_fn_decl(visitor, decl));
836846
try_visit!(visitor.visit_expr(body));
837847
}

compiler/rustc_lint/src/early.rs

+4-19
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ impl<'a, T: EarlyLintPass> EarlyContextAndPass<'a, T> {
6868
}
6969

7070
impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T> {
71+
fn visit_coroutine_kind(&mut self, coroutine_kind: &'a ast::CoroutineKind) -> Self::Result {
72+
self.check_id(coroutine_kind.closure_id());
73+
}
74+
7175
fn visit_param(&mut self, param: &'a ast::Param) {
7276
self.with_lint_attrs(param.id, &param.attrs, |cx| {
7377
lint_callback!(cx, check_param, param);
@@ -111,17 +115,6 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
111115
self.with_lint_attrs(e.id, &e.attrs, |cx| {
112116
lint_callback!(cx, check_expr, e);
113117
ast_visit::walk_expr(cx, e);
114-
// Explicitly check for lints associated with 'closure_id', since
115-
// it does not have a corresponding AST node
116-
match e.kind {
117-
ast::ExprKind::Closure(box ast::Closure {
118-
coroutine_kind: Some(coroutine_kind),
119-
..
120-
}) => {
121-
cx.check_id(coroutine_kind.closure_id());
122-
}
123-
_ => {}
124-
}
125118
lint_callback!(cx, check_expr_post, e);
126119
})
127120
}
@@ -156,14 +149,6 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
156149
lint_callback!(self, check_fn, fk, span, id);
157150
self.check_id(id);
158151
ast_visit::walk_fn(self, fk);
159-
160-
// Explicitly check for lints associated with 'closure_id', since
161-
// it does not have a corresponding AST node
162-
if let ast_visit::FnKind::Fn(_, _, sig, _, _, _) = fk {
163-
if let Some(coroutine_kind) = sig.header.coroutine_kind {
164-
self.check_id(coroutine_kind.closure_id());
165-
}
166-
}
167152
}
168153

169154
fn visit_variant_data(&mut self, s: &'a ast::VariantData) {

0 commit comments

Comments
 (0)