Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 04c626b

Browse files
authoredNov 14, 2024
Unrolled build for rust-lang#133012
Rollup merge of rust-lang#133012 - Eclips4:issue-125670, r=compiler-errors Add test cases for rust-lang#125918 Closes rust-lang#125670 r? `@jieyouxu`
2 parents 22bcb81 + 7347bee commit 04c626b

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//@edition:2021
2+
3+
fn foo() {
4+
const { return }
5+
//~^ ERROR: return statement outside of function body
6+
}
7+
8+
fn labelled_block_break() {
9+
'a: { const { break 'a } }
10+
//~^ ERROR: `break` outside of a loop or labeled block
11+
//~| ERROR: use of unreachable label
12+
}
13+
14+
fn loop_break() {
15+
loop {
16+
const { break }
17+
//~^ ERROR: `break` outside of a loop or labeled block
18+
}
19+
}
20+
21+
fn continue_to_labelled_block() {
22+
'a: { const { continue 'a } }
23+
//~^ ERROR: `continue` outside of a loop
24+
//~| ERROR: use of unreachable label
25+
}
26+
27+
fn loop_continue() {
28+
loop {
29+
const { continue }
30+
//~^ ERROR: `continue` outside of a loop
31+
}
32+
}
33+
34+
async fn await_across_const_block() {
35+
const { async {}.await }
36+
//~^ ERROR: `await` is only allowed inside `async` functions and blocks
37+
}
38+
39+
fn reference_to_non_constant_in_const_block() {
40+
let x = 1;
41+
const { &x };
42+
//~^ ERROR: attempt to use a non-constant value in a constant
43+
}
44+
45+
46+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
error[E0767]: use of unreachable label `'a`
2+
--> $DIR/cross_const_control_flow.rs:9:25
3+
|
4+
LL | 'a: { const { break 'a } }
5+
| -- ^^ unreachable label `'a`
6+
| |
7+
| unreachable label defined here
8+
|
9+
= note: labels are unreachable through functions, closures, async blocks and modules
10+
11+
error[E0767]: use of unreachable label `'a`
12+
--> $DIR/cross_const_control_flow.rs:22:28
13+
|
14+
LL | 'a: { const { continue 'a } }
15+
| -- ^^ unreachable label `'a`
16+
| |
17+
| unreachable label defined here
18+
|
19+
= note: labels are unreachable through functions, closures, async blocks and modules
20+
21+
error[E0435]: attempt to use a non-constant value in a constant
22+
--> $DIR/cross_const_control_flow.rs:41:14
23+
|
24+
LL | const { &x };
25+
| ^ non-constant value
26+
|
27+
help: consider using `const` instead of `let`
28+
|
29+
LL | const x: /* Type */ = 1;
30+
| ~~~~~ ++++++++++++
31+
32+
error[E0728]: `await` is only allowed inside `async` functions and blocks
33+
--> $DIR/cross_const_control_flow.rs:35:22
34+
|
35+
LL | const { async {}.await }
36+
| -----------^^^^^--
37+
| | |
38+
| | only allowed inside `async` functions and blocks
39+
| this is not `async`
40+
41+
error[E0268]: `break` outside of a loop or labeled block
42+
--> $DIR/cross_const_control_flow.rs:9:19
43+
|
44+
LL | 'a: { const { break 'a } }
45+
| ^^^^^^^^ cannot `break` outside of a loop or labeled block
46+
47+
error[E0268]: `break` outside of a loop or labeled block
48+
--> $DIR/cross_const_control_flow.rs:16:17
49+
|
50+
LL | const { break }
51+
| ^^^^^ cannot `break` outside of a loop or labeled block
52+
53+
error[E0268]: `continue` outside of a loop
54+
--> $DIR/cross_const_control_flow.rs:22:19
55+
|
56+
LL | 'a: { const { continue 'a } }
57+
| ^^^^^^^^^^^ cannot `continue` outside of a loop
58+
59+
error[E0268]: `continue` outside of a loop
60+
--> $DIR/cross_const_control_flow.rs:29:17
61+
|
62+
LL | const { continue }
63+
| ^^^^^^^^ cannot `continue` outside of a loop
64+
65+
error[E0572]: return statement outside of function body
66+
--> $DIR/cross_const_control_flow.rs:4:13
67+
|
68+
LL | / fn foo() {
69+
LL | | const { return }
70+
| | --^^^^^^-- the return is part of this body...
71+
LL | |
72+
LL | | }
73+
| |_- ...not the enclosing function body
74+
75+
error: aborting due to 9 previous errors
76+
77+
Some errors have detailed explanations: E0268, E0435, E0572, E0728, E0767.
78+
For more information about an error, try `rustc --explain E0268`.

0 commit comments

Comments
 (0)
Failed to load comments.