@@ -3,7 +3,7 @@ use std::ops::ControlFlow;
3
3
4
4
use rustc_ast as ast;
5
5
use rustc_ast:: util:: { classify, parser} ;
6
- use rustc_ast:: { ExprKind , StmtKind } ;
6
+ use rustc_ast:: { ExprKind , FnRetTy , StmtKind } ;
7
7
use rustc_errors:: { MultiSpan , pluralize} ;
8
8
use rustc_hir:: def:: { DefKind , Res } ;
9
9
use rustc_hir:: def_id:: DefId ;
@@ -594,6 +594,7 @@ enum UnusedDelimsCtx {
594
594
AnonConst ,
595
595
MatchArmExpr ,
596
596
IndexExpr ,
597
+ ClosureBody ,
597
598
}
598
599
599
600
impl From < UnusedDelimsCtx > for & ' static str {
@@ -615,6 +616,7 @@ impl From<UnusedDelimsCtx> for &'static str {
615
616
UnusedDelimsCtx :: ArrayLenExpr | UnusedDelimsCtx :: AnonConst => "const expression" ,
616
617
UnusedDelimsCtx :: MatchArmExpr => "match arm expression" ,
617
618
UnusedDelimsCtx :: IndexExpr => "index expression" ,
619
+ UnusedDelimsCtx :: ClosureBody => "closure body" ,
618
620
}
619
621
}
620
622
}
@@ -933,6 +935,18 @@ trait UnusedDelimLint {
933
935
let ( args_to_check, ctx) = match * call_or_other {
934
936
Call ( _, ref args) => ( & args[ ..] , UnusedDelimsCtx :: FunctionArg ) ,
935
937
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
+ }
936
950
// actual catch-all arm
937
951
_ => {
938
952
return ;
0 commit comments