blob: 73bfa803acd2c08ef559be9b52df1fc5c60ccaa9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
// check-pass
// Basic usage patterns of free & associated generic const items.
#![feature(generic_const_items)]
#![allow(incomplete_features)]
fn main() {
const NULL<T>: Option<T> = None::<T>;
const NOTHING<T>: Option<T> = None; // arg inferred
let _ = NOTHING::<String>;
let _: Option<u8> = NULL; // arg inferred
const IDENTITY<const X: u64>: u64 = X;
const COUNT: u64 = IDENTITY::<48>;
const AMOUNT: u64 = IDENTITY::<COUNT>;
const NUMBER: u64 = IDENTITY::<{ AMOUNT * 2 }>;
let _ = NUMBER;
let _ = IDENTITY::<0>;
let _ = match 0 {
IDENTITY::<1> => 2,
IDENTITY::<{ 1 + 1 }> => 4,
_ => 0,
};
const CREATE<I: Inhabited>: I = I::PROOF;
let _ = CREATE::<u64>;
let _: u64 = CREATE; // arg inferred
let _ = <() as Main<u64>>::MAKE::<u64>;
let _: (u64, u64) = <()>::MAKE; // args inferred
}
pub fn usage<'any>() {
const REGION_POLY<'a>: &'a () = &();
let _: &'any () = REGION_POLY::<'any>;
let _: &'any () = REGION_POLY::<'_>;
let _: &'static () = REGION_POLY;
}
trait Main<O> {
type Output<I>;
const MAKE<I: Inhabited>: Self::Output<I>;
}
impl<O: Inhabited> Main<O> for () {
type Output<I> = (O, I);
const MAKE<I: Inhabited>: Self::Output<I> = (O::PROOF, I::PROOF);
}
trait Inhabited {
const PROOF: Self;
}
impl Inhabited for u64 {
const PROOF: Self = 512;
}
|