Skip to content

Commit 60765e3

Browse files
committed
bring back check for repr(C)
1 parent 134bed6 commit 60765e3

File tree

1 file changed

+14
-13
lines changed
  • compiler/rustc_hir_analysis/src/check

1 file changed

+14
-13
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,18 +1522,16 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
15221522
}
15231523
// Even some 1-ZST fields are not allowed though, if they have `non_exhaustive`.
15241524

1525-
fn check_non_exhaustive<'tcx>(
1525+
fn check_unsuited<'tcx>(
15261526
tcx: TyCtxt<'tcx>,
15271527
typing_env: ty::TypingEnv<'tcx>,
1528-
t: Ty<'tcx>,
1528+
ty: Ty<'tcx>,
15291529
) -> ControlFlow<(&'static str, DefId, GenericArgsRef<'tcx>, bool)> {
15301530
// We can encounter projections during traversal, so ensure the type is normalized.
1531-
let t = tcx.try_normalize_erasing_regions(typing_env, t).unwrap_or(t);
1532-
match t.kind() {
1533-
ty::Tuple(list) => {
1534-
list.iter().try_for_each(|t| check_non_exhaustive(tcx, typing_env, t))
1535-
}
1536-
ty::Array(ty, _) => check_non_exhaustive(tcx, typing_env, *ty),
1531+
let ty = tcx.try_normalize_erasing_regions(typing_env, ty).unwrap_or(ty);
1532+
match ty.kind() {
1533+
ty::Tuple(list) => list.iter().try_for_each(|t| check_unsuited(tcx, typing_env, t)),
1534+
ty::Array(ty, _) => check_unsuited(tcx, typing_env, *ty),
15371535
ty::Adt(def, args) => {
15381536
if !def.did().is_local()
15391537
&& !find_attr!(
@@ -1556,15 +1554,18 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
15561554
));
15571555
}
15581556
}
1557+
if def.repr().c() {
1558+
return ControlFlow::Break((def.descr(), def.did(), args, true));
1559+
}
15591560
def.all_fields()
15601561
.map(|field| field.ty(tcx, args))
1561-
.try_for_each(|t| check_non_exhaustive(tcx, typing_env, t))
1562+
.try_for_each(|t| check_unsuited(tcx, typing_env, t))
15621563
}
15631564
_ => ControlFlow::Continue(()),
15641565
}
15651566
}
15661567

1567-
(span, trivial, check_non_exhaustive(tcx, typing_env, ty).break_value())
1568+
(span, trivial, check_unsuited(tcx, typing_env, ty).break_value())
15681569
});
15691570

15701571
let non_trivial_fields = field_infos
@@ -1581,12 +1582,12 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
15811582
);
15821583
return;
15831584
}
1584-
let mut prev_non_exhaustive_1zst = false;
1585+
let mut prev_unsuited_1zst = false;
15851586
for (span, _trivial, non_exhaustive_1zst) in field_infos {
15861587
if let Some((descr, def_id, args, non_exhaustive)) = non_exhaustive_1zst {
15871588
// If there are any non-trivial fields, then there can be no non-exhaustive 1-zsts.
15881589
// Otherwise, it's only an issue if there's >1 non-exhaustive 1-zst.
1589-
if non_trivial_count > 0 || prev_non_exhaustive_1zst {
1590+
if non_trivial_count > 0 || prev_unsuited_1zst {
15901591
tcx.node_span_lint(
15911592
REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS,
15921593
tcx.local_def_id_to_hir_id(adt.did().expect_local()),
@@ -1610,7 +1611,7 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
16101611
},
16111612
)
16121613
} else {
1613-
prev_non_exhaustive_1zst = true;
1614+
prev_unsuited_1zst = true;
16141615
}
16151616
}
16161617
}

0 commit comments

Comments
 (0)