@@ -2,7 +2,7 @@ use std::iter;
2
2
3
3
use rustc_ast as ast;
4
4
use rustc_ast:: util:: { classify, parser} ;
5
- use rustc_ast:: { ExprKind , StmtKind } ;
5
+ use rustc_ast:: { ExprKind , FnRetTy , StmtKind } ;
6
6
use rustc_errors:: { MultiSpan , pluralize} ;
7
7
use rustc_hir:: def:: { DefKind , Res } ;
8
8
use rustc_hir:: def_id:: DefId ;
@@ -593,6 +593,7 @@ enum UnusedDelimsCtx {
593
593
AnonConst ,
594
594
MatchArmExpr ,
595
595
IndexExpr ,
596
+ ClosureBody ,
596
597
}
597
598
598
599
impl From < UnusedDelimsCtx > for & ' static str {
@@ -614,6 +615,7 @@ impl From<UnusedDelimsCtx> for &'static str {
614
615
UnusedDelimsCtx :: ArrayLenExpr | UnusedDelimsCtx :: AnonConst => "const expression" ,
615
616
UnusedDelimsCtx :: MatchArmExpr => "match arm expression" ,
616
617
UnusedDelimsCtx :: IndexExpr => "index expression" ,
618
+ UnusedDelimsCtx :: ClosureBody => "closure body" ,
617
619
}
618
620
}
619
621
}
@@ -909,6 +911,18 @@ trait UnusedDelimLint {
909
911
let ( args_to_check, ctx) = match * call_or_other {
910
912
Call ( _, ref args) => ( & args[ ..] , UnusedDelimsCtx :: FunctionArg ) ,
911
913
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(...)]` which generate closure
917
+ && !cx
918
+ . sess ( )
919
+ . source_map ( )
920
+ . span_to_snippet ( closure. fn_decl_span )
921
+ . unwrap_or_default ( )
922
+ . contains ( "core::contracts" ) =>
923
+ {
924
+ ( & [ closure. body . clone ( ) ] [ ..] , UnusedDelimsCtx :: ClosureBody )
925
+ }
912
926
// actual catch-all arm
913
927
_ => {
914
928
return ;
0 commit comments