2018-08-30 12:18:55 +00:00
|
|
|
// run-pass
|
2018-09-25 21:51:35 +00:00
|
|
|
#![allow(dead_code)]
|
2015-01-15 06:54:51 +00:00
|
|
|
|
2019-04-22 11:53:52 +00:00
|
|
|
use std::fmt::Debug;
|
|
|
|
|
2015-01-15 06:54:51 +00:00
|
|
|
struct NT(str);
|
|
|
|
struct DST { a: u32, b: str }
|
|
|
|
|
2019-04-22 11:53:52 +00:00
|
|
|
macro_rules! check {
|
|
|
|
(val: $ty_of:expr, $expected:expr) => {
|
|
|
|
assert_eq!(type_name_of_val($ty_of), $expected);
|
|
|
|
};
|
|
|
|
($ty:ty, $expected:expr) => {
|
2019-04-18 02:38:17 +00:00
|
|
|
assert_eq!(std::any::type_name::<$ty>(), $expected);
|
2019-04-22 11:53:52 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-01-15 06:54:51 +00:00
|
|
|
fn main() {
|
2015-03-15 02:01:57 +00:00
|
|
|
// type_name should support unsized types
|
2019-04-22 11:53:52 +00:00
|
|
|
check!([u8], "[u8]");
|
|
|
|
check!(str, "str");
|
|
|
|
check!(dyn Send, "dyn core::marker::Send");
|
|
|
|
check!(NT, "issue_21058::NT");
|
|
|
|
check!(DST, "issue_21058::DST");
|
|
|
|
check!(&i32, "&i32");
|
|
|
|
check!(&'static i32, "&i32");
|
|
|
|
check!((i32, u32), "(i32, u32)");
|
|
|
|
check!(val: foo(), "issue_21058::Foo");
|
|
|
|
check!(val: Foo::new, "issue_21058::Foo::new");
|
|
|
|
check!(val:
|
|
|
|
<Foo as Debug>::fmt,
|
|
|
|
"<issue_21058::Foo as core::fmt::Debug>::fmt"
|
|
|
|
);
|
|
|
|
check!(val: || {}, "issue_21058::main::{{closure}}");
|
|
|
|
bar::<i32>();
|
|
|
|
}
|
|
|
|
|
|
|
|
trait Trait {
|
|
|
|
type Assoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Trait for i32 {
|
|
|
|
type Assoc = String;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bar<T: Trait>() {
|
|
|
|
check!(T::Assoc, "alloc::string::String");
|
|
|
|
check!(T, "i32");
|
|
|
|
}
|
|
|
|
|
|
|
|
fn type_name_of_val<T>(_: T) -> &'static str {
|
2019-04-18 02:38:17 +00:00
|
|
|
std::any::type_name::<T>()
|
2019-04-22 11:53:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
struct Foo;
|
|
|
|
|
|
|
|
impl Foo {
|
|
|
|
fn new() -> Self { Foo }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn foo() -> impl Debug {
|
|
|
|
Foo
|
2015-01-15 06:54:51 +00:00
|
|
|
}
|