Add tests for concrete const types

This commit is contained in:
ben 2019-05-05 08:41:39 +12:00
parent 3af1bdc4bc
commit bfa15f3988
4 changed files with 50 additions and 0 deletions

View File

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

View File

@ -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)]
| ^^^^^^^^^^^^^^

View File

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

View File

@ -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)]
| ^^^^^^^^^^^^^^