@@ -5,7 +5,7 @@ use rustc_data_structures::unord::{UnordMap, UnordSet};
5
5
use rustc_errors:: codes:: * ;
6
6
use rustc_errors:: MultiSpan ;
7
7
use rustc_hir:: def:: { CtorKind , DefKind } ;
8
- use rustc_hir:: Node ;
8
+ use rustc_hir:: { LangItem , Node } ;
9
9
use rustc_infer:: infer:: { RegionVariableOrigin , TyCtxtInferExt } ;
10
10
use rustc_infer:: traits:: Obligation ;
11
11
use rustc_lint_defs:: builtin:: REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS ;
@@ -1259,6 +1259,17 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
1259
1259
ty:: Tuple ( list) => list. iter ( ) . try_for_each ( |t| check_non_exhaustive ( tcx, t) ) ,
1260
1260
ty:: Array ( ty, _) => check_non_exhaustive ( tcx, * ty) ,
1261
1261
ty:: Adt ( def, args) => {
1262
+ if matches ! (
1263
+ tcx. as_lang_item( def. did( ) ) ,
1264
+ Some ( LangItem :: UnsafeCell | LangItem :: ManuallyDrop | LangItem :: MaybeUninit )
1265
+ ) || matches ! (
1266
+ tcx. get_diagnostic_name( def. did( ) ) ,
1267
+ Some ( sym:: Cell | sym:: SyncUnsafeCell )
1268
+ ) {
1269
+ // These are the types from `std` that guarantee that
1270
+ // they have the same layout as `T`.
1271
+ return check_non_exhaustive ( tcx, args. type_at ( 0 ) ) ;
1272
+ }
1262
1273
if !def. did ( ) . is_local ( ) {
1263
1274
let non_exhaustive = def. is_variant_list_non_exhaustive ( )
1264
1275
|| def
0 commit comments