mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 05:33:27 +00:00
large_futures
: Delay macro check
This commit is contained in:
parent
430c02cbd0
commit
c3dd028d3e
1 changed files with 20 additions and 23 deletions
|
@ -54,29 +54,26 @@ impl_lint_pass!(LargeFuture => [LARGE_FUTURES]);
|
||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for LargeFuture {
|
impl<'tcx> LateLintPass<'tcx> for LargeFuture {
|
||||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
|
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
|
||||||
if matches!(expr.span.ctxt().outer_expn_data().kind, rustc_span::ExpnKind::Macro(..)) {
|
if let ExprKind::Match(scrutinee, _, MatchSource::AwaitDesugar) = expr.kind
|
||||||
return;
|
&& let ExprKind::Call(func, [arg, ..]) = scrutinee.kind
|
||||||
}
|
&& let ExprKind::Path(QPath::LangItem(LangItem::IntoFutureIntoFuture, ..)) = func.kind
|
||||||
if let ExprKind::Match(expr, _, MatchSource::AwaitDesugar) = expr.kind {
|
&& !expr.span.from_expansion()
|
||||||
if let ExprKind::Call(func, [expr, ..]) = expr.kind
|
&& let ty = cx.typeck_results().expr_ty(arg)
|
||||||
&& let ExprKind::Path(QPath::LangItem(LangItem::IntoFutureIntoFuture, ..)) = func.kind
|
&& let Some(future_trait_def_id) = cx.tcx.lang_items().future_trait()
|
||||||
&& let ty = cx.typeck_results().expr_ty(expr)
|
&& implements_trait(cx, ty, future_trait_def_id, &[])
|
||||||
&& let Some(future_trait_def_id) = cx.tcx.lang_items().future_trait()
|
&& let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(ty))
|
||||||
&& implements_trait(cx, ty, future_trait_def_id, &[])
|
&& let size = layout.layout.size()
|
||||||
&& let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(ty))
|
&& size >= Size::from_bytes(self.future_size_threshold)
|
||||||
&& let size = layout.layout.size()
|
{
|
||||||
&& size >= Size::from_bytes(self.future_size_threshold)
|
span_lint_and_sugg(
|
||||||
{
|
cx,
|
||||||
span_lint_and_sugg(
|
LARGE_FUTURES,
|
||||||
cx,
|
arg.span,
|
||||||
LARGE_FUTURES,
|
format!("large future with a size of {} bytes", size.bytes()),
|
||||||
expr.span,
|
"consider `Box::pin` on it",
|
||||||
format!("large future with a size of {} bytes", size.bytes()),
|
format!("Box::pin({})", snippet(cx, arg.span, "..")),
|
||||||
"consider `Box::pin` on it",
|
Applicability::Unspecified,
|
||||||
format!("Box::pin({})", snippet(cx, expr.span, "..")),
|
);
|
||||||
Applicability::Unspecified,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue