@@ -17,6 +17,7 @@ use rustc_lint::LateContext;
1717use rustc_middle:: mir:: ConstValue ;
1818use rustc_middle:: mir:: interpret:: Scalar ;
1919use rustc_middle:: traits:: EvaluationResult ;
20+ use rustc_middle:: ty:: adjustment:: { Adjust , Adjustment } ;
2021use rustc_middle:: ty:: layout:: ValidityRequirement ;
2122use rustc_middle:: ty:: {
2223 self , AdtDef , AliasTy , AssocItem , AssocTag , Binder , BoundRegion , FnSig , GenericArg , GenericArgKind , GenericArgsRef ,
@@ -30,7 +31,7 @@ use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt;
3031use rustc_trait_selection:: traits:: { Obligation , ObligationCause } ;
3132use std:: assert_matches:: debug_assert_matches;
3233use std:: collections:: hash_map:: Entry ;
33- use std:: iter;
34+ use std:: { iter, mem } ;
3435
3536use crate :: path_res;
3637use crate :: paths:: { PathNS , lookup_path_str} ;
@@ -1362,7 +1363,6 @@ pub fn is_slice_like<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
13621363 || matches ! ( ty. kind( ) , ty:: Adt ( adt_def, _) if cx. tcx. is_diagnostic_item( sym:: Vec , adt_def. did( ) ) )
13631364}
13641365
1365- /// Gets the index of a field by name.
13661366pub fn get_field_idx_by_name ( ty : Ty < ' _ > , name : Symbol ) -> Option < usize > {
13671367 match * ty. kind ( ) {
13681368 ty:: Adt ( def, _) if def. is_union ( ) || def. is_struct ( ) => {
@@ -1372,3 +1372,11 @@ pub fn get_field_idx_by_name(ty: Ty<'_>, name: Symbol) -> Option<usize> {
13721372 _ => None ,
13731373 }
13741374}
1375+
1376+ /// Checks if the adjustments contain a mutable dereference of a `ManuallyDrop<_>`.
1377+ pub fn adjust_derefs_manually_drop < ' tcx > ( adjustments : & ' tcx [ Adjustment < ' tcx > ] , mut ty : Ty < ' tcx > ) -> bool {
1378+ adjustments. iter ( ) . any ( |a| {
1379+ let ty = mem:: replace ( & mut ty, a. target ) ;
1380+ matches ! ( a. kind, Adjust :: Deref ( Some ( op) ) if op. mutbl == Mutability :: Mut ) && is_manually_drop ( ty)
1381+ } )
1382+ }
0 commit comments