diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-05-09 00:58:25 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-05-09 00:58:25 +0200 |
| commit | 59ff11393dc1b55ddd87ae717c052eaa17d3d3d3 (patch) | |
| tree | 4516c3fcfe02c898f6d865e132d42005bd60f0fa | |
| parent | cfed892cb37ef5f1dce29d2e38d3a2eb9f86bb53 (diff) | |
| parent | bfa15f39888a514f1eb164e210cf5d85b33146e1 (diff) | |
| download | rust-59ff11393dc1b55ddd87ae717c052eaa17d3d3d3.tar.gz rust-59ff11393dc1b55ddd87ae717c052eaa17d3d3d3.zip | |
Rollup merge of #60550 - skinny121:concrete_const_tests, r=varkor
Add tests for concrete const types In response to the request for help in https://github.com/rust-lang/rust/issues/44580#issuecomment-488819344, I have added several ui tests around the use of concrete const types, i.e. A<2>. r? @varkor
4 files changed, 50 insertions, 0 deletions
diff --git a/src/test/ui/const-generics/concrete-const-as-fn-arg.rs b/src/test/ui/const-generics/concrete-const-as-fn-arg.rs new file mode 100644 index 00000000000..54981b77a2b --- /dev/null +++ b/src/test/ui/const-generics/concrete-const-as-fn-arg.rs @@ -0,0 +1,14 @@ +// Test that a concrete const type i.e. A<2>, can be used as an argument type in a function +// run-pass + +#![feature(const_generics)] +//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash + +struct A<const N: usize>; // ok + +fn with_concrete_const_arg(_: A<2>) -> u32 { 17 } + +fn main() { + let val: A<2> = A; + assert_eq!(with_concrete_const_arg(val), 17); +} diff --git a/src/test/ui/const-generics/concrete-const-as-fn-arg.stderr b/src/test/ui/const-generics/concrete-const-as-fn-arg.stderr new file mode 100644 index 00000000000..955b319d700 --- /dev/null +++ b/src/test/ui/const-generics/concrete-const-as-fn-arg.stderr @@ -0,0 +1,6 @@ +warning: the feature `const_generics` is incomplete and may cause the compiler to crash + --> $DIR/concrete-const-as-fn-arg.rs:4:12 + | +LL | #![feature(const_generics)] + | ^^^^^^^^^^^^^^ + diff --git a/src/test/ui/const-generics/concrete-const-impl-method.rs b/src/test/ui/const-generics/concrete-const-impl-method.rs new file mode 100644 index 00000000000..226ea415180 --- /dev/null +++ b/src/test/ui/const-generics/concrete-const-impl-method.rs @@ -0,0 +1,24 @@ +// Test that a method/associated non-method within an impl block of a concrete const type i.e. A<2>, +// is callable. +// run-pass + +#![feature(const_generics)] +//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash + +pub struct A<const N: u32>; + +impl A<2> { + fn impl_method(&self) -> u32 { + 17 + } + + fn associated_non_method() -> u32 { + 17 + } +} + +fn main() { + let val: A<2> = A; + assert_eq!(val.impl_method(), 17); + assert_eq!(A::<2>::associated_non_method(), 17); +} diff --git a/src/test/ui/const-generics/concrete-const-impl-method.stderr b/src/test/ui/const-generics/concrete-const-impl-method.stderr new file mode 100644 index 00000000000..3ce488c6275 --- /dev/null +++ b/src/test/ui/const-generics/concrete-const-impl-method.stderr @@ -0,0 +1,6 @@ +warning: the feature `const_generics` is incomplete and may cause the compiler to crash + --> $DIR/concrete-const-impl-method.rs:5:12 + | +LL | #![feature(const_generics)] + | ^^^^^^^^^^^^^^ + |
