Skip to content

Commit 85e2ea6

Browse files
Add UnexpectedUnsized variant to LayoutError
Signed-off-by: FedericoBruzzone <[email protected]>
1 parent 13738b0 commit 85e2ea6

File tree

6 files changed

+27
-1
lines changed

6 files changed

+27
-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+
UnexpectedUnsized(..)
215+
| SizeOverflow(..)
216+
| NormalizationFailure(..)
217+
| ReferencesError(..)
218+
| Cycle(..) => {
215219
false // not our job to report these
216220
}
217221
}

compiler/rustc_middle/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,6 @@ middle_unknown_layout =
108108
middle_values_too_big =
109109
values of the type `{$ty}` are too big for the target architecture
110110
middle_written_to_path = the full type name has been written to '{$path}'
111+
112+
middle_unexpected_unsized =
113+
cannot determine the layout of the type `{$ty}`

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_unexpected_unsized)]
133+
Unsized { 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+
UnexpectedUnsized(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+
UnexpectedUnsized(_) => middle_unexpected_unsized,
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+
UnexpectedUnsized(ty) => E::Unsized { 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::UnexpectedUnsized(ty) => {
279+
write!(f, "cannot determine the layout for the type `{ty}`")
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::UnexpectedUnsized(_)
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::UnexpectedUnsized(..)
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::UnexpectedUnsized(_)) %}
51+
<p> {# #}
52+
<strong>Note:</strong> Encountered an error during type layout; {#+ #}
53+
the type was unexpectedly unsized. {# #}
54+
</p>
4755
{% when Err(LayoutError::ReferencesError(_)) %}
4856
<p> {# #}
4957
<strong>Note:</strong> Encountered an error during type layout; {#+ #}

0 commit comments

Comments
 (0)