]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-21058.rs
Merge commit '6ed6f1e6a1a8f414ba7e6d9b8222e7e5a1686e42' into clippyup
[rust.git] / src / test / ui / issues / issue-21058.rs
1 // run-pass
2 #![allow(dead_code)]
3
4 use std::fmt::Debug;
5
6 struct NT(str);
7 struct DST { a: u32, b: str }
8
9 macro_rules! check {
10     (val: $ty_of:expr, $expected:expr) => {
11         assert_eq!(type_name_of_val($ty_of), $expected);
12     };
13     ($ty:ty, $expected:expr) => {
14         assert_eq!(std::any::type_name::<$ty>(), $expected);
15     };
16 }
17
18 fn main() {
19     // type_name should support unsized types
20     check!([u8], "[u8]");
21     check!(str, "str");
22     check!(dyn Send, "dyn core::marker::Send");
23     check!(NT, "issue_21058::NT");
24     check!(DST, "issue_21058::DST");
25     check!(&i32, "&i32");
26     check!(&'static i32, "&i32");
27     check!((i32, u32), "(i32, u32)");
28     check!(val: foo(), "issue_21058::Foo");
29     check!(val: Foo::new, "issue_21058::Foo::new");
30     check!(val:
31         <Foo as Debug>::fmt,
32         "<issue_21058::Foo as core::fmt::Debug>::fmt"
33     );
34     check!(val: || {}, "issue_21058::main::{{closure}}");
35     bar::<i32>();
36 }
37
38 trait Trait {
39     type Assoc;
40 }
41
42 impl Trait for i32 {
43     type Assoc = String;
44 }
45
46 fn bar<T: Trait>() {
47     check!(T::Assoc, "alloc::string::String");
48     check!(T, "i32");
49 }
50
51 fn type_name_of_val<T>(_: T) -> &'static str {
52     std::any::type_name::<T>()
53 }
54
55 #[derive(Debug)]
56 struct Foo;
57
58 impl Foo {
59     fn new() -> Self { Foo }
60 }
61
62 fn foo() -> impl Debug {
63     Foo
64 }