diff options
| author | Amanieu d'Antras <amanieu@gmail.com> | 2021-02-23 15:12:28 +0000 |
|---|---|---|
| committer | Amanieu d'Antras <amanieu@gmail.com> | 2021-02-23 17:25:55 +0000 |
| commit | d87eec1bf67959977c8ebaadc2ddcf4bdc14658a (patch) | |
| tree | 1f777c2c1702ec27d57c346a8c9f7c1b876df372 /src | |
| parent | 9b471a3f5fe57e5c6e08acf665f2094422415a3d (diff) | |
| download | rust-d87eec1bf67959977c8ebaadc2ddcf4bdc14658a.tar.gz rust-d87eec1bf67959977c8ebaadc2ddcf4bdc14658a.zip | |
Add #[rustc_legacy_const_generics]
Diffstat (limited to 'src')
4 files changed, 125 insertions, 0 deletions
diff --git a/src/test/ui/auxiliary/legacy-const-generics.rs b/src/test/ui/auxiliary/legacy-const-generics.rs new file mode 100644 index 00000000000..67352a2fbbb --- /dev/null +++ b/src/test/ui/auxiliary/legacy-const-generics.rs @@ -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] +} diff --git a/src/test/ui/invalid-rustc_legacy_const_generics-arguments.rs b/src/test/ui/invalid-rustc_legacy_const_generics-arguments.rs new file mode 100644 index 00000000000..e044cd7a1f5 --- /dev/null +++ b/src/test/ui/invalid-rustc_legacy_const_generics-arguments.rs @@ -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() {} diff --git a/src/test/ui/invalid-rustc_legacy_const_generics-arguments.stderr b/src/test/ui/invalid-rustc_legacy_const_generics-arguments.stderr new file mode 100644 index 00000000000..92fad679257 --- /dev/null +++ b/src/test/ui/invalid-rustc_legacy_const_generics-arguments.stderr @@ -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 + diff --git a/src/test/ui/legacy-const-generics.rs b/src/test/ui/legacy-const-generics.rs new file mode 100644 index 00000000000..00ab4b6cccf --- /dev/null +++ b/src/test/ui/legacy-const-generics.rs @@ -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]); +} |
