Skip to content

Commit 17eca60

Browse files
Dont ICE when encountering post-mono layout cycle error
1 parent 6a3c45e commit 17eca60

5 files changed

Lines changed: 129 additions & 5 deletions

File tree

‎compiler/rustc_codegen_llvm/src/context.rs‎

Lines changed: 6 additions & 5 deletions
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-
ifletFnAbiError::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
}
Lines changed: 59 additions & 0 deletions
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+
pubfnblock_on<T>(fut:implFuture<Output = T>) -> T{
11+
letmut fut = pin!(fut);
12+
// Poll loop, just to test the future...
13+
let ctx = &mutContext::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+
traitBlah{
24+
asyncfniter<T>(&mutself,iterator:T)
25+
where
26+
T:IntoIterator<Item = ()>;
27+
}
28+
29+
implBlahfor(){
30+
asyncfniter<T>(&mutself,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+
structWrap<T:Blah>{
40+
t:T,
41+
}
42+
43+
impl<T:Blah>Wrap<T>
44+
where
45+
T:Blah,
46+
{
47+
asyncfnice(&mutself){
48+
//~^ ERROR a cycle occurred during layout computation
49+
let arr:[();0] = [];
50+
self.t.iter(arr.into_iter()).await;
51+
}
52+
}
53+
54+
fnmain(){
55+
block_on(async{
56+
letmut t = Wrap{t:()};
57+
t.ice();
58+
})
59+
}
Lines changed: 23 additions & 0 deletions
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`.
Lines changed: 25 additions & 0 deletions
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+
traitTrait{
5+
typeAssoc;
6+
}
7+
8+
implTraitfor(){
9+
typeAssoc = Wrapper<()>;
10+
}
11+
12+
structWrapper<T:Trait>{
13+
_x: <TasTrait>::Assoc,
14+
}
15+
16+
fnabi<T:Trait>(_:Option<Wrapper<T>>){}
17+
//~^ ERROR a cycle occurred during layout computation
18+
19+
fnindirect<T:Trait>(){
20+
abi::<T>(None);
21+
}
22+
23+
fnmain(){
24+
indirect::<()>();
25+
}
Lines changed: 16 additions & 0 deletions
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)