@@ -117,15 +117,15 @@ use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
117117use rustc_middle:: ty:: fast_reject:: SimplifiedType ;
118118use rustc_middle:: ty:: layout:: IntegerExt ;
119119use 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 ,
122122} ;
123123use rustc_span:: hygiene:: { ExpnKind , MacroKind } ;
124124use rustc_span:: source_map:: SourceMap ;
125125use rustc_span:: symbol:: { Ident , Symbol , kw} ;
126126use rustc_span:: { InnerSpan , Span , sym} ;
127127use rustc_target:: abi:: Integer ;
128- use visitors:: Visitable ;
128+ use visitors:: { Visitable , for_each_unconsumed_temporary } ;
129129
130130use crate :: consts:: { ConstEvalCtxt , Constant , mir_to_const} ;
131131use crate :: higher:: Range ;
@@ -3465,3 +3465,20 @@ pub fn is_receiver_of_method_call(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool
34653465 }
34663466 false
34673467}
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