-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
310 additions
and
2 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_legacy_const_generics(1)] | ||
pub fn foo<const Y: usize>(x: usize, z: usize) -> [usize; 3] { | ||
[x, Y, z] | ||
} |
35 changes: 35 additions & 0 deletions
35
src/test/ui/invalid-rustc_legacy_const_generics-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,35 @@ | ||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_legacy_const_generics(0)] //~ ERROR index exceeds number of arguments | ||
fn foo1() {} | ||
|
||
#[rustc_legacy_const_generics(1)] //~ ERROR index exceeds number of arguments | ||
fn foo2(_: u8) {} | ||
|
||
#[rustc_legacy_const_generics(2)] //~ ERROR index exceeds number of arguments | ||
fn foo3<const X: usize>(_: u8) {} | ||
|
||
#[rustc_legacy_const_generics(a)] //~ ERROR arguments should be non-negative integers | ||
fn foo4() {} | ||
|
||
#[rustc_legacy_const_generics(1, a, 2, b)] //~ ERROR arguments should be non-negative integers | ||
fn foo5(_: u8, _: u8, _: u8) {} | ||
|
||
#[rustc_legacy_const_generics(0)] //~ ERROR attribute should be applied to a function | ||
struct S; | ||
|
||
#[rustc_legacy_const_generics(0usize)] //~ ERROR suffixed literals are not allowed in attributes | ||
fn foo6(_: u8) {} | ||
|
||
extern { | ||
#[rustc_legacy_const_generics(1)] //~ ERROR index exceeds number of arguments | ||
fn foo7(_: u8); | ||
} | ||
|
||
#[rustc_legacy_const_generics] //~ ERROR malformed `rustc_legacy_const_generics` attribute | ||
fn bar1() {} | ||
|
||
#[rustc_legacy_const_generics = 1] //~ ERROR malformed `rustc_legacy_const_generics` attribute | ||
fn bar2() {} | ||
|
||
fn main() {} |
66 changes: 66 additions & 0 deletions
66
src/test/ui/invalid-rustc_legacy_const_generics-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,66 @@ | ||
error: suffixed literals are not allowed in attributes | ||
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:21:31 | ||
| | ||
LL | #[rustc_legacy_const_generics(0usize)] | ||
| ^^^^^^ | ||
| | ||
= help: instead of using a suffixed literal (`1u8`, `1.0f32`, etc.), use an unsuffixed version (`1`, `1.0`, etc.) | ||
|
||
error: malformed `rustc_legacy_const_generics` attribute input | ||
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:29:1 | ||
| | ||
LL | #[rustc_legacy_const_generics] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_legacy_const_generics(N)]` | ||
|
||
error: malformed `rustc_legacy_const_generics` attribute input | ||
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:32:1 | ||
| | ||
LL | #[rustc_legacy_const_generics = 1] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_legacy_const_generics(N)]` | ||
|
||
error: index exceeds number of arguments | ||
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:3:31 | ||
| | ||
LL | #[rustc_legacy_const_generics(0)] | ||
| ^ there are only 0 arguments | ||
|
||
error: index exceeds number of arguments | ||
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:6:31 | ||
| | ||
LL | #[rustc_legacy_const_generics(1)] | ||
| ^ there is only 1 argument | ||
|
||
error: index exceeds number of arguments | ||
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:9:31 | ||
| | ||
LL | #[rustc_legacy_const_generics(2)] | ||
| ^ there are only 2 arguments | ||
|
||
error: arguments should be non-negative integers | ||
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:12:31 | ||
| | ||
LL | #[rustc_legacy_const_generics(a)] | ||
| ^ | ||
|
||
error: arguments should be non-negative integers | ||
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:15:34 | ||
| | ||
LL | #[rustc_legacy_const_generics(1, a, 2, b)] | ||
| ^ ^ | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:18:1 | ||
| | ||
LL | #[rustc_legacy_const_generics(0)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | struct S; | ||
| --------- not a function | ||
|
||
error: index exceeds number of arguments | ||
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:25:35 | ||
| | ||
LL | #[rustc_legacy_const_generics(1)] | ||
| ^ there is only 1 argument | ||
|
||
error: aborting due to 10 previous errors | ||
|
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,18 @@ | ||
// aux-build:legacy-const-generics.rs | ||
// run-pass | ||
|
||
#![feature(rustc_attrs)] | ||
|
||
extern crate legacy_const_generics; | ||
|
||
#[rustc_legacy_const_generics(1)] | ||
pub fn bar<const Y: usize>(x: usize, z: usize) -> [usize; 3] { | ||
[x, Y, z] | ||
} | ||
|
||
fn main() { | ||
assert_eq!(legacy_const_generics::foo(0 + 0, 1 + 1, 2 + 2), [0, 2, 4]); | ||
assert_eq!(legacy_const_generics::foo::<{1 + 1}>(0 + 0, 2 + 2), [0, 2, 4]); | ||
// TODO: Only works cross-crate | ||
//assert_eq!(bar(0, 1, 2), [0, 1, 2]); | ||
} |