Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for concrete const types #60550

Merged
merged 1 commit into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)]
| ^^^^^^^^^^^^^^