forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#76559 - lcnr:const-evaluatable, r=oli-obk
add the `const_evaluatable_checked` feature Implements a rather small subset of rust-lang/compiler-team#340 Unlike the MCP, this does not try to compare different constant, but instead only adds the constants found in where clauses to the predicates of a function. This PR adds the feature gate `const_evaluatable_checked`, without which nothing should change. r? @oli-obk @eddyb
- Loading branch information
Showing
9 changed files
with
137 additions
and
17 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
14 changes: 14 additions & 0 deletions
14
...est/ui/const-generics/const_evaluatable_checked/feature-gate-const_evaluatable_checked.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 @@ | ||
#![feature(const_generics)] | ||
#![allow(incomplete_features)] | ||
|
||
type Arr<const N: usize> = [u8; N - 1]; | ||
|
||
fn test<const N: usize>() -> Arr<N> where Arr<N>: Default { | ||
//~^ ERROR constant expression depends | ||
Default::default() | ||
} | ||
|
||
fn main() { | ||
let x = test::<33>(); | ||
assert_eq!(x, [0; 32]); | ||
} |
10 changes: 10 additions & 0 deletions
10
...ui/const-generics/const_evaluatable_checked/feature-gate-const_evaluatable_checked.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,10 @@ | ||
error: constant expression depends on a generic parameter | ||
--> $DIR/feature-gate-const_evaluatable_checked.rs:6:30 | ||
| | ||
LL | fn test<const N: usize>() -> Arr<N> where Arr<N>: Default { | ||
| ^^^^^^ | ||
| | ||
= note: this may fail depending on what value the parameter takes | ||
|
||
error: aborting due to previous error | ||
|
14 changes: 14 additions & 0 deletions
14
src/test/ui/const-generics/const_evaluatable_checked/simple.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, const_evaluatable_checked)] | ||
#![allow(incomplete_features)] | ||
|
||
type Arr<const N: usize> = [u8; N - 1]; | ||
|
||
fn test<const N: usize>() -> Arr<N> where Arr<N>: Default { | ||
Default::default() | ||
} | ||
|
||
fn main() { | ||
let x = test::<33>(); | ||
assert_eq!(x, [0; 32]); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/test/ui/const-generics/const_evaluatable_checked/simple_fail.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,12 @@ | ||
#![feature(const_generics, const_evaluatable_checked)] | ||
#![allow(incomplete_features)] | ||
|
||
type Arr<const N: usize> = [u8; N - 1]; //~ ERROR evaluation of constant | ||
|
||
fn test<const N: usize>() -> Arr<N> where Arr<N>: Sized { | ||
todo!() | ||
} | ||
|
||
fn main() { | ||
test::<0>(); | ||
} |
9 changes: 9 additions & 0 deletions
9
src/test/ui/const-generics/const_evaluatable_checked/simple_fail.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/simple_fail.rs:4:33 | ||
| | ||
LL | type Arr<const N: usize> = [u8; N - 1]; | ||
| ^^^^^ attempt to compute `0_usize - 1_usize` which would overflow | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. |