Skip to content

Commit c3c5a5c

Browse files
committed
Auto merge of #113922 - matthiaskrgr:rollup-90cj2vv, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #113887 (new solver: add a separate cache for coherence) - #113910 (Add FnPtr ty to SMIR) - #113913 (error/E0691: include alignment in error message) - #113914 (rustc_target: drop duplicate code) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 557359f + 1aaf583 commit c3c5a5c

File tree

9 files changed

+444
-245
lines changed

9 files changed

+444
-245
lines changed

compiler/rustc_error_codes/src/error_codes/E0691.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ struct ForceAlign32;
1111
1212
#[repr(transparent)]
1313
struct Wrapper(f32, ForceAlign32); // error: zero-sized field in transparent
14-
// struct has alignment larger than 1
14+
// struct has alignment of 32, which
15+
// is larger than 1
1516
```
1617

1718
A transparent struct, enum, or union is supposed to be represented exactly like

compiler/rustc_hir_analysis/src/check/check.rs

+19-10
Original file line numberDiff line numberDiff line change
@@ -1078,9 +1078,9 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
10781078
// We are currently checking the type this field came from, so it must be local
10791079
let span = tcx.hir().span_if_local(field.did).unwrap();
10801080
let zst = layout.is_ok_and(|layout| layout.is_zst());
1081-
let align1 = layout.is_ok_and(|layout| layout.align.abi.bytes() == 1);
1081+
let align = layout.ok().map(|layout| layout.align.abi.bytes());
10821082
if !zst {
1083-
return (span, zst, align1, None);
1083+
return (span, zst, align, None);
10841084
}
10851085

10861086
fn check_non_exhaustive<'tcx>(
@@ -1115,30 +1115,39 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
11151115
}
11161116
}
11171117

1118-
(span, zst, align1, check_non_exhaustive(tcx, ty).break_value())
1118+
(span, zst, align, check_non_exhaustive(tcx, ty).break_value())
11191119
});
11201120

11211121
let non_zst_fields = field_infos
11221122
.clone()
1123-
.filter_map(|(span, zst, _align1, _non_exhaustive)| if !zst { Some(span) } else { None });
1123+
.filter_map(|(span, zst, _align, _non_exhaustive)| if !zst { Some(span) } else { None });
11241124
let non_zst_count = non_zst_fields.clone().count();
11251125
if non_zst_count >= 2 {
11261126
bad_non_zero_sized_fields(tcx, adt, non_zst_count, non_zst_fields, tcx.def_span(adt.did()));
11271127
}
11281128
let incompatible_zst_fields =
11291129
field_infos.clone().filter(|(_, _, _, opt)| opt.is_some()).count();
11301130
let incompat = incompatible_zst_fields + non_zst_count >= 2 && non_zst_count < 2;
1131-
for (span, zst, align1, non_exhaustive) in field_infos {
1132-
if zst && !align1 {
1133-
struct_span_err!(
1131+
for (span, zst, align, non_exhaustive) in field_infos {
1132+
if zst && align != Some(1) {
1133+
let mut err = struct_span_err!(
11341134
tcx.sess,
11351135
span,
11361136
E0691,
11371137
"zero-sized field in transparent {} has alignment larger than 1",
11381138
adt.descr(),
1139-
)
1140-
.span_label(span, "has alignment larger than 1")
1141-
.emit();
1139+
);
1140+
1141+
if let Some(align_bytes) = align {
1142+
err.span_label(
1143+
span,
1144+
format!("has alignment of {align_bytes}, which is larger than 1"),
1145+
);
1146+
} else {
1147+
err.span_label(span, "may have alignment larger than 1");
1148+
}
1149+
1150+
err.emit();
11421151
}
11431152
if incompat && let Some((descr, def_id, args, non_exhaustive)) = non_exhaustive {
11441153
tcx.struct_span_lint_hir(

compiler/rustc_middle/src/ty/context.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ pub struct GlobalCtxt<'tcx> {
569569

570570
/// Caches the results of goal evaluation in the new solver.
571571
pub new_solver_evaluation_cache: solve::EvaluationCache<'tcx>,
572+
pub new_solver_coherence_evaluation_cache: solve::EvaluationCache<'tcx>,
572573

573574
/// Data layout specification for the current target.
574575
pub data_layout: TargetDataLayout,
@@ -680,10 +681,12 @@ impl<'tcx> TyCtxt<'tcx> {
680681
value.lift_to_tcx(self)
681682
}
682683

683-
/// Creates a type context and call the closure with a `TyCtxt` reference
684-
/// to the context. The closure enforces that the type context and any interned
685-
/// value (types, args, etc.) can only be used while `ty::tls` has a valid
686-
/// reference to the context, to allow formatting values that need it.
684+
/// Creates a type context. To use the context call `fn enter` which
685+
/// provides a `TyCtxt`.
686+
///
687+
/// By only providing the `TyCtxt` inside of the closure we enforce that the type
688+
/// context and any interned alue (types, args, etc.) can only be used while `ty::tls`
689+
/// has a valid reference to the context, to allow formatting values that need it.
687690
pub fn create_global_ctxt(
688691
s: &'tcx Session,
689692
lint_store: Lrc<dyn Any + sync::DynSend + sync::DynSync>,
@@ -721,6 +724,7 @@ impl<'tcx> TyCtxt<'tcx> {
721724
selection_cache: Default::default(),
722725
evaluation_cache: Default::default(),
723726
new_solver_evaluation_cache: Default::default(),
727+
new_solver_coherence_evaluation_cache: Default::default(),
724728
data_layout,
725729
alloc_map: Lock::new(interpret::AllocMap::new()),
726730
}

compiler/rustc_smir/src/rustc_internal/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ pub fn generator_def(did: DefId) -> stable_mir::ty::GeneratorDef {
4747
with_tables(|t| t.generator_def(did))
4848
}
4949

50+
pub fn param_def(did: DefId) -> stable_mir::ty::ParamDef {
51+
with_tables(|t| t.param_def(did))
52+
}
53+
54+
pub fn br_named_def(did: DefId) -> stable_mir::ty::BrNamedDef {
55+
with_tables(|t| t.br_named_def(did))
56+
}
57+
5058
impl<'tcx> Tables<'tcx> {
5159
pub fn item_def_id(&self, item: &stable_mir::CrateItem) -> DefId {
5260
self.def_ids[item.0]
@@ -76,6 +84,14 @@ impl<'tcx> Tables<'tcx> {
7684
stable_mir::ty::GeneratorDef(self.create_def_id(did))
7785
}
7886

87+
pub fn param_def(&mut self, did: DefId) -> stable_mir::ty::ParamDef {
88+
stable_mir::ty::ParamDef(self.create_def_id(did))
89+
}
90+
91+
pub fn br_named_def(&mut self, did: DefId) -> stable_mir::ty::BrNamedDef {
92+
stable_mir::ty::BrNamedDef(self.create_def_id(did))
93+
}
94+
7995
fn create_def_id(&mut self, did: DefId) -> stable_mir::DefId {
8096
// FIXME: this becomes inefficient when we have too many ids
8197
for (i, &d) in self.def_ids.iter().enumerate() {

0 commit comments

Comments
 (0)