Skip to content

Commit

Permalink
Add tests for concrete const types
Browse files Browse the repository at this point in the history
  • Loading branch information
skinnyBat committed May 8, 2019
1 parent 3af1bdc commit bfa15f3
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/test/ui/const-generics/concrete-const-as-fn-arg.rs
Original file line number Diff line number Diff line change
@@ -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);
}
6 changes: 6 additions & 0 deletions src/test/ui/const-generics/concrete-const-as-fn-arg.stderr
Original file line number Diff line number Diff line change
@@ -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)]
| ^^^^^^^^^^^^^^

24 changes: 24 additions & 0 deletions src/test/ui/const-generics/concrete-const-impl-method.rs
Original file line number Diff line number Diff line change
@@ -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);
}
6 changes: 6 additions & 0 deletions src/test/ui/const-generics/concrete-const-impl-method.stderr
Original file line number Diff line number Diff line change
@@ -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)]
| ^^^^^^^^^^^^^^

0 comments on commit bfa15f3

Please sign in to comment.