mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 23:24:24 +00:00
Rollup merge of #117175 - oli-obk:gen_fn_split, r=compiler-errors
Rename AsyncCoroutineKind to CoroutineSource pulled out of https://github.com/rust-lang/rust/pull/116447 Also refactors the printing infra of `CoroutineSource` to be ready for easily extending it with a `Gen` variant for `gen` blocks
This commit is contained in:
commit
5f19fac9e7
5 changed files with 10 additions and 10 deletions
|
@ -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::{AsyncCoroutineKind, Body, BodyId, CoroutineKind, ExprKind, QPath};
|
use rustc_hir::{CoroutineSource, Body, BodyId, CoroutineKind, ExprKind, 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,7 +45,7 @@ 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 AsyncCoroutineKind::{Block, Closure};
|
use CoroutineSource::{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(CoroutineKind::Async(Block | Closure)) = body.coroutine_kind {
|
if let Some(CoroutineKind::Async(Block | Closure)) = body.coroutine_kind {
|
||||||
|
|
|
@ -2,7 +2,7 @@ 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::{AsyncCoroutineKind, Body, CoroutineKind};
|
use rustc_hir::{CoroutineSource, Body, CoroutineKind};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::mir::CoroutineLayout;
|
use rustc_middle::mir::CoroutineLayout;
|
||||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||||
|
@ -195,7 +195,7 @@ impl LateLintPass<'_> for AwaitHolding {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) {
|
fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) {
|
||||||
use AsyncCoroutineKind::{Block, Closure, Fn};
|
use CoroutineSource::{Block, Closure, Fn};
|
||||||
if let Some(CoroutineKind::Async(Block | Closure | Fn)) = body.coroutine_kind {
|
if let Some(CoroutineKind::Async(Block | Closure | Fn)) = body.coroutine_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(coroutine_layout) = cx.tcx.mir_coroutine_witnesses(def_id) {
|
if let Some(coroutine_layout) = cx.tcx.mir_coroutine_witnesses(def_id) {
|
||||||
|
|
|
@ -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::{
|
||||||
AsyncCoroutineKind, Block, Body, Closure, CoroutineKind, Expr, ExprKind, FnDecl, FnRetTy, GenericArg, GenericBound,
|
CoroutineSource, Block, Body, Closure, CoroutineKind, Expr, ExprKind, FnDecl, FnRetTy, 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.coroutine_kind == Some(CoroutineKind::Async(AsyncCoroutineKind::Block));
|
if closure_body.coroutine_kind == Some(CoroutineKind::Async(CoroutineSource::Block));
|
||||||
then {
|
then {
|
||||||
return Some(closure_body);
|
return Some(closure_body);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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::{AsyncCoroutineKind, Block, Body, CoroutineKind, Expr, ExprKind, LangItem, MatchSource, QPath};
|
use rustc_hir::{CoroutineSource, Block, Body, CoroutineKind, Expr, ExprKind, 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(CoroutineKind::Async(AsyncCoroutineKind::Fn)) = body.coroutine_kind {
|
if let Some(CoroutineKind::Async(CoroutineSource::Fn)) = body.coroutine_kind {
|
||||||
if let ExprKind::Block(
|
if let ExprKind::Block(
|
||||||
Block {
|
Block {
|
||||||
expr:
|
expr:
|
||||||
|
|
|
@ -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::{AsyncCoroutineKind, Closure, CoroutineKind, Expr, ExprKind, MatchSource};
|
use rustc_hir::{CoroutineSource, Closure, CoroutineKind, Expr, ExprKind, 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.coroutine_kind, Some(CoroutineKind::Async(AsyncCoroutineKind::Block)))
|
matches!(body.coroutine_kind, Some(CoroutineKind::Async(CoroutineSource::Block)))
|
||||||
{
|
{
|
||||||
cx
|
cx
|
||||||
.typeck_results()
|
.typeck_results()
|
||||||
|
|
Loading…
Reference in a new issue