forked from rust-lang/rust
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
forbid generic params in complex consts
- Loading branch information
Showing
8 changed files
with
194 additions
and
18 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
37 changes: 37 additions & 0 deletions
37
src/test/ui/const-generics/min_const_generics/complex-expression.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,37 @@ | ||
#![feature(min_const_generics)] | ||
|
||
fn test<const N: usize>() {} | ||
|
||
fn ok<const M: usize>() -> [u8; M] { | ||
[0; { M }] | ||
} | ||
|
||
struct Break0<const N: usize>([u8; { N + 1 }]); | ||
//~^ ERROR generic parameters must not be used inside of non trivial constant values | ||
|
||
struct Break1<const N: usize>([u8; { { N } }]); | ||
//~^ ERROR generic parameters must not be used inside of non trivial constant values | ||
|
||
fn break2<const N: usize>() { | ||
let _: [u8; N + 1]; | ||
//~^ ERROR generic parameters must not be used inside of non trivial constant values | ||
} | ||
|
||
fn break3<const N: usize>() { | ||
let _ = [0; N + 1]; | ||
//~^ ERROR generic parameters must not be used inside of non trivial constant values | ||
} | ||
|
||
trait Foo { | ||
const ASSOC: usize; | ||
} | ||
|
||
impl<const N: usize> Foo for [u8; N] { | ||
const ASSOC: usize = N + 1; | ||
//~^ ERROR generic parameters must not be used inside of non trivial constant values | ||
// FIXME(min_const_generics): We probably have to allow this as we can | ||
// already allow referencing type parameters here on stable. | ||
} | ||
|
||
|
||
fn main() {} |
42 changes: 42 additions & 0 deletions
42
src/test/ui/const-generics/min_const_generics/complex-expression.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,42 @@ | ||
error: generic parameters must not be used inside of non trivial constant values | ||
--> $DIR/complex-expression.rs:9:38 | ||
| | ||
LL | struct Break0<const N: usize>([u8; { N + 1 }]); | ||
| ^ non-trivial anonymous constants must not depend on the parameter `N` | ||
| | ||
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants | ||
|
||
error: generic parameters must not be used inside of non trivial constant values | ||
--> $DIR/complex-expression.rs:12:40 | ||
| | ||
LL | struct Break1<const N: usize>([u8; { { N } }]); | ||
| ^ non-trivial anonymous constants must not depend on the parameter `N` | ||
| | ||
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants | ||
|
||
error: generic parameters must not be used inside of non trivial constant values | ||
--> $DIR/complex-expression.rs:16:17 | ||
| | ||
LL | let _: [u8; N + 1]; | ||
| ^ non-trivial anonymous constants must not depend on the parameter `N` | ||
| | ||
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants | ||
|
||
error: generic parameters must not be used inside of non trivial constant values | ||
--> $DIR/complex-expression.rs:21:17 | ||
| | ||
LL | let _ = [0; N + 1]; | ||
| ^ non-trivial anonymous constants must not depend on the parameter `N` | ||
| | ||
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants | ||
|
||
error: generic parameters must not be used inside of non trivial constant values | ||
--> $DIR/complex-expression.rs:30:26 | ||
| | ||
LL | const ASSOC: usize = N + 1; | ||
| ^ non-trivial anonymous constants must not depend on the parameter `N` | ||
| | ||
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants | ||
|
||
error: aborting due to 5 previous errors | ||
|
4 changes: 4 additions & 0 deletions
4
src/test/ui/const-generics/min_const_generics/feature-gate-min_const_generics.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,4 @@ | ||
fn test<const N: usize>() {} | ||
//~^ ERROR const generics are unstable | ||
|
||
fn main() {} |
12 changes: 12 additions & 0 deletions
12
src/test/ui/const-generics/min_const_generics/feature-gate-min_const_generics.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,12 @@ | ||
error[E0658]: const generics are unstable | ||
--> $DIR/feature-gate-min_const_generics.rs:1:15 | ||
| | ||
LL | fn test<const N: usize>() {} | ||
| ^ | ||
| | ||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information | ||
= help: add `#![feature(const_generics)]` to the crate attributes to enable | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0658`. |