-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 #78832 - lcnr:const-evaluatable-unevaluated, r=oli-obk
look at assoc ct, check the type of nodes an example where types matter are function objects, see the added test which previously passed. Now does a shallow comparison of unevaluated constants. r? ```@oli-obk```
- Loading branch information
Showing
4 changed files
with
78 additions
and
0 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
31 changes: 31 additions & 0 deletions
31
src/test/ui/const-generics/const_evaluatable_checked/associated-consts.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,31 @@ | ||
// run-pass | ||
#![feature(const_generics, const_evaluatable_checked)] | ||
#![allow(incomplete_features)] | ||
|
||
pub trait BlockCipher { | ||
const BLOCK_SIZE: usize; | ||
} | ||
|
||
struct FooCipher; | ||
impl BlockCipher for FooCipher { | ||
const BLOCK_SIZE: usize = 64; | ||
} | ||
|
||
struct BarCipher; | ||
impl BlockCipher for BarCipher { | ||
const BLOCK_SIZE: usize = 32; | ||
} | ||
|
||
pub struct Block<C>(C); | ||
|
||
pub fn test<C: BlockCipher, const M: usize>() | ||
where | ||
[u8; M - C::BLOCK_SIZE]: Sized, | ||
{ | ||
let _ = [0; M - C::BLOCK_SIZE]; | ||
} | ||
|
||
fn main() { | ||
test::<FooCipher, 128>(); | ||
test::<BarCipher, 64>(); | ||
} |
16 changes: 16 additions & 0 deletions
16
src/test/ui/const-generics/const_evaluatable_checked/different-fn.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,16 @@ | ||
#![feature(const_generics, const_evaluatable_checked)] | ||
#![allow(incomplete_features)] | ||
|
||
use std::mem::size_of; | ||
use std::marker::PhantomData; | ||
|
||
struct Foo<T>(PhantomData<T>); | ||
|
||
fn test<T>() -> [u8; size_of::<T>()] { | ||
[0; size_of::<Foo<T>>()] | ||
//~^ ERROR unconstrained generic constant | ||
} | ||
|
||
fn main() { | ||
test::<u32>(); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/test/ui/const-generics/const_evaluatable_checked/different-fn.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,14 @@ | ||
error: unconstrained generic constant | ||
--> $DIR/different-fn.rs:10:9 | ||
| | ||
LL | [0; size_of::<Foo<T>>()] | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: consider adding a `where` bound for this expression | ||
--> $DIR/different-fn.rs:10:9 | ||
| | ||
LL | [0; size_of::<Foo<T>>()] | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|