Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The type_name of tuple-structs and their ZST function item are the same #84666

Closed
scottmcm opened this issue Apr 28, 2021 · 0 comments · Fixed by #85963
Closed

The type_name of tuple-structs and their ZST function item are the same #84666

scottmcm opened this issue Apr 28, 2021 · 0 comments · Fixed by #85963
Labels
C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@scottmcm
Copy link
Member

I tried this code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=f6fa0a5aa4d0a3d422c2db601a77c304

use std::any::type_name;

struct Velocity(f32, f32);

fn show_name<T>(_: T) {
    dbg!(type_name::<T>());
}

fn main() {
    show_name(Velocity);
    show_name(Velocity(0.0, -9.8));
}

I expected to see this happen:
The two names would be different, so that in logging I'd be able to notice I passed the wrong thing.

Instead, this happened:

[src/main.rs:6] type_name::<T>() = "playground::Velocity"
[src/main.rs:6] type_name::<T>() = "playground::Velocity"

Context:
This came up in the bevy discord server: https://discord.com/channels/691052431525675048/742884593551802431/836883497578397706

It allows you to put an instance of anything as a component on an entity, and get it back again later by type. So passing in a struct Marker; instance is fine -- and useful for filtering -- but it can't tell the difference between useful ZSTs like that and accidental ZSTs like Velocity where they meant to pass Velocity::new(). It would be nice for that to be at least available in debug logging, as a way to see what's available, but if that shows "Velocity" then it'd be particularly confusing when the "give me a ::<Velocity>()" doesn't work.

I'm not proposing any concrete string that this should return; it'd just be nice for it to be better distinguished.

@scottmcm scottmcm added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 28, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this issue Jun 3, 2021
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`
@bors bors closed this as completed in 0a12431 Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant