1+ use  rustc_hir:: * ; 
2+ use  rustc_lint:: { LateContext ,  LateLintPass } ; 
3+ use  rustc_session:: declare_lint_pass; 
4+ 
5+ use  clippy_utils:: diagnostics:: span_lint_and_sugg; 
6+ use  clippy_utils:: source:: snippet; 
7+ use  clippy_utils:: ty:: implements_trait; 
8+ use  rustc_errors:: Applicability ; 
9+ use  rustc_middle:: ty; 
10+ use  rustc_span:: sym; 
11+ use  clippy_utils:: ty:: is_type_diagnostic_item; 
12+ 
13+ declare_clippy_lint !  { 
14+     /// ### What it does 
15+ /// 
16+ /// ### Why restrict this? 
17+ /// 
18+ /// ### Example 
19+ /// ```no_run 
20+ /// // example code where clippy issues a warning 
21+ /// ``` 
22+ /// Use instead: 
23+ /// ```no_run 
24+ /// // example code which does not raise clippy warning 
25+ /// ``` 
26+ [ clippy:: version = "1.91.0" ] 
27+     pub  DISCARDED_FUTURE , 
28+     restriction, 
29+     "default lint description" 
30+ } 
31+ declare_lint_pass ! ( DiscardedFuture  => [ DISCARDED_FUTURE ] ) ; 
32+ 
33+ impl < ' tcx >  LateLintPass < ' tcx >  for  DiscardedFuture  { 
34+     fn  check_stmt ( & mut  self ,  cx :  & LateContext < ' tcx > ,  stmt :  & ' tcx  Stmt < ' tcx > )  { 
35+         if  let  StmtKind :: Let ( let_stmt)  = stmt. kind 
36+             && let  PatKind :: Wild  = let_stmt. pat . kind 
37+             && let  Some ( expr)  = let_stmt. init 
38+             && let  ty = cx. typeck_results ( ) . expr_ty ( expr) 
39+             && is_type_diagnostic_item ( cx,  ty,  sym:: Result ) 
40+             && let  ty:: Adt ( _,  substs)  = ty. kind ( ) 
41+             && let  Some ( inner_ty)  = substs[ 0 ] . as_type ( ) 
42+             && let  Some ( future_trait_def_id)  = cx. tcx . lang_items ( ) . future_trait ( ) 
43+             && implements_trait ( cx,  inner_ty,  future_trait_def_id,  & [ ] ) 
44+         { 
45+             span_lint_and_sugg ( 
46+                 cx, 
47+                 DISCARDED_FUTURE , 
48+                 expr. span , 
49+                 format ! ( "Discarding a Result<Future>: did you mean to call .await on this first?" ) , 
50+                 "consider `.await` on it" , 
51+                 format ! ( "{}.await" ,  snippet( cx,  expr. span,  ".." ) ) , 
52+                 Applicability :: MaybeIncorrect , 
53+             ) ; 
54+         } 
55+     } 
56+ } 
0 commit comments