Skip to content

Commit 59ff113

Browse files
authored
Rollup merge of rust-lang#60550 - skinny121:concrete_const_tests, r=varkor
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
2 parents cfed892 + bfa15f3 commit 59ff113

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Test that a concrete const type i.e. A<2>, can be used as an argument type in a function
2+
// run-pass
3+
4+
#![feature(const_generics)]
5+
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
6+
7+
struct A<const N: usize>; // ok
8+
9+
fn with_concrete_const_arg(_: A<2>) -> u32 { 17 }
10+
11+
fn main() {
12+
let val: A<2> = A;
13+
assert_eq!(with_concrete_const_arg(val), 17);
14+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
2+
--> $DIR/concrete-const-as-fn-arg.rs:4:12
3+
|
4+
LL | #![feature(const_generics)]
5+
| ^^^^^^^^^^^^^^
6+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Test that a method/associated non-method within an impl block of a concrete const type i.e. A<2>,
2+
// is callable.
3+
// run-pass
4+
5+
#![feature(const_generics)]
6+
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
7+
8+
pub struct A<const N: u32>;
9+
10+
impl A<2> {
11+
fn impl_method(&self) -> u32 {
12+
17
13+
}
14+
15+
fn associated_non_method() -> u32 {
16+
17
17+
}
18+
}
19+
20+
fn main() {
21+
let val: A<2> = A;
22+
assert_eq!(val.impl_method(), 17);
23+
assert_eq!(A::<2>::associated_non_method(), 17);
24+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
2+
--> $DIR/concrete-const-impl-method.rs:5:12
3+
|
4+
LL | #![feature(const_generics)]
5+
| ^^^^^^^^^^^^^^
6+

0 commit comments

Comments
 (0)