@@ -17,6 +17,7 @@ use rustc_lint::LateContext;
17
17
use rustc_middle:: mir:: ConstValue ;
18
18
use rustc_middle:: mir:: interpret:: Scalar ;
19
19
use rustc_middle:: traits:: EvaluationResult ;
20
+ use rustc_middle:: ty:: adjustment:: { Adjust , Adjustment } ;
20
21
use rustc_middle:: ty:: layout:: ValidityRequirement ;
21
22
use rustc_middle:: ty:: {
22
23
self , AdtDef , AliasTy , AssocItem , AssocTag , Binder , BoundRegion , FnSig , GenericArg , GenericArgKind , GenericArgsRef ,
@@ -30,7 +31,7 @@ use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt;
30
31
use rustc_trait_selection:: traits:: { Obligation , ObligationCause } ;
31
32
use std:: assert_matches:: debug_assert_matches;
32
33
use std:: collections:: hash_map:: Entry ;
33
- use std:: iter;
34
+ use std:: { iter, mem } ;
34
35
35
36
use crate :: path_res;
36
37
use crate :: paths:: { PathNS , lookup_path_str} ;
@@ -1362,7 +1363,6 @@ pub fn is_slice_like<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
1362
1363
|| matches ! ( ty. kind( ) , ty:: Adt ( adt_def, _) if cx. tcx. is_diagnostic_item( sym:: Vec , adt_def. did( ) ) )
1363
1364
}
1364
1365
1365
- /// Gets the index of a field by name.
1366
1366
pub fn get_field_idx_by_name ( ty : Ty < ' _ > , name : Symbol ) -> Option < usize > {
1367
1367
match * ty. kind ( ) {
1368
1368
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> {
1372
1372
_ => None ,
1373
1373
}
1374
1374
}
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