forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
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#77343 - varkor:rustc_args_required_const-va…
…lidation, r=lcnr Validate `rustc_args_required_const` Fixes rust-lang#74608.
- Loading branch information
Showing
4 changed files
with
176 additions
and
10 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
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
26 changes: 26 additions & 0 deletions
26
src/test/ui/invalid-rustc_args_required_const-arguments.rs
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,26 @@ | ||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_args_required_const(0)] //~ ERROR index exceeds number of arguments | ||
fn foo1() {} | ||
|
||
#[rustc_args_required_const(1)] //~ ERROR index exceeds number of arguments | ||
fn foo2(_: u8) {} | ||
|
||
#[rustc_args_required_const(a)] //~ ERROR arguments should be non-negative integers | ||
fn foo4() {} | ||
|
||
#[rustc_args_required_const(1, a, 2, b)] //~ ERROR arguments should be non-negative integers | ||
fn foo5(_: u8, _: u8, _: u8) {} | ||
|
||
#[rustc_args_required_const(0)] //~ ERROR attribute should be applied to a function | ||
struct S; | ||
|
||
#[rustc_args_required_const(0usize)] //~ ERROR suffixed literals are not allowed in attributes | ||
fn foo6(_: u8) {} | ||
|
||
extern { | ||
#[rustc_args_required_const(1)] //~ ERROR index exceeds number of arguments | ||
fn foo7(_: u8); | ||
} | ||
|
||
fn main() {} |
48 changes: 48 additions & 0 deletions
48
src/test/ui/invalid-rustc_args_required_const-arguments.stderr
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,48 @@ | ||
error: suffixed literals are not allowed in attributes | ||
--> $DIR/invalid-rustc_args_required_const-arguments.rs:18:29 | ||
| | ||
LL | #[rustc_args_required_const(0usize)] | ||
| ^^^^^^ | ||
| | ||
= help: instead of using a suffixed literal (`1u8`, `1.0f32`, etc.), use an unsuffixed version (`1`, `1.0`, etc.) | ||
|
||
error: index exceeds number of arguments | ||
--> $DIR/invalid-rustc_args_required_const-arguments.rs:3:29 | ||
| | ||
LL | #[rustc_args_required_const(0)] | ||
| ^ there are only 0 arguments | ||
|
||
error: index exceeds number of arguments | ||
--> $DIR/invalid-rustc_args_required_const-arguments.rs:6:29 | ||
| | ||
LL | #[rustc_args_required_const(1)] | ||
| ^ there is only 1 argument | ||
|
||
error: arguments should be non-negative integers | ||
--> $DIR/invalid-rustc_args_required_const-arguments.rs:9:29 | ||
| | ||
LL | #[rustc_args_required_const(a)] | ||
| ^ | ||
|
||
error: arguments should be non-negative integers | ||
--> $DIR/invalid-rustc_args_required_const-arguments.rs:12:32 | ||
| | ||
LL | #[rustc_args_required_const(1, a, 2, b)] | ||
| ^ ^ | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid-rustc_args_required_const-arguments.rs:15:1 | ||
| | ||
LL | #[rustc_args_required_const(0)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | struct S; | ||
| --------- not a function | ||
|
||
error: index exceeds number of arguments | ||
--> $DIR/invalid-rustc_args_required_const-arguments.rs:22:33 | ||
| | ||
LL | #[rustc_args_required_const(1)] | ||
| ^ there is only 1 argument | ||
|
||
error: aborting due to 7 previous errors | ||
|