@@ -3,7 +3,7 @@ use std::ops::ControlFlow;
33
44use rustc_ast as ast;
55use rustc_ast:: util:: { classify, parser} ;
6- use rustc_ast:: { ExprKind , StmtKind } ;
6+ use rustc_ast:: { ExprKind , FnRetTy , StmtKind } ;
77use rustc_errors:: { MultiSpan , pluralize} ;
88use rustc_hir:: def:: { DefKind , Res } ;
99use rustc_hir:: def_id:: DefId ;
@@ -594,6 +594,7 @@ enum UnusedDelimsCtx {
594594 AnonConst ,
595595 MatchArmExpr ,
596596 IndexExpr ,
597+ ClosureBody ,
597598}
598599
599600impl From < UnusedDelimsCtx > for & ' static str {
@@ -615,6 +616,7 @@ impl From<UnusedDelimsCtx> for &'static str {
615616 UnusedDelimsCtx :: ArrayLenExpr | UnusedDelimsCtx :: AnonConst => "const expression" ,
616617 UnusedDelimsCtx :: MatchArmExpr => "match arm expression" ,
617618 UnusedDelimsCtx :: IndexExpr => "index expression" ,
619+ UnusedDelimsCtx :: ClosureBody => "closure body" ,
618620 }
619621 }
620622}
@@ -933,6 +935,18 @@ trait UnusedDelimLint {
933935 let ( args_to_check, ctx) = match * call_or_other {
934936 Call ( _, ref args) => ( & args[ ..] , UnusedDelimsCtx :: FunctionArg ) ,
935937 MethodCall ( ref call) => ( & call. args [ ..] , UnusedDelimsCtx :: MethodArg ) ,
938+ Closure ( ref closure)
939+ if matches ! ( closure. fn_decl. output, FnRetTy :: Default ( _) )
940+ // skip `#[core::contracts::requires(...)]` and `#[core::contracts::ensures(...)]` which generate closure
941+ && !cx
942+ . sess ( )
943+ . source_map ( )
944+ . span_to_snippet ( closure. fn_decl_span )
945+ . unwrap_or_default ( )
946+ . contains ( "core::contracts" ) =>
947+ {
948+ ( & [ closure. body . clone ( ) ] [ ..] , UnusedDelimsCtx :: ClosureBody )
949+ }
936950 // actual catch-all arm
937951 _ => {
938952 return ;
0 commit comments