-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve wf check for const param defaults
- Loading branch information
Showing
8 changed files
with
94 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
14 changes: 14 additions & 0 deletions
14
src/test/ui/const-generics/defaults/const-param-as-default-value.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,14 @@ | ||
// run-pass | ||
#![feature(const_generics_defaults)] | ||
#![allow(incomplete_features)] | ||
struct Foo<const N: usize, const M: usize = N>([u8; N], [u8; M]); | ||
|
||
fn foo<const N: usize>() -> Foo<N> { | ||
let x = [0; N]; | ||
Foo(x, x) | ||
} | ||
|
||
fn main() { | ||
let val = foo::<13>(); | ||
assert_eq!(val.0, val.1); | ||
} |
18 changes: 18 additions & 0 deletions
18
src/test/ui/const-generics/defaults/const-param-in-ty-defaults.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,18 @@ | ||
// run-pass | ||
#![feature(const_generics_defaults)] | ||
#![allow(incomplete_features)] | ||
// FIXME(const_generics_defaults): while we can allow this, | ||
// we probably won't easily allow this with more complex const operations. | ||
// | ||
// So we have to make a conscious decision here when stabilizing a relaxed parameter ordering. | ||
struct Foo<const N: usize, T = [u8; N]>(T); | ||
|
||
impl<const N: usize> Foo<N> { | ||
fn new() -> Self { | ||
Foo([0; N]) | ||
} | ||
} | ||
|
||
fn main() { | ||
assert_eq!(Foo::new().0, [0; 10]); | ||
} |
5 changes: 5 additions & 0 deletions
5
src/test/ui/const-generics/defaults/default-param-wf-concrete.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,5 @@ | ||
#![feature(const_generics_defaults)] | ||
#![allow(incomplete_features)] | ||
struct Foo<const N: u8 = { 255 + 1 }>; | ||
//~^ ERROR evaluation of constant value failed | ||
fn main() {} |
9 changes: 9 additions & 0 deletions
9
src/test/ui/const-generics/defaults/default-param-wf-concrete.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,9 @@ | ||
error[E0080]: evaluation of constant value failed | ||
--> $DIR/default-param-wf-concrete.rs:3:28 | ||
| | ||
LL | struct Foo<const N: u8 = { 255 + 1 }>; | ||
| ^^^^^^^ attempt to compute `u8::MAX + 1_u8`, which would overflow | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
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