Make layout_of cycles fatal errors

This commit is contained in:
John Kåre Alsaker
2026-02-27 06:23:06 +01:00
parent 0312931d8c
commit 043bd76768
13 changed files with 11 additions and 78 deletions
+1 -5
View File
@@ -1134,11 +1134,7 @@ fn handle_fn_abi_err(
fn_abi_request: FnAbiRequest<'tcx>,
) -> ! {
match err {
FnAbiError::Layout(
LayoutError::SizeOverflow(_)
| LayoutError::Cycle(_)
| LayoutError::InvalidSimd { .. },
) => {
FnAbiError::Layout(LayoutError::SizeOverflow(_) | LayoutError::InvalidSimd { .. }) => {
self.tcx.dcx().emit_fatal(Spanned { span, node: err });
}
_ => match fn_abi_request {
@@ -107,8 +107,7 @@ fn handle_layout_err(
| LayoutError::SizeOverflow(_)
| LayoutError::InvalidSimd { .. }
| LayoutError::TooGeneric(_)
| LayoutError::ReferencesError(_)
| LayoutError::Cycle(_) => {}
| LayoutError::ReferencesError(_) => {}
}
err_inval!(Layout(err))
}
@@ -194,8 +194,7 @@ fn should_emit_layout_error<'tcx>(abi: ExternAbi, layout_err: &'tcx LayoutError<
| SizeOverflow(..)
| InvalidSimd { .. }
| NormalizationFailure(..)
| ReferencesError(..)
| Cycle(..) => {
| ReferencesError(..) => {
false // not our job to report these
}
}
+1 -5
View File
@@ -260,8 +260,6 @@ pub enum LayoutError<'tcx> {
NormalizationFailure(Ty<'tcx>, NormalizationError<'tcx>),
/// A non-layout error is reported elsewhere.
ReferencesError(ErrorGuaranteed),
/// A type has cyclic layout, i.e. the type contains itself without indirection.
Cycle(ErrorGuaranteed),
}
impl<'tcx> fmt::Display for LayoutError<'tcx> {
@@ -286,7 +284,6 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
t,
e.get_type_for_failure()
),
LayoutError::Cycle(_) => write!(f, "a cycle occurred during layout computation"),
LayoutError::ReferencesError(_) => write!(f, "the type has an unknown layout"),
}
}
@@ -358,8 +355,7 @@ pub fn compute(
Err(err @ LayoutError::TooGeneric(_)) => err,
// We can't extract SizeSkeleton info from other layout errors
Err(
e @ LayoutError::Cycle(_)
| e @ LayoutError::Unknown(_)
e @ LayoutError::Unknown(_)
| e @ LayoutError::SizeOverflow(_)
| e @ LayoutError::InvalidSimd { .. }
| e @ LayoutError::NormalizationFailure(..)
@@ -12,7 +12,6 @@
use rustc_middle::queries::{QueryVTables, TaggedQueryKey};
use rustc_middle::query::Cycle;
use rustc_middle::query::erase::erase_val;
use rustc_middle::ty::layout::LayoutError;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::def_id::{DefId, LocalDefId};
use rustc_span::{ErrorGuaranteed, Span};
@@ -203,8 +202,7 @@ fn layout_of<'tcx>(tcx: TyCtxt<'tcx>, cycle: Cycle<'tcx>) -> &'tcx ty::layout::L
|| create_cycle_error(tcx, &cycle),
);
let guar = diag.emit();
tcx.arena.alloc(LayoutError::Cycle(guar))
diag.emit().raise_fatal()
}
// item_and_field_ids should form a cycle where each field contains the
@@ -282,7 +282,6 @@ fn from(err: &LayoutError<'tcx>) -> Self {
| LayoutError::InvalidSimd { .. }
| LayoutError::NormalizationFailure(..) => Self::UnknownLayout,
LayoutError::SizeOverflow(..) => Self::SizeOverflow,
LayoutError::Cycle(err) => Self::TypeError(*err),
}
}
}
@@ -60,11 +60,6 @@
<strong>Note:</strong> Encountered an error during type layout; {#+ #}
the type failed to be normalized. {# #}
</p>
{% when Err(LayoutError::Cycle(_)) %}
<p> {# #}
<strong>Note:</strong> Encountered an error during type layout; {#+ #}
the type's layout depended on the type's layout itself. {# #}
</p>
{% when Err(LayoutError::InvalidSimd {..}) %}
<p> {# #}
<strong>Note:</strong> Encountered an error during type layout; {#+ #}
-1
View File
@@ -1,6 +1,5 @@
//@ build-fail
//~^ ERROR: cycle detected when computing layout of
//~? ERROR: a cycle occurred during layout computation
// Issue #111176 -- ensure that we do not emit ICE on layout cycles
+2 -14
View File
@@ -6,18 +6,6 @@ note: cycle used when const-evaluating + checking `core::mem::SizedTypePropertie
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
error[E0080]: a cycle occurred during layout computation
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
|
= note: evaluation of `<S<S<()>> as std::mem::SizedTypeProperties>::SIZE` failed here
error: aborting due to 1 previous error
note: the above error was encountered while instantiating `fn std::mem::size_of::<S<S<()>>>`
--> $DIR/layout-cycle.rs:26:5
|
LL | mem::size_of::<S<T>>()
| ^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0080, E0391.
For more information about an error, try `rustc --explain E0080`.
For more information about this error, try `rustc --explain E0391`.
@@ -5,12 +5,6 @@ error[E0391]: cycle detected when computing layout of `Wrapper<()>`
= note: cycle used when computing layout of `core::option::Option<Wrapper<()>>`
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
note: the above error was encountered while instantiating `fn abi::<()>`
--> $DIR/post-mono-layout-cycle.rs:19:5
|
LL | abi::<T>(None);
| ^^^^^^^^^^^^^^
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0391`.
@@ -1,21 +0,0 @@
error[E0391]: cycle detected when computing layout of `Foo`
|
= note: ...which requires computing layout of `<&'static Foo as core::ops::deref::Deref>::Target`...
= note: ...which again requires computing layout of `Foo`, completing the cycle
note: cycle used when const-evaluating + checking `_`
--> $DIR/stack-overflow-trait-infer-98842.rs:14:1
|
LL | const _: *const Foo = 0 as _;
| ^^^^^^^^^^^^^^^^^^^
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
error[E0080]: a cycle occurred during layout computation
--> $DIR/stack-overflow-trait-infer-98842.rs:14:1
|
LL | const _: *const Foo = 0 as _;
| ^^^^^^^^^^^^^^^^^^^ evaluation of `_` failed here
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0080, E0391.
For more information about an error, try `rustc --explain E0080`.
@@ -2,8 +2,7 @@
// issue: rust-lang/rust#98842
//@ check-fail
//@ edition:2021
//@ stderr-per-bitwidth
//~^^^^^ ERROR cycle detected when computing layout of `Foo`
//~^^^^ ERROR cycle detected when computing layout of `Foo`
// If the inner `Foo` is named through an associated type,
// the "infinite size" error does not occur.
@@ -12,6 +11,5 @@
// and it will infinitely recurse somewhere trying to figure out the
// size of this pointer (is my guess):
const _: *const Foo = 0 as _;
//~^ ERROR a cycle occurred during layout computation
pub fn main() {}
@@ -3,19 +3,12 @@ error[E0391]: cycle detected when computing layout of `Foo`
= note: ...which requires computing layout of `<&'static Foo as core::ops::deref::Deref>::Target`...
= note: ...which again requires computing layout of `Foo`, completing the cycle
note: cycle used when const-evaluating + checking `_`
--> $DIR/stack-overflow-trait-infer-98842.rs:14:1
--> $DIR/stack-overflow-trait-infer-98842.rs:13:1
|
LL | const _: *const Foo = 0 as _;
| ^^^^^^^^^^^^^^^^^^^
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
error[E0080]: a cycle occurred during layout computation
--> $DIR/stack-overflow-trait-infer-98842.rs:14:1
|
LL | const _: *const Foo = 0 as _;
| ^^^^^^^^^^^^^^^^^^^ evaluation of `_` failed here
error: aborting due to 1 previous error
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0080, E0391.
For more information about an error, try `rustc --explain E0080`.
For more information about this error, try `rustc --explain E0391`.