Skip to content

Commit

Permalink
Rollup merge of rust-lang#60550 - skinny121:concrete_const_tests, r=v…
Browse files Browse the repository at this point in the history
…arkor

Add tests for concrete const types

In response to the request for help in rust-lang#44580 (comment), I have added several ui tests around the use of concrete const types, i.e. A<2>.

r? @varkor
  • Loading branch information
Centril committed May 8, 2019
2 parents cfed892 + bfa15f3 commit 59ff113
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 59ff113

Please sign in to comment.