Auto merge of #117849 - compiler-errors:cycle, r=cjgillot

make `LayoutError::Cycle` carry `ErrorGuaranteed`

Addresses a FIXME, and also I think it's wise for error variants to carry their `ErrorGuaranteed` -- makes it easier to use that `ErrorGuaranteed` for creating, e.g. `TyKind::Error` and other error kinds. Splitting out from #117703.
This commit is contained in:
bors 2023-11-14 16:04:29 +00:00
commit 8d57ad1ade
3 changed files with 8 additions and 9 deletions

View File

@ -215,7 +215,7 @@ pub enum LayoutError<'tcx> {
SizeOverflow(Ty<'tcx>), SizeOverflow(Ty<'tcx>),
NormalizationFailure(Ty<'tcx>, NormalizationError<'tcx>), NormalizationFailure(Ty<'tcx>, NormalizationError<'tcx>),
ReferencesError(ErrorGuaranteed), ReferencesError(ErrorGuaranteed),
Cycle, Cycle(ErrorGuaranteed),
} }
impl<'tcx> LayoutError<'tcx> { impl<'tcx> LayoutError<'tcx> {
@ -226,7 +226,7 @@ impl<'tcx> LayoutError<'tcx> {
Unknown(_) => middle_unknown_layout, Unknown(_) => middle_unknown_layout,
SizeOverflow(_) => middle_values_too_big, SizeOverflow(_) => middle_values_too_big,
NormalizationFailure(_, _) => middle_cannot_be_normalized, NormalizationFailure(_, _) => middle_cannot_be_normalized,
Cycle => middle_cycle, Cycle(_) => middle_cycle,
ReferencesError(_) => middle_layout_references_error, ReferencesError(_) => middle_layout_references_error,
} }
} }
@ -240,7 +240,7 @@ impl<'tcx> LayoutError<'tcx> {
NormalizationFailure(ty, e) => { NormalizationFailure(ty, e) => {
E::NormalizationFailure { ty, failure_ty: e.get_type_for_failure() } E::NormalizationFailure { ty, failure_ty: e.get_type_for_failure() }
} }
Cycle => E::Cycle, Cycle(_) => E::Cycle,
ReferencesError(_) => E::ReferencesError, ReferencesError(_) => E::ReferencesError,
} }
} }
@ -261,7 +261,7 @@ impl<'tcx> fmt::Display for LayoutError<'tcx> {
t, t,
e.get_type_for_failure() e.get_type_for_failure()
), ),
LayoutError::Cycle => write!(f, "a cycle occurred during layout computation"), LayoutError::Cycle(_) => write!(f, "a cycle occurred during layout computation"),
LayoutError::ReferencesError(_) => write!(f, "the type has an unknown layout"), LayoutError::ReferencesError(_) => write!(f, "the type has an unknown layout"),
} }
} }
@ -333,7 +333,7 @@ impl<'tcx> SizeSkeleton<'tcx> {
Err(err @ LayoutError::Unknown(_)) => err, Err(err @ LayoutError::Unknown(_)) => err,
// We can't extract SizeSkeleton info from other layout errors // We can't extract SizeSkeleton info from other layout errors
Err( Err(
e @ LayoutError::Cycle e @ LayoutError::Cycle(_)
| e @ LayoutError::SizeOverflow(_) | e @ LayoutError::SizeOverflow(_)
| e @ LayoutError::NormalizationFailure(..) | e @ LayoutError::NormalizationFailure(..)
| e @ LayoutError::ReferencesError(_), | e @ LayoutError::ReferencesError(_),

View File

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

View File

@ -54,7 +54,7 @@
<strong>Note:</strong> Encountered an error during type layout; {#+ #} <strong>Note:</strong> Encountered an error during type layout; {#+ #}
the type failed to be normalized. {# #} the type failed to be normalized. {# #}
</p> {# #} </p> {# #}
{% when Err(LayoutError::Cycle) %} {% when Err(LayoutError::Cycle(_)) %}
<p> {# #} <p> {# #}
<strong>Note:</strong> Encountered an error during type layout; {#+ #} <strong>Note:</strong> Encountered an error during type layout; {#+ #}
the type's layout depended on the type's layout itself. {# #} the type's layout depended on the type's layout itself. {# #}