@@ -117,15 +117,15 @@ use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
117
117
use rustc_middle:: ty:: fast_reject:: SimplifiedType ;
118
118
use rustc_middle:: ty:: layout:: IntegerExt ;
119
119
use rustc_middle:: ty:: {
120
- self as rustc_ty, Binder , BorrowKind , ClosureKind , EarlyBinder , FloatTy , GenericArgsRef , IntTy , Ty , TyCtxt ,
121
- TypeVisitableExt , UintTy , UpvarCapture ,
120
+ self as rustc_ty, Binder , BorrowKind , ClosureKind , EarlyBinder , FloatTy , GenericArgKind , GenericArgsRef , IntTy , Ty ,
121
+ TyCtxt , TypeVisitableExt , UintTy , UpvarCapture ,
122
122
} ;
123
123
use rustc_span:: hygiene:: { ExpnKind , MacroKind } ;
124
124
use rustc_span:: source_map:: SourceMap ;
125
125
use rustc_span:: symbol:: { Ident , Symbol , kw} ;
126
126
use rustc_span:: { InnerSpan , Span , sym} ;
127
127
use rustc_target:: abi:: Integer ;
128
- use visitors:: Visitable ;
128
+ use visitors:: { Visitable , for_each_unconsumed_temporary } ;
129
129
130
130
use crate :: consts:: { ConstEvalCtxt , Constant , mir_to_const} ;
131
131
use crate :: higher:: Range ;
@@ -3465,3 +3465,20 @@ pub fn is_receiver_of_method_call(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool
3465
3465
}
3466
3466
false
3467
3467
}
3468
+
3469
+ /// Returns true if `expr` creates any temporary whose type references a non-static lifetime and has
3470
+ /// a significant drop and does not consume it.
3471
+ pub fn leaks_droppable_temporary_with_limited_lifetime < ' tcx > ( cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' tcx > ) -> bool {
3472
+ for_each_unconsumed_temporary ( cx, expr, |temporary_ty| {
3473
+ if temporary_ty. has_significant_drop ( cx. tcx , cx. typing_env ( ) )
3474
+ && temporary_ty
3475
+ . walk ( )
3476
+ . any ( |arg| matches ! ( arg. unpack( ) , GenericArgKind :: Lifetime ( re) if !re. is_static( ) ) )
3477
+ {
3478
+ ControlFlow :: Break ( ( ) )
3479
+ } else {
3480
+ ControlFlow :: Continue ( ( ) )
3481
+ }
3482
+ } )
3483
+ . is_break ( )
3484
+ }
0 commit comments