@@ -2,7 +2,7 @@ use std::iter;
22
33use rustc_ast as ast;
44use rustc_ast:: util:: { classify, parser} ;
5- use rustc_ast:: { ExprKind , StmtKind } ;
5+ use rustc_ast:: { ExprKind , FnRetTy , StmtKind } ;
66use rustc_errors:: { MultiSpan , pluralize} ;
77use rustc_hir:: def:: { DefKind , Res } ;
88use rustc_hir:: def_id:: DefId ;
@@ -593,6 +593,7 @@ enum UnusedDelimsCtx {
593593 AnonConst ,
594594 MatchArmExpr ,
595595 IndexExpr ,
596+ ClosureBody ,
596597}
597598
598599impl From < UnusedDelimsCtx > for & ' static str {
@@ -614,6 +615,7 @@ impl From<UnusedDelimsCtx> for &'static str {
614615 UnusedDelimsCtx :: ArrayLenExpr | UnusedDelimsCtx :: AnonConst => "const expression" ,
615616 UnusedDelimsCtx :: MatchArmExpr => "match arm expression" ,
616617 UnusedDelimsCtx :: IndexExpr => "index expression" ,
618+ UnusedDelimsCtx :: ClosureBody => "closure body" ,
617619 }
618620 }
619621}
@@ -909,6 +911,14 @@ trait UnusedDelimLint {
909911 let ( args_to_check, ctx) = match * call_or_other {
910912 Call ( _, ref args) => ( & args[ ..] , UnusedDelimsCtx :: FunctionArg ) ,
911913 MethodCall ( ref call) => ( & call. args [ ..] , UnusedDelimsCtx :: MethodArg ) ,
914+ Closure ( ref closure)
915+ if matches ! ( closure. fn_decl. output, FnRetTy :: Default ( _) )
916+ // skip `#[core::contracts::requires(...)]` and `#[core::contracts::ensures(...)]`
917+ // which generate closure expr with span that is same as the inner closure body span
918+ && e. span != closure. body . span =>
919+ {
920+ ( & [ closure. body . clone ( ) ] [ ..] , UnusedDelimsCtx :: ClosureBody )
921+ }
912922 // actual catch-all arm
913923 _ => {
914924 return ;
@@ -1392,6 +1402,7 @@ impl UnusedDelimLint for UnusedBraces {
13921402 && ( ctx != UnusedDelimsCtx :: AnonConst
13931403 || ( matches ! ( expr. kind, ast:: ExprKind :: Lit ( _) )
13941404 && !expr. span . from_expansion ( ) ) )
1405+ && ctx != UnusedDelimsCtx :: ClosureBody
13951406 && !cx. sess ( ) . source_map ( ) . is_multiline ( value. span )
13961407 && value. attrs . is_empty ( )
13971408 && !value. span . from_expansion ( )
0 commit comments