Skip to content

Commit fd252e3

Browse files
authored
Rollup merge of rust-lang#85963 - m-ou-se:constructor-type-name, r=yaahc
Show `::{{constructor}}` in std::any::type_name(). Fix rust-lang#84666 Before: ``` [src/main.rs:6] type_name::<T>() = "playground::Velocity" [src/main.rs:6] type_name::<T>() = "playground::Velocity" ``` After: ``` [src/main.rs:6] type_name::<T>() = "scratchpad::Velocity::{{constructor}}" [src/main.rs:6] type_name::<T>() = "scratchpad::Velocity" ``` cc ``@scottmcm``
2 parents 5c537c2 + 015ade4 commit fd252e3

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

core/tests/any.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,16 @@ fn any_unsized() {
114114
fn is_any<T: Any + ?Sized>() {}
115115
is_any::<[i32]>();
116116
}
117+
118+
#[test]
119+
fn distinct_type_names() {
120+
// https://github.com/rust-lang/rust/issues/84666
121+
122+
struct Velocity(f32, f32);
123+
124+
fn type_name_of_val<T>(_: T) -> &'static str {
125+
type_name::<T>()
126+
}
127+
128+
assert_ne!(type_name_of_val(Velocity), type_name_of_val(Velocity(0.0, -9.8)),);
129+
}

0 commit comments

Comments
 (0)