Skip to content

Commit 67b3fde

Browse files
authored
Add a test, as suggested.
1 parent 271cf97 commit 67b3fde

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// run-pass
2+
3+
#![feature(core_intrinsics)]
4+
#![feature(const_fn)]
5+
#![allow(dead_code)]
6+
7+
const fn type_name_wrapper<T>(_: &T) -> &'static str {
8+
unsafe { std::intrinsics::type_name::<T>() }
9+
}
10+
11+
struct Struct<TA, TB, TC> {
12+
a: TA,
13+
b: TB,
14+
c: TC,
15+
}
16+
17+
type StructInstantiation = Struct<i8, f64, bool>;
18+
19+
const CONST_STRUCT: StructInstantiation = StructInstantiation {
20+
a: 12,
21+
b: 13.7,
22+
c: false,
23+
};
24+
25+
const CONST_STRUCT_NAME: &'static str = type_name_wrapper(&CONST_STRUCT);
26+
27+
fn main() {
28+
println!("{}", CONST_STRUCT_NAME);
29+
30+
let non_const_struct = StructInstantiation {
31+
a: 87,
32+
b: 65.99,
33+
c: true,
34+
};
35+
let non_const_struct_name = type_name_wrapper(&non_const_struct);
36+
37+
println!("{}", non_const_struct_name);
38+
}

0 commit comments

Comments
 (0)