look at assoc ct, check the type of nodes

This commit is contained in:
Bastian Kauschke 2020-11-07 12:37:28 +01:00
parent 0256d065d4
commit 439171e094
4 changed files with 78 additions and 0 deletions

View file

@ -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>();
}

View file

@ -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>();
}

View file

@ -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