1
Fork 0

s/Generator/Coroutine/

This commit is contained in:
Oli Scherer 2023-10-19 16:06:43 +00:00
parent 214b4d91bd
commit 868e513935
10 changed files with 20 additions and 20 deletions

View file

@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_hir_and_then;
use clippy_utils::source::snippet; use clippy_utils::source::snippet;
use clippy_utils::ty::implements_trait; use clippy_utils::ty::implements_trait;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{AsyncGeneratorKind, Body, BodyId, ExprKind, GeneratorKind, QPath}; use rustc_hir::{AsyncCoroutineKind, Body, BodyId, ExprKind, CoroutineKind, QPath};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_session::{declare_lint_pass, declare_tool_lint};
@ -45,10 +45,10 @@ declare_lint_pass!(AsyncYieldsAsync => [ASYNC_YIELDS_ASYNC]);
impl<'tcx> LateLintPass<'tcx> for AsyncYieldsAsync { impl<'tcx> LateLintPass<'tcx> for AsyncYieldsAsync {
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) { fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) {
use AsyncGeneratorKind::{Block, Closure}; use AsyncCoroutineKind::{Block, Closure};
// For functions, with explicitly defined types, don't warn. // For functions, with explicitly defined types, don't warn.
// XXXkhuey maybe we should? // XXXkhuey maybe we should?
if let Some(GeneratorKind::Async(Block | Closure)) = body.generator_kind { if let Some(CoroutineKind::Async(Block | Closure)) = body.generator_kind {
if let Some(future_trait_def_id) = cx.tcx.lang_items().future_trait() { if let Some(future_trait_def_id) = cx.tcx.lang_items().future_trait() {
let body_id = BodyId { let body_id = BodyId {
hir_id: body.value.hir_id, hir_id: body.value.hir_id,

View file

@ -2,9 +2,9 @@ use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::{match_def_path, paths}; use clippy_utils::{match_def_path, paths};
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::{AsyncGeneratorKind, Body, GeneratorKind}; use rustc_hir::{AsyncCoroutineKind, Body, CoroutineKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::mir::GeneratorLayout; use rustc_middle::mir::CoroutineLayout;
use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::{sym, Span}; use rustc_span::{sym, Span};
@ -195,8 +195,8 @@ impl LateLintPass<'_> for AwaitHolding {
} }
fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) { fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) {
use AsyncGeneratorKind::{Block, Closure, Fn}; use AsyncCoroutineKind::{Block, Closure, Fn};
if let Some(GeneratorKind::Async(Block | Closure | Fn)) = body.generator_kind { if let Some(CoroutineKind::Async(Block | Closure | Fn)) = body.generator_kind {
let def_id = cx.tcx.hir().body_owner_def_id(body.id()); let def_id = cx.tcx.hir().body_owner_def_id(body.id());
if let Some(generator_layout) = cx.tcx.mir_generator_witnesses(def_id) { if let Some(generator_layout) = cx.tcx.mir_generator_witnesses(def_id) {
self.check_interior_types(cx, generator_layout); self.check_interior_types(cx, generator_layout);
@ -206,7 +206,7 @@ impl LateLintPass<'_> for AwaitHolding {
} }
impl AwaitHolding { impl AwaitHolding {
fn check_interior_types(&self, cx: &LateContext<'_>, generator: &GeneratorLayout<'_>) { fn check_interior_types(&self, cx: &LateContext<'_>, generator: &CoroutineLayout<'_>) {
for (ty_index, ty_cause) in generator.field_tys.iter_enumerated() { for (ty_index, ty_cause) in generator.field_tys.iter_enumerated() {
if let rustc_middle::ty::Adt(adt, _) = ty_cause.ty.kind() { if let rustc_middle::ty::Adt(adt, _) = ty_cause.ty.kind() {
let await_points = || { let await_points = || {

View file

@ -842,8 +842,8 @@ impl TyCoercionStability {
| ty::Adt(..) | ty::Adt(..)
| ty::Foreign(_) | ty::Foreign(_)
| ty::FnDef(..) | ty::FnDef(..)
| ty::Generator(..) | ty::Coroutine(..)
| ty::GeneratorWitness(..) | ty::CoroutineWitness(..)
| ty::Closure(..) | ty::Closure(..)
| ty::Never | ty::Never
| ty::Tuple(_) | ty::Tuple(_)

View file

@ -436,7 +436,7 @@ fn lint_for_missing_headers(
let body = cx.tcx.hir().body(body_id); let body = cx.tcx.hir().body(body_id);
let ret_ty = typeck.expr_ty(body.value); let ret_ty = typeck.expr_ty(body.value);
if implements_trait(cx, ret_ty, future, &[]); if implements_trait(cx, ret_ty, future, &[]);
if let ty::Generator(_, subs, _) = ret_ty.kind(); if let ty::Coroutine(_, subs, _) = ret_ty.kind();
if is_type_diagnostic_item(cx, subs.as_generator().return_ty(), sym::Result); if is_type_diagnostic_item(cx, subs.as_generator().return_ty(), sym::Result);
then { then {
span_lint( span_lint(

View file

@ -12,7 +12,7 @@ declare_clippy_lint! {
/// It checks for the size of a `Future` created by `async fn` or `async {}`. /// It checks for the size of a `Future` created by `async fn` or `async {}`.
/// ///
/// ### Why is this bad? /// ### Why is this bad?
/// Due to the current [unideal implementation](https://github.com/rust-lang/rust/issues/69826) of `Generator`, /// Due to the current [unideal implementation](https://github.com/rust-lang/rust/issues/69826) of `Coroutine`,
/// large size of a `Future` may cause stack overflows. /// large size of a `Future` may cause stack overflows.
/// ///
/// ### Example /// ### Example

View file

@ -4,7 +4,7 @@ use if_chain::if_chain;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::intravisit::FnKind; use rustc_hir::intravisit::FnKind;
use rustc_hir::{ use rustc_hir::{
AsyncGeneratorKind, Block, Body, Closure, Expr, ExprKind, FnDecl, FnRetTy, GeneratorKind, GenericArg, GenericBound, AsyncCoroutineKind, Block, Body, Closure, Expr, ExprKind, FnDecl, FnRetTy, CoroutineKind, GenericArg, GenericBound,
ImplItem, Item, ItemKind, LifetimeName, Node, Term, TraitRef, Ty, TyKind, TypeBindingKind, ImplItem, Item, ItemKind, LifetimeName, Node, Term, TraitRef, Ty, TyKind, TypeBindingKind,
}; };
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
@ -188,7 +188,7 @@ fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>)
.. ..
} = block_expr; } = block_expr;
let closure_body = cx.tcx.hir().body(body); let closure_body = cx.tcx.hir().body(body);
if closure_body.generator_kind == Some(GeneratorKind::Async(AsyncGeneratorKind::Block)); if closure_body.generator_kind == Some(CoroutineKind::Async(AsyncCoroutineKind::Block));
then { then {
return Some(closure_body); return Some(closure_body);
} }

View file

@ -4,7 +4,7 @@ use clippy_utils::source::snippet;
use if_chain::if_chain; use if_chain::if_chain;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::{AsyncGeneratorKind, Block, Body, Expr, ExprKind, GeneratorKind, LangItem, MatchSource, QPath}; use rustc_hir::{AsyncCoroutineKind, Block, Body, Expr, ExprKind, CoroutineKind, LangItem, MatchSource, QPath};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_session::{declare_lint_pass, declare_tool_lint};
@ -87,7 +87,7 @@ impl LateLintPass<'_> for NeedlessQuestionMark {
} }
fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) { fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) {
if let Some(GeneratorKind::Async(AsyncGeneratorKind::Fn)) = body.generator_kind { if let Some(CoroutineKind::Async(AsyncCoroutineKind::Fn)) = body.generator_kind {
if let ExprKind::Block( if let ExprKind::Block(
Block { Block {
expr: expr:

View file

@ -5,7 +5,7 @@ use clippy_utils::peel_blocks;
use clippy_utils::source::{snippet, walk_span_to_context}; use clippy_utils::source::{snippet, walk_span_to_context};
use clippy_utils::visitors::for_each_expr; use clippy_utils::visitors::for_each_expr;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{AsyncGeneratorKind, Closure, Expr, ExprKind, GeneratorKind, MatchSource}; use rustc_hir::{AsyncCoroutineKind, Closure, Expr, ExprKind, CoroutineKind, MatchSource};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro; use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::UpvarCapture; use rustc_middle::ty::UpvarCapture;
@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantAsyncBlock {
fn desugar_async_block<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> { fn desugar_async_block<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> {
if let ExprKind::Closure(Closure { body, def_id, .. }) = expr.kind && if let ExprKind::Closure(Closure { body, def_id, .. }) = expr.kind &&
let body = cx.tcx.hir().body(*body) && let body = cx.tcx.hir().body(*body) &&
matches!(body.generator_kind, Some(GeneratorKind::Async(AsyncGeneratorKind::Block))) matches!(body.generator_kind, Some(CoroutineKind::Async(AsyncCoroutineKind::Block)))
{ {
cx cx
.typeck_results() .typeck_results()

View file

@ -86,7 +86,7 @@ impl<'a, 'tcx> Visitor<'tcx> for AsyncFnVisitor<'a, 'tcx> {
} }
fn visit_body(&mut self, b: &'tcx Body<'tcx>) { fn visit_body(&mut self, b: &'tcx Body<'tcx>) {
let is_async_block = matches!(b.generator_kind, Some(rustc_hir::GeneratorKind::Async(_))); let is_async_block = matches!(b.generator_kind, Some(rustc_hir::CoroutineKind::Async(_)));
if is_async_block { if is_async_block {
self.async_depth += 1; self.async_depth += 1;

View file

@ -305,7 +305,7 @@ fn check_terminator<'tcx>(
Ok(()) Ok(())
}, },
TerminatorKind::SwitchInt { discr, targets: _ } => check_operand(tcx, discr, span, body), TerminatorKind::SwitchInt { discr, targets: _ } => check_operand(tcx, discr, span, body),
TerminatorKind::GeneratorDrop | TerminatorKind::Yield { .. } => { TerminatorKind::CoroutineDrop | TerminatorKind::Yield { .. } => {
Err((span, "const fn generators are unstable".into())) Err((span, "const fn generators are unstable".into()))
}, },
TerminatorKind::Call { TerminatorKind::Call {