forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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`
- Loading branch information
Showing
2 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//@edition:2021 | ||
|
||
fn foo() { | ||
const { return } | ||
//~^ ERROR: return statement outside of function body | ||
} | ||
|
||
fn labelled_block_break() { | ||
'a: { const { break 'a } } | ||
//~^ ERROR: `break` outside of a loop or labeled block | ||
//~| ERROR: use of unreachable label | ||
} | ||
|
||
fn loop_break() { | ||
loop { | ||
const { break } | ||
//~^ ERROR: `break` outside of a loop or labeled block | ||
} | ||
} | ||
|
||
fn continue_to_labelled_block() { | ||
'a: { const { continue 'a } } | ||
//~^ ERROR: `continue` outside of a loop | ||
//~| ERROR: use of unreachable label | ||
} | ||
|
||
fn loop_continue() { | ||
loop { | ||
const { continue } | ||
//~^ ERROR: `continue` outside of a loop | ||
} | ||
} | ||
|
||
async fn await_across_const_block() { | ||
const { async {}.await } | ||
//~^ ERROR: `await` is only allowed inside `async` functions and blocks | ||
} | ||
|
||
fn reference_to_non_constant_in_const_block() { | ||
let x = 1; | ||
const { &x }; | ||
//~^ ERROR: attempt to use a non-constant value in a constant | ||
} | ||
|
||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
error[E0767]: use of unreachable label `'a` | ||
--> $DIR/cross_const_control_flow.rs:9:25 | ||
| | ||
LL | 'a: { const { break 'a } } | ||
| -- ^^ unreachable label `'a` | ||
| | | ||
| unreachable label defined here | ||
| | ||
= note: labels are unreachable through functions, closures, async blocks and modules | ||
|
||
error[E0767]: use of unreachable label `'a` | ||
--> $DIR/cross_const_control_flow.rs:22:28 | ||
| | ||
LL | 'a: { const { continue 'a } } | ||
| -- ^^ unreachable label `'a` | ||
| | | ||
| unreachable label defined here | ||
| | ||
= note: labels are unreachable through functions, closures, async blocks and modules | ||
|
||
error[E0435]: attempt to use a non-constant value in a constant | ||
--> $DIR/cross_const_control_flow.rs:41:14 | ||
| | ||
LL | const { &x }; | ||
| ^ non-constant value | ||
| | ||
help: consider using `const` instead of `let` | ||
| | ||
LL | const x: /* Type */ = 1; | ||
| ~~~~~ ++++++++++++ | ||
|
||
error[E0728]: `await` is only allowed inside `async` functions and blocks | ||
--> $DIR/cross_const_control_flow.rs:35:22 | ||
| | ||
LL | const { async {}.await } | ||
| -----------^^^^^-- | ||
| | | | ||
| | only allowed inside `async` functions and blocks | ||
| this is not `async` | ||
|
||
error[E0268]: `break` outside of a loop or labeled block | ||
--> $DIR/cross_const_control_flow.rs:9:19 | ||
| | ||
LL | 'a: { const { break 'a } } | ||
| ^^^^^^^^ cannot `break` outside of a loop or labeled block | ||
|
||
error[E0268]: `break` outside of a loop or labeled block | ||
--> $DIR/cross_const_control_flow.rs:16:17 | ||
| | ||
LL | const { break } | ||
| ^^^^^ cannot `break` outside of a loop or labeled block | ||
|
||
error[E0268]: `continue` outside of a loop | ||
--> $DIR/cross_const_control_flow.rs:22:19 | ||
| | ||
LL | 'a: { const { continue 'a } } | ||
| ^^^^^^^^^^^ cannot `continue` outside of a loop | ||
|
||
error[E0268]: `continue` outside of a loop | ||
--> $DIR/cross_const_control_flow.rs:29:17 | ||
| | ||
LL | const { continue } | ||
| ^^^^^^^^ cannot `continue` outside of a loop | ||
|
||
error[E0572]: return statement outside of function body | ||
--> $DIR/cross_const_control_flow.rs:4:13 | ||
| | ||
LL | / fn foo() { | ||
LL | | const { return } | ||
| | --^^^^^^-- the return is part of this body... | ||
LL | | | ||
LL | | } | ||
| |_- ...not the enclosing function body | ||
|
||
error: aborting due to 9 previous errors | ||
|
||
Some errors have detailed explanations: E0268, E0435, E0572, E0728, E0767. | ||
For more information about an error, try `rustc --explain E0268`. |