-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add #[rustc_legacy_const_generics] #82447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d87eec1
Add #[rustc_legacy_const_generics]
Amanieu e604d01
Move tests to subdirectory
Amanieu 69cde44
TODO -> FIXME
Amanieu 00eca69
Properly reject non-const arguments
Amanieu 2451f12
Address review comments
Amanieu cccd779
Fix tests
Amanieu 22184a0
Add a cache for rustc_legacy_const_generics
Amanieu 00afbe7
Improve checking for attribute
Amanieu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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] | ||
} | ||
Amanieu marked this conversation as resolved.
Show resolved
Hide resolved
|
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions
35
src/test/ui/invalid/invalid-rustc_legacy_const_generics-arguments.rs
This file contains hidden or 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/invalid-rustc_legacy_const_generics-arguments.stderr
This file contains hidden or 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 hidden or 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]); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.