-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #82447 - Amanieu:legacy_const_generics, r=oli-obk
Add #[rustc_legacy_const_generics] This is the first step towards removing `#[rustc_args_required_const]`: a new attribute is added which rewrites function calls of the form `func(a, b, c)` to `func::<{b}>(a, c)`. This allows previously stabilized functions in `stdarch` which use `rustc_args_required_const` to use const generics instead. This new attribute is not intended to ever be stabilized, it is only intended for use in `stdarch` as a replacement for `#[rustc_args_required_const]`. ```rust #[rustc_legacy_const_generics(1)] pub fn foo<const Y: usize>(x: usize, z: usize) -> [usize; 3] { [x, Y, z] } fn main() { assert_eq!(foo(0 + 0, 1 + 1, 2 + 2), [0, 2, 4]); assert_eq!(foo::<{1 + 1}>(0 + 0, 2 + 2), [0, 2, 4]); } ``` r? `@oli-obk`
- Loading branch information
Showing
16 changed files
with
429 additions
and
4 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
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] | ||
} |
File renamed without changes.
File renamed without changes.
38 changes: 38 additions & 0 deletions
38
src/test/ui/invalid/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,38 @@ | ||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_legacy_const_generics(0)] //~ ERROR #[rustc_legacy_const_generics] must have one index for | ||
fn foo1() {} | ||
|
||
#[rustc_legacy_const_generics(1)] //~ ERROR index exceeds number of arguments | ||
fn foo2<const X: usize>() {} | ||
|
||
#[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<const X: usize>() {} | ||
|
||
#[rustc_legacy_const_generics(1, a, 2, b)] //~ ERROR arguments should be non-negative integers | ||
fn foo5<const X: usize, const Y: usize, const Z: usize, const W: usize>() {} | ||
|
||
#[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<const X: usize>() {} | ||
|
||
extern { | ||
#[rustc_legacy_const_generics(1)] //~ ERROR attribute should be applied to a function | ||
fn foo7<const X: usize>(); //~ ERROR foreign items may not have const parameters | ||
} | ||
|
||
#[rustc_legacy_const_generics(0)] //~ ERROR #[rustc_legacy_const_generics] functions must only have | ||
fn foo8<X>() {} | ||
|
||
#[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() {} |
Oops, something went wrong.