diff options
| author | Zachary Catlin <z@zc.is> | 2020-11-11 21:17:45 -0500 |
|---|---|---|
| committer | Zachary Catlin <z@zc.is> | 2020-11-11 21:17:45 -0500 |
| commit | e4a43fce3bdf7959408c186e1d3f21bf0400b546 (patch) | |
| tree | f3aba9acfef6009d54d1e9d63fec905b1e76f0e0 /src/test/ui | |
| parent | 562d50eb7b67109ca420eab8705673b138863e6a (diff) | |
| parent | 77180db6f81ffdacd14545f1df0a5db55dac1706 (diff) | |
| download | rust-e4a43fce3bdf7959408c186e1d3f21bf0400b546.tar.gz rust-e4a43fce3bdf7959408c186e1d3f21bf0400b546.zip | |
Merge changes from rust-lang/rust
Diffstat (limited to 'src/test/ui')
3 files changed, 61 insertions, 0 deletions
diff --git a/src/test/ui/const-generics/const_evaluatable_checked/associated-consts.rs b/src/test/ui/const-generics/const_evaluatable_checked/associated-consts.rs new file mode 100644 index 00000000000..533fe55b45b --- /dev/null +++ b/src/test/ui/const-generics/const_evaluatable_checked/associated-consts.rs @@ -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>(); +} diff --git a/src/test/ui/const-generics/const_evaluatable_checked/different-fn.rs b/src/test/ui/const-generics/const_evaluatable_checked/different-fn.rs new file mode 100644 index 00000000000..05049d9c2a6 --- /dev/null +++ b/src/test/ui/const-generics/const_evaluatable_checked/different-fn.rs @@ -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>(); +} diff --git a/src/test/ui/const-generics/const_evaluatable_checked/different-fn.stderr b/src/test/ui/const-generics/const_evaluatable_checked/different-fn.stderr new file mode 100644 index 00000000000..1f6dddb04e5 --- /dev/null +++ b/src/test/ui/const-generics/const_evaluatable_checked/different-fn.stderr @@ -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 + |
