Skip to content

Commit a4dec53

Browse files
authored
Unrolled build for rust-lang#131420
Rollup merge of rust-lang#131420 - compiler-errors:post-mono-layout-cycle, r=wesleywiser Dont ICE when encountering post-mono layout cycle error It's possible to encounter post-mono layout cycle errors in `fn_abi_of_instance`. Don't ICE in those cases. This was originally discovered in an async fn, but that's not the only way to encounter such an error (which the other test I added should demonstrate). Error messsages suck, but this fix is purely about suppressing the ICE. Fixes rust-lang#131409
2 parents eb4e234 + 17eca60 commit a4dec53

File tree

5 files changed

+129
-5
lines changed

5 files changed

+129
-5
lines changed

compiler/rustc_codegen_llvm/src/context.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1187,10 +1187,11 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for CodegenCx<'_, 'tcx> {
11871187
span: Span,
11881188
fn_abi_request: FnAbiRequest<'tcx>,
11891189
) -> ! {
1190-
if let FnAbiError::Layout(LayoutError::SizeOverflow(_)) = err {
1191-
self.tcx.dcx().emit_fatal(Spanned { span, node: err })
1192-
} else {
1193-
match fn_abi_request {
1190+
match err {
1191+
FnAbiError::Layout(LayoutError::SizeOverflow(_) | LayoutError::Cycle(_)) => {
1192+
self.tcx.dcx().emit_fatal(Spanned { span, node: err });
1193+
}
1194+
_ => match fn_abi_request {
11941195
FnAbiRequest::OfFnPtr { sig, extra_args } => {
11951196
span_bug!(span, "`fn_abi_of_fn_ptr({sig}, {extra_args:?})` failed: {err:?}",);
11961197
}
@@ -1200,7 +1201,7 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for CodegenCx<'_, 'tcx> {
12001201
"`fn_abi_of_instance({instance}, {extra_args:?})` failed: {err:?}",
12011202
);
12021203
}
1203-
}
1204+
},
12041205
}
12051206
}
12061207
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//@ build-fail
2+
//@ edition: 2021
3+
4+
#![feature(async_closure, noop_waker)]
5+
6+
use std::future::Future;
7+
use std::pin::pin;
8+
use std::task::*;
9+
10+
pub fn block_on<T>(fut: impl Future<Output = T>) -> T {
11+
let mut fut = pin!(fut);
12+
// Poll loop, just to test the future...
13+
let ctx = &mut Context::from_waker(Waker::noop());
14+
15+
loop {
16+
match fut.as_mut().poll(ctx) {
17+
Poll::Pending => {}
18+
Poll::Ready(t) => break t,
19+
}
20+
}
21+
}
22+
23+
trait Blah {
24+
async fn iter<T>(&mut self, iterator: T)
25+
where
26+
T: IntoIterator<Item = ()>;
27+
}
28+
29+
impl Blah for () {
30+
async fn iter<T>(&mut self, iterator: T)
31+
//~^ ERROR recursion in an async fn requires boxing
32+
where
33+
T: IntoIterator<Item = ()>,
34+
{
35+
Blah::iter(self, iterator).await
36+
}
37+
}
38+
39+
struct Wrap<T: Blah> {
40+
t: T,
41+
}
42+
43+
impl<T: Blah> Wrap<T>
44+
where
45+
T: Blah,
46+
{
47+
async fn ice(&mut self) {
48+
//~^ ERROR a cycle occurred during layout computation
49+
let arr: [(); 0] = [];
50+
self.t.iter(arr.into_iter()).await;
51+
}
52+
}
53+
54+
fn main() {
55+
block_on(async {
56+
let mut t = Wrap { t: () };
57+
t.ice();
58+
})
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0733]: recursion in an async fn requires boxing
2+
--> $DIR/post-mono-layout-cycle-2.rs:30:5
3+
|
4+
LL | / async fn iter<T>(&mut self, iterator: T)
5+
LL | |
6+
LL | | where
7+
LL | | T: IntoIterator<Item = ()>,
8+
| |___________________________________^
9+
LL | {
10+
LL | Blah::iter(self, iterator).await
11+
| -------------------------------- recursive call here
12+
|
13+
= note: a recursive `async fn` call must introduce indirection such as `Box::pin` to avoid an infinitely sized future
14+
15+
error: a cycle occurred during layout computation
16+
--> $DIR/post-mono-layout-cycle-2.rs:47:5
17+
|
18+
LL | async fn ice(&mut self) {
19+
| ^^^^^^^^^^^^^^^^^^^^^^^
20+
21+
error: aborting due to 2 previous errors
22+
23+
For more information about this error, try `rustc --explain E0733`.
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//@ build-fail
2+
//~^ cycle detected when computing layout of `Wrapper<()>`
3+
4+
trait Trait {
5+
type Assoc;
6+
}
7+
8+
impl Trait for () {
9+
type Assoc = Wrapper<()>;
10+
}
11+
12+
struct Wrapper<T: Trait> {
13+
_x: <T as Trait>::Assoc,
14+
}
15+
16+
fn abi<T: Trait>(_: Option<Wrapper<T>>) {}
17+
//~^ ERROR a cycle occurred during layout computation
18+
19+
fn indirect<T: Trait>() {
20+
abi::<T>(None);
21+
}
22+
23+
fn main() {
24+
indirect::<()>();
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0391]: cycle detected when computing layout of `Wrapper<()>`
2+
|
3+
= note: ...which requires computing layout of `<() as Trait>::Assoc`...
4+
= note: ...which again requires computing layout of `Wrapper<()>`, completing the cycle
5+
= note: cycle used when computing layout of `core::option::Option<Wrapper<()>>`
6+
= 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
7+
8+
error: a cycle occurred during layout computation
9+
--> $DIR/post-mono-layout-cycle.rs:16:1
10+
|
11+
LL | fn abi<T: Trait>(_: Option<Wrapper<T>>) {}
12+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13+
14+
error: aborting due to 2 previous errors
15+
16+
For more information about this error, try `rustc --explain E0391`.

0 commit comments

Comments
 (0)