Skip to content

Commit 121d9f5

Browse files
make LayoutError::Cycle carry ErrorGuaranteed
1 parent 2b603f9 commit 121d9f5

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

compiler/rustc_middle/src/ty/layout.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ pub enum LayoutError<'tcx> {
215215
SizeOverflow(Ty<'tcx>),
216216
NormalizationFailure(Ty<'tcx>, NormalizationError<'tcx>),
217217
ReferencesError(ErrorGuaranteed),
218-
Cycle,
218+
Cycle(ErrorGuaranteed),
219219
}
220220

221221
impl<'tcx> LayoutError<'tcx> {
@@ -226,7 +226,7 @@ impl<'tcx> LayoutError<'tcx> {
226226
Unknown(_) => middle_unknown_layout,
227227
SizeOverflow(_) => middle_values_too_big,
228228
NormalizationFailure(_, _) => middle_cannot_be_normalized,
229-
Cycle => middle_cycle,
229+
Cycle(_) => middle_cycle,
230230
ReferencesError(_) => middle_layout_references_error,
231231
}
232232
}
@@ -240,7 +240,7 @@ impl<'tcx> LayoutError<'tcx> {
240240
NormalizationFailure(ty, e) => {
241241
E::NormalizationFailure { ty, failure_ty: e.get_type_for_failure() }
242242
}
243-
Cycle => E::Cycle,
243+
Cycle(_) => E::Cycle,
244244
ReferencesError(_) => E::ReferencesError,
245245
}
246246
}
@@ -261,7 +261,7 @@ impl<'tcx> fmt::Display for LayoutError<'tcx> {
261261
t,
262262
e.get_type_for_failure()
263263
),
264-
LayoutError::Cycle => write!(f, "a cycle occurred during layout computation"),
264+
LayoutError::Cycle(_) => write!(f, "a cycle occurred during layout computation"),
265265
LayoutError::ReferencesError(_) => write!(f, "the type has an unknown layout"),
266266
}
267267
}
@@ -333,7 +333,7 @@ impl<'tcx> SizeSkeleton<'tcx> {
333333
Err(err @ LayoutError::Unknown(_)) => err,
334334
// We can't extract SizeSkeleton info from other layout errors
335335
Err(
336-
e @ LayoutError::Cycle
336+
e @ LayoutError::Cycle(_)
337337
| e @ LayoutError::SizeOverflow(_)
338338
| e @ LayoutError::NormalizationFailure(..)
339339
| e @ LayoutError::ReferencesError(_),

compiler/rustc_middle/src/values.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,11 @@ impl<'tcx> Value<TyCtxt<'tcx>> for ty::EarlyBinder<ty::Binder<'_, ty::FnSig<'_>>
114114
}
115115

116116
impl<'tcx, T> Value<TyCtxt<'tcx>> for Result<T, &'_ ty::layout::LayoutError<'_>> {
117-
fn from_cycle_error(_tcx: TyCtxt<'tcx>, _cycle: &[QueryInfo], _guar: ErrorGuaranteed) -> Self {
117+
fn from_cycle_error(_tcx: TyCtxt<'tcx>, _cycle: &[QueryInfo], guar: ErrorGuaranteed) -> Self {
118118
// tcx.arena.alloc cannot be used because we are not allowed to use &'tcx LayoutError under
119119
// min_specialization. Since this is an error path anyways, leaking doesn't matter (and really,
120120
// tcx.arena.alloc is pretty much equal to leaking).
121-
// FIXME: `Cycle` should carry the ErrorGuaranteed
122-
Err(Box::leak(Box::new(ty::layout::LayoutError::Cycle)))
121+
Err(Box::leak(Box::new(ty::layout::LayoutError::Cycle(guar))))
123122
}
124123
}
125124

src/librustdoc/html/templates/type_layout.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ <h2 id="layout" class="small-section-header"> {# #}
5454
<strong>Note:</strong> Encountered an error during type layout; {#+ #}
5555
the type failed to be normalized. {# #}
5656
</p> {# #}
57-
{% when Err(LayoutError::Cycle) %}
57+
{% when Err(LayoutError::Cycle(_)) %}
5858
<p> {# #}
5959
<strong>Note:</strong> Encountered an error during type layout; {#+ #}
6060
the type's layout depended on the type's layout itself. {# #}

0 commit comments

Comments
 (0)