1
1
use std:: iter;
2
2
3
3
use rustc_ast:: util:: { classify, parser} ;
4
- use rustc_ast:: { self as ast, ExprKind , HasAttrs as _, StmtKind } ;
4
+ use rustc_ast:: { self as ast, ExprKind , FnRetTy , HasAttrs as _, StmtKind } ;
5
5
use rustc_attr_data_structures:: { AttributeKind , find_attr} ;
6
6
use rustc_data_structures:: fx:: FxHashMap ;
7
7
use rustc_errors:: { MultiSpan , pluralize} ;
@@ -599,6 +599,7 @@ enum UnusedDelimsCtx {
599
599
AnonConst ,
600
600
MatchArmExpr ,
601
601
IndexExpr ,
602
+ ClosureBody ,
602
603
}
603
604
604
605
impl From < UnusedDelimsCtx > for & ' static str {
@@ -620,6 +621,7 @@ impl From<UnusedDelimsCtx> for &'static str {
620
621
UnusedDelimsCtx :: ArrayLenExpr | UnusedDelimsCtx :: AnonConst => "const expression" ,
621
622
UnusedDelimsCtx :: MatchArmExpr => "match arm expression" ,
622
623
UnusedDelimsCtx :: IndexExpr => "index expression" ,
624
+ UnusedDelimsCtx :: ClosureBody => "closure body" ,
623
625
}
624
626
}
625
627
}
@@ -919,6 +921,11 @@ trait UnusedDelimLint {
919
921
let ( args_to_check, ctx) = match * call_or_other {
920
922
Call ( _, ref args) => ( & args[ ..] , UnusedDelimsCtx :: FunctionArg ) ,
921
923
MethodCall ( ref call) => ( & call. args [ ..] , UnusedDelimsCtx :: MethodArg ) ,
924
+ Closure ( ref closure)
925
+ if matches ! ( closure. fn_decl. output, FnRetTy :: Default ( _) ) =>
926
+ {
927
+ ( & [ closure. body . clone ( ) ] [ ..] , UnusedDelimsCtx :: ClosureBody )
928
+ }
922
929
// actual catch-all arm
923
930
_ => {
924
931
return ;
@@ -1508,6 +1515,7 @@ impl UnusedDelimLint for UnusedBraces {
1508
1515
&& ( ctx != UnusedDelimsCtx :: AnonConst
1509
1516
|| ( matches ! ( expr. kind, ast:: ExprKind :: Lit ( _) )
1510
1517
&& !expr. span . from_expansion ( ) ) )
1518
+ && ctx != UnusedDelimsCtx :: ClosureBody
1511
1519
&& !cx. sess ( ) . source_map ( ) . is_multiline ( value. span )
1512
1520
&& value. attrs . is_empty ( )
1513
1521
&& !value. span . from_expansion ( )
0 commit comments