@@ -54,29 +54,26 @@ impl_lint_pass!(LargeFuture => [LARGE_FUTURES]);
5454
5555impl < ' tcx > LateLintPass < ' tcx > for LargeFuture {
5656 fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' tcx > ) {
57- if matches ! ( expr. span. ctxt( ) . outer_expn_data( ) . kind, rustc_span:: ExpnKind :: Macro ( ..) ) {
58- return ;
59- }
60- if let ExprKind :: Match ( expr, _, MatchSource :: AwaitDesugar ) = expr. kind {
61- if let ExprKind :: Call ( func, [ expr, ..] ) = expr. kind
62- && let ExprKind :: Path ( QPath :: LangItem ( LangItem :: IntoFutureIntoFuture , ..) ) = func. kind
63- && let ty = cx. typeck_results ( ) . expr_ty ( expr)
64- && let Some ( future_trait_def_id) = cx. tcx . lang_items ( ) . future_trait ( )
65- && implements_trait ( cx, ty, future_trait_def_id, & [ ] )
66- && let Ok ( layout) = cx. tcx . layout_of ( cx. param_env . and ( ty) )
67- && let size = layout. layout . size ( )
68- && size >= Size :: from_bytes ( self . future_size_threshold )
69- {
70- span_lint_and_sugg (
71- cx,
72- LARGE_FUTURES ,
73- expr. span ,
74- format ! ( "large future with a size of {} bytes" , size. bytes( ) ) ,
75- "consider `Box::pin` on it" ,
76- format ! ( "Box::pin({})" , snippet( cx, expr. span, ".." ) ) ,
77- Applicability :: Unspecified ,
78- ) ;
79- }
57+ if let ExprKind :: Match ( scrutinee, _, MatchSource :: AwaitDesugar ) = expr. kind
58+ && let ExprKind :: Call ( func, [ arg, ..] ) = scrutinee. kind
59+ && let ExprKind :: Path ( QPath :: LangItem ( LangItem :: IntoFutureIntoFuture , ..) ) = func. kind
60+ && !expr. span . from_expansion ( )
61+ && let ty = cx. typeck_results ( ) . expr_ty ( arg)
62+ && let Some ( future_trait_def_id) = cx. tcx . lang_items ( ) . future_trait ( )
63+ && implements_trait ( cx, ty, future_trait_def_id, & [ ] )
64+ && let Ok ( layout) = cx. tcx . layout_of ( cx. param_env . and ( ty) )
65+ && let size = layout. layout . size ( )
66+ && size >= Size :: from_bytes ( self . future_size_threshold )
67+ {
68+ span_lint_and_sugg (
69+ cx,
70+ LARGE_FUTURES ,
71+ arg. span ,
72+ format ! ( "large future with a size of {} bytes" , size. bytes( ) ) ,
73+ "consider `Box::pin` on it" ,
74+ format ! ( "Box::pin({})" , snippet( cx, arg. span, ".." ) ) ,
75+ Applicability :: Unspecified ,
76+ ) ;
8077 }
8178 }
8279}
0 commit comments