]> git.lizzy.rs Git - rust.git/blob - src/test/ui/return/issue-86188-return-not-in-fn-body.rs
Rollup merge of #100861 - RalfJung:const-ice, r=oli-obk
[rust.git] / src / test / ui / return / issue-86188-return-not-in-fn-body.rs
1 // Due to a compiler bug, if a return occurs outside of a function body
2 // (e.g. in an AnonConst body), the return value expression would not be
3 // type-checked, leading to an ICE. This test checks that the ICE no
4 // longer happens, and that an appropriate error message is issued that
5 // also explains why the return is considered "outside of a function body"
6 // if it seems to be inside one, as in the main function below.
7
8 const C: [(); 42] = {
9     [(); return || {
10     //~^ ERROR: return statement outside of function body [E0572]
11         let tx;
12     }]
13 };
14
15 struct S {}
16 trait Tr {
17     fn foo();
18     fn bar() {
19     //~^ NOTE: ...not the enclosing function body
20         [(); return];
21         //~^ ERROR: return statement outside of function body [E0572]
22         //~| NOTE: the return is part of this body...
23     }
24 }
25 impl Tr for S {
26     fn foo() {
27     //~^ NOTE: ...not the enclosing function body
28         [(); return];
29         //~^ ERROR: return statement outside of function body [E0572]
30         //~| NOTE: the return is part of this body...
31     }
32 }
33
34 fn main() {
35 //~^ NOTE: ...not the enclosing function body
36     [(); return || {
37     //~^ ERROR: return statement outside of function body [E0572]
38     //~| NOTE: the return is part of this body...
39         let tx;
40     }];
41 }