Skip to content

Commit 3d25b5c

Browse files
committed
Fix ICE failed to get layout for ReferencesError
1 parent 60fa393 commit 3d25b5c

File tree

5 files changed

+55
-3
lines changed

5 files changed

+55
-3
lines changed

compiler/rustc_codegen_cranelift/src/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ impl<'tcx> LayoutOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> {
477477

478478
#[inline]
479479
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
480-
if let layout::LayoutError::SizeOverflow(_) = err {
480+
if let LayoutError::SizeOverflow(_) | LayoutError::ReferencesError(_) = err {
481481
self.0.sess.span_fatal(span, err.to_string())
482482
} else {
483483
span_bug!(span, "failed to get layout for `{}`: {}", ty, err)

compiler/rustc_codegen_gcc/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ impl<'gcc, 'tcx> LayoutOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> {
476476

477477
#[inline]
478478
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
479-
if let LayoutError::SizeOverflow(_) = err {
479+
if let LayoutError::SizeOverflow(_) | LayoutError::ReferencesError(_) = err {
480480
self.sess().emit_fatal(respan(span, err.into_diagnostic()))
481481
} else {
482482
span_bug!(span, "failed to get layout for `{}`: {}", ty, err)

compiler/rustc_codegen_llvm/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ impl<'tcx> LayoutOfHelpers<'tcx> for CodegenCx<'_, 'tcx> {
985985

986986
#[inline]
987987
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
988-
if let LayoutError::SizeOverflow(_) = err {
988+
if let LayoutError::SizeOverflow(_) | LayoutError::ReferencesError(_) = err {
989989
self.sess().emit_fatal(Spanned { span, node: err.into_diagnostic() })
990990
} else {
991991
span_bug!(span, "failed to get layout for `{ty}`: {err:?}")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// build-fail
2+
// compile-flags: --crate-type lib -Cdebuginfo=2
3+
// error-pattern: the type has an unknown layout
4+
5+
#![recursion_limit = "10"]
6+
macro_rules! link {
7+
($outer:ident, $inner:ident) => {
8+
struct $outer($inner);
9+
impl $outer {
10+
fn new() -> $outer {
11+
$outer($inner::new())
12+
}
13+
}
14+
impl std::ops::Deref for $outer {
15+
type Target = $inner;
16+
fn deref(&self) -> &$inner {
17+
&self.0
18+
}
19+
}
20+
};
21+
}
22+
23+
struct Bottom;
24+
25+
impl Bottom {
26+
fn new() -> Bottom {
27+
Bottom
28+
}
29+
}
30+
31+
32+
link!(A, B);
33+
link!(B, C);
34+
link!(C, D);
35+
link!(D, E);
36+
link!(E, F);
37+
link!(F, G);
38+
link!(G, H);
39+
link!(H, I);
40+
link!(I, J);
41+
link!(J, K);
42+
link!(K, Bottom);
43+
44+
fn main() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: reached the recursion limit finding the struct tail for `Bottom`
2+
|
3+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "20"]`
4+
5+
error: the type has an unknown layout
6+
7+
error: aborting due to 2 previous errors
8+

0 commit comments

Comments
 (0)