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_attr_data_structures:: { AttributeKind , find_attr} ;
66use rustc_errors:: { MultiSpan , pluralize} ;
77use rustc_hir:: def:: { DefKind , Res } ;
@@ -595,6 +595,7 @@ enum UnusedDelimsCtx {
595595 AnonConst ,
596596 MatchArmExpr ,
597597 IndexExpr ,
598+ ClosureBody ,
598599}
599600
600601impl From < UnusedDelimsCtx > for & ' static str {
@@ -616,6 +617,7 @@ impl From<UnusedDelimsCtx> for &'static str {
616617 UnusedDelimsCtx :: ArrayLenExpr | UnusedDelimsCtx :: AnonConst => "const expression" ,
617618 UnusedDelimsCtx :: MatchArmExpr => "match arm expression" ,
618619 UnusedDelimsCtx :: IndexExpr => "index expression" ,
620+ UnusedDelimsCtx :: ClosureBody => "closure body" ,
619621 }
620622 }
621623}
@@ -915,6 +917,11 @@ trait UnusedDelimLint {
915917 let ( args_to_check, ctx) = match * call_or_other {
916918 Call ( _, ref args) => ( & args[ ..] , UnusedDelimsCtx :: FunctionArg ) ,
917919 MethodCall ( ref call) => ( & call. args [ ..] , UnusedDelimsCtx :: MethodArg ) ,
920+ Closure ( ref closure)
921+ if matches ! ( closure. fn_decl. output, FnRetTy :: Default ( _) ) =>
922+ {
923+ ( & [ closure. body . clone ( ) ] [ ..] , UnusedDelimsCtx :: ClosureBody )
924+ }
918925 // actual catch-all arm
919926 _ => {
920927 return ;
@@ -1398,6 +1405,7 @@ impl UnusedDelimLint for UnusedBraces {
13981405 && ( ctx != UnusedDelimsCtx :: AnonConst
13991406 || ( matches ! ( expr. kind, ast:: ExprKind :: Lit ( _) )
14001407 && !expr. span . from_expansion ( ) ) )
1408+ && ctx != UnusedDelimsCtx :: ClosureBody
14011409 && !cx. sess ( ) . source_map ( ) . is_multiline ( value. span )
14021410 && value. attrs . is_empty ( )
14031411 && !value. span . from_expansion ( )
0 commit comments