11use std:: iter;
22
33use 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 } ;
55use rustc_errors:: { MultiSpan , pluralize} ;
66use rustc_hir:: def:: { DefKind , Res } ;
77use rustc_hir:: def_id:: DefId ;
@@ -592,6 +592,7 @@ enum UnusedDelimsCtx {
592592 AnonConst ,
593593 MatchArmExpr ,
594594 IndexExpr ,
595+ ClosureBody ,
595596}
596597
597598impl From < UnusedDelimsCtx > for & ' static str {
@@ -613,6 +614,7 @@ impl From<UnusedDelimsCtx> for &'static str {
613614 UnusedDelimsCtx :: ArrayLenExpr | UnusedDelimsCtx :: AnonConst => "const expression" ,
614615 UnusedDelimsCtx :: MatchArmExpr => "match arm expression" ,
615616 UnusedDelimsCtx :: IndexExpr => "index expression" ,
617+ UnusedDelimsCtx :: ClosureBody => "closure body" ,
616618 }
617619 }
618620}
@@ -912,6 +914,11 @@ trait UnusedDelimLint {
912914 let ( args_to_check, ctx) = match * call_or_other {
913915 Call ( _, ref args) => ( & args[ ..] , UnusedDelimsCtx :: FunctionArg ) ,
914916 MethodCall ( ref call) => ( & call. args [ ..] , UnusedDelimsCtx :: MethodArg ) ,
917+ Closure ( ref closure)
918+ if matches ! ( closure. fn_decl. output, FnRetTy :: Default ( _) ) =>
919+ {
920+ ( & [ closure. body . clone ( ) ] [ ..] , UnusedDelimsCtx :: ClosureBody )
921+ }
915922 // actual catch-all arm
916923 _ => {
917924 return ;
@@ -1395,6 +1402,7 @@ impl UnusedDelimLint for UnusedBraces {
13951402 && ( ctx != UnusedDelimsCtx :: AnonConst
13961403 || ( matches ! ( expr. kind, ast:: ExprKind :: Lit ( _) )
13971404 && !expr. span . from_expansion ( ) ) )
1405+ && ctx != UnusedDelimsCtx :: ClosureBody
13981406 && !cx. sess ( ) . source_map ( ) . is_multiline ( value. span )
13991407 && value. attrs . is_empty ( )
14001408 && !value. span . from_expansion ( )
0 commit comments