Skip to content

Commit 5de4857

Browse files
Add UnexpectedUnsized variant to LayoutError
Signed-off-by: FedericoBruzzone <[email protected]>
1 parent 6f2ca60 commit 5de4857

File tree

6 files changed

+28
-1
lines changed

6 files changed

+28
-1
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,11 @@ fn should_emit_generic_error<'tcx>(abi: ExternAbi, layout_err: &'tcx LayoutError
211211
_ => bug!("invalid ABI: {abi}"),
212212
}
213213
}
214-
SizeOverflow(..) | NormalizationFailure(..) | ReferencesError(..) | Cycle(..) => {
214+
TooGeneric(..)
215+
| SizeOverflow(..)
216+
| NormalizationFailure(..)
217+
| ReferencesError(..)
218+
| Cycle(..) => {
215219
false // not our job to report these
216220
}
217221
}

compiler/rustc_middle/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,15 @@ middle_strict_coherence_needs_negative_coherence =
100100
to use `strict_coherence` on this trait, the `with_negative_coherence` feature must be enabled
101101
.label = due to this attribute
102102
103+
middle_too_generic =
104+
cannot determine the layout of the type `{$ty}`; too generic
105+
103106
middle_type_length_limit = reached the type-length limit while instantiating `{$shrunk}`
104107
105108
middle_unknown_layout =
106109
the type `{$ty}` has an unknown layout
107110
108111
middle_values_too_big =
109112
values of the type `{$ty}` are too big for the target architecture
113+
110114
middle_written_to_path = the full type name has been written to '{$path}'

compiler/rustc_middle/src/error.rs

+3
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ pub enum LayoutError<'tcx> {
129129
#[diag(middle_unknown_layout)]
130130
Unknown { ty: Ty<'tcx> },
131131

132+
#[diag(middle_too_generic)]
133+
TooGeneric { ty: Ty<'tcx> },
134+
132135
#[diag(middle_values_too_big)]
133136
Overflow { ty: Ty<'tcx> },
134137

compiler/rustc_middle/src/ty/layout.rs

+7
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ impl fmt::Display for ValidityRequirement {
231231
pub enum LayoutError<'tcx> {
232232
Unknown(Ty<'tcx>),
233233
SizeOverflow(Ty<'tcx>),
234+
TooGeneric(Ty<'tcx>),
234235
NormalizationFailure(Ty<'tcx>, NormalizationError<'tcx>),
235236
ReferencesError(ErrorGuaranteed),
236237
Cycle(ErrorGuaranteed),
@@ -244,6 +245,7 @@ impl<'tcx> LayoutError<'tcx> {
244245
match self {
245246
Unknown(_) => middle_unknown_layout,
246247
SizeOverflow(_) => middle_values_too_big,
248+
TooGeneric(_) => middle_too_generic,
247249
NormalizationFailure(_, _) => middle_cannot_be_normalized,
248250
Cycle(_) => middle_cycle,
249251
ReferencesError(_) => middle_layout_references_error,
@@ -257,6 +259,7 @@ impl<'tcx> LayoutError<'tcx> {
257259
match self {
258260
Unknown(ty) => E::Unknown { ty },
259261
SizeOverflow(ty) => E::Overflow { ty },
262+
TooGeneric(ty) => E::TooGeneric { ty },
260263
NormalizationFailure(ty, e) => {
261264
E::NormalizationFailure { ty, failure_ty: e.get_type_for_failure() }
262265
}
@@ -272,6 +275,9 @@ impl<'tcx> fmt::Display for LayoutError<'tcx> {
272275
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
273276
match *self {
274277
LayoutError::Unknown(ty) => write!(f, "the type `{ty}` has an unknown layout"),
278+
LayoutError::TooGeneric(ty) => {
279+
write!(f, "cannot determine the layout for the type `{ty}`; too generic")
280+
}
275281
LayoutError::SizeOverflow(ty) => {
276282
write!(f, "values of the type `{ty}` are too big for the target architecture")
277283
}
@@ -355,6 +361,7 @@ impl<'tcx> SizeSkeleton<'tcx> {
355361
Err(
356362
e @ LayoutError::Cycle(_)
357363
| e @ LayoutError::SizeOverflow(_)
364+
| e @ LayoutError::TooGeneric(_)
358365
| e @ LayoutError::NormalizationFailure(..)
359366
| e @ LayoutError::ReferencesError(_),
360367
) => return Err(e),

compiler/rustc_transmute/src/layout/tree.rs

+1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ pub(crate) mod rustc {
197197
match err {
198198
LayoutError::Unknown(..)
199199
| LayoutError::ReferencesError(..)
200+
| LayoutError::TooGeneric(..)
200201
| LayoutError::NormalizationFailure(..) => Self::UnknownLayout,
201202
LayoutError::SizeOverflow(..) => Self::SizeOverflow,
202203
LayoutError::Cycle(err) => Self::TypeError(*err),

src/librustdoc/html/templates/type_layout.html

+8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ <h2 id="layout" class="section-header"> {# #}
4444
<strong>Note:</strong> Encountered an error during type layout; {#+ #}
4545
the type was too big. {# #}
4646
</p>
47+
{# This kind of error probably can't happen with valid code, but we don't
48+
want to panic and prevent the docs from building, so we just let the
49+
user know that we couldn't compute the layout. #}
50+
{% when Err(LayoutError::TooGeneric(_)) %}
51+
<p> {# #}
52+
<strong>Note:</strong> Encountered an error during type layout; {#+ #}
53+
the type was too generic. {# #}
54+
</p>
4755
{% when Err(LayoutError::ReferencesError(_)) %}
4856
<p> {# #}
4957
<strong>Note:</strong> Encountered an error during type layout; {#+ #}

0 commit comments

Comments
 (0)