@@ -2,7 +2,7 @@ use std::iter;
2
2
3
3
use rustc_ast as ast;
4
4
use rustc_ast:: util:: { classify, parser} ;
5
- use rustc_ast:: { ExprKind , StmtKind } ;
5
+ use rustc_ast:: { ExprKind , FnRetTy , StmtKind } ;
6
6
use rustc_errors:: { MultiSpan , pluralize} ;
7
7
use rustc_hir:: def:: { DefKind , Res } ;
8
8
use rustc_hir:: def_id:: DefId ;
@@ -593,6 +593,7 @@ enum UnusedDelimsCtx {
593
593
AnonConst ,
594
594
MatchArmExpr ,
595
595
IndexExpr ,
596
+ ClosureBody ,
596
597
}
597
598
598
599
impl From < UnusedDelimsCtx > for & ' static str {
@@ -614,6 +615,7 @@ impl From<UnusedDelimsCtx> for &'static str {
614
615
UnusedDelimsCtx :: ArrayLenExpr | UnusedDelimsCtx :: AnonConst => "const expression" ,
615
616
UnusedDelimsCtx :: MatchArmExpr => "match arm expression" ,
616
617
UnusedDelimsCtx :: IndexExpr => "index expression" ,
618
+ UnusedDelimsCtx :: ClosureBody => "closure body" ,
617
619
}
618
620
}
619
621
}
@@ -909,6 +911,11 @@ trait UnusedDelimLint {
909
911
let ( args_to_check, ctx) = match * call_or_other {
910
912
Call ( _, ref args) => ( & args[ ..] , UnusedDelimsCtx :: FunctionArg ) ,
911
913
MethodCall ( ref call) => ( & call. args [ ..] , UnusedDelimsCtx :: MethodArg ) ,
914
+ Closure ( ref closure)
915
+ if matches ! ( closure. fn_decl. output, FnRetTy :: Default ( _) ) =>
916
+ {
917
+ ( & [ closure. body . clone ( ) ] [ ..] , UnusedDelimsCtx :: ClosureBody )
918
+ }
912
919
// actual catch-all arm
913
920
_ => {
914
921
return ;
@@ -1392,6 +1399,7 @@ impl UnusedDelimLint for UnusedBraces {
1392
1399
&& ( ctx != UnusedDelimsCtx :: AnonConst
1393
1400
|| ( matches ! ( expr. kind, ast:: ExprKind :: Lit ( _) )
1394
1401
&& !expr. span . from_expansion ( ) ) )
1402
+ && ctx != UnusedDelimsCtx :: ClosureBody
1395
1403
&& !cx. sess ( ) . source_map ( ) . is_multiline ( value. span )
1396
1404
&& value. attrs . is_empty ( )
1397
1405
&& !value. span . from_expansion ( )
0 commit comments