Skip to content

Stabilize type_name_of_val #118234

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Dec 15, 2023
Merged

Stabilize type_name_of_val #118234

merged 1 commit into from
Dec 15, 2023

Conversation

tgross35
Copy link
Contributor

@tgross35 tgross35 commented Nov 24, 2023

Make the following API stable:

// in core::any
pub fn type_name_of_val<T: ?Sized>(_val: &T) -> &'static str

This is a convenience method to get the type name of a value, as opposed to type_name that takes a type as a generic.

Const stability is not added because this relies on type_name which is also not const. That has a blocking issue #97156.

Wording was also changed to direct most of the details to type_name so we don't have as much duplicated documentation.

Fixes tracking issue #66359.

There were two main concerns in the tracking issue:

  1. Naming: type_name_of and type_name_of_val seem like the only mentioned options. Differences in opinion here come from std::mem::{size_of, align_of, size_of_val, align_of_val}. This PR leaves the name as type_name_of_val, but I can change if desired since it is pretty verbose.
  2. What this displays for &dyn: I don't think that having type_name_of_val function resolve those is worth the headache it would be, see Tracking issue for any::type_name_of_val #66359 (comment) for some workarounds. I also amended the docs wording to leave it open-ended, in case we have means to change that behavior in the future.

@rustbot label -T-libs +T-libs-api +needs-fcp
r? libs-api

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Nov 24, 2023
@tgross35
Copy link
Contributor Author

No rustbot, I said that already

@rustbot label -T-libs -T-compiler

@rustbot rustbot removed T-libs Relevant to the library team, which will review and decide on the PR/issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 24, 2023
@tgross35
Copy link
Contributor Author

cc implementer @lcnr

@jhpratt
Copy link
Member

jhpratt commented Nov 25, 2023

2. I don't think that having type_name_of_val function resolve those is worth the headache it would be,

Given that it's intended for diagnostics and the actual content isn't specified, I don't think is an issue at all. It can always be changed in the future.

Big 👍 on stabilization, though.

@dtolnay dtolnay assigned dtolnay and unassigned Amanieu Nov 25, 2023
Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FCP proposal: #66359 (comment)

@dtolnay dtolnay added S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 25, 2023
Make the following API stable:

    // in core::any
    pub fn type_name_of_val<T: ?Sized>(_val: &T) -> &'static str

Const stability is not added because this relies on `type_name` which is also
not const. That has a blocking issue.

Fixes rust-lang#66359
@dtolnay dtolnay removed the S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. label Dec 15, 2023
Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@dtolnay
Copy link
Member

dtolnay commented Dec 15, 2023

@bors r+

@bors
Copy link
Collaborator

bors commented Dec 15, 2023

📌 Commit b225aab has been approved by dtolnay

It is now in the queue for this repository.

@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Dec 15, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 15, 2023
…lnay

Stabilize `type_name_of_val`

Make the following API stable:

```rust
// in core::any
pub fn type_name_of_val<T: ?Sized>(_val: &T) -> &'static str
```

This is a convenience method to get the type name of a value, as opposed to `type_name` that takes a type as a generic.

Const stability is not added because this relies on `type_name` which is also not const. That has a blocking issue rust-lang#97156.

Wording was also changed to direct most of the details to `type_name` so we don't have as much duplicated documentation.

Fixes tracking issue rust-lang#66359.

There were two main concerns in the tracking issue:

1. Naming: `type_name_of` and `type_name_of_val` seem like the only mentioned options. Differences in opinion here come from `std::mem::{size_of, align_of, size_of_val, align_of_val}`. This PR leaves the name as `type_name_of_val`, but I can change if desired since it is pretty verbose.
2. What this displays for `&dyn`: I don't think that having `type_name_of_val` function resolve those is worth the headache it would be, see rust-lang#66359 (comment) for some workarounds. I also amended the docs wording to leave it open-ended, in case we have means to change that behavior in the future.

`@rustbot` label -T-libs +T-libs-api +needs-fcp
r? libs-api
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 15, 2023
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#117824 (Stabilize `ptr::{from_ref, from_mut}`)
 - rust-lang#118234 (Stabilize `type_name_of_val`)
 - rust-lang#118944 (Move type relations into submodule `relate` in rustc_infer, and notify when it has changed)
 - rust-lang#118977 (Simplify `src-script.js` code)
 - rust-lang#118985 (Remove `@JohnTitor` from diagnostics pings)
 - rust-lang#118986 (Simplify JS code a little bit)
 - rust-lang#118988 (rustdoc: add regression test for JS data file loading)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit ea6daca into rust-lang:master Dec 15, 2023
@rustbot rustbot added this to the 1.76.0 milestone Dec 15, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Dec 15, 2023
Rollup merge of rust-lang#118234 - tgross35:type_name_of_value, r=dtolnay

Stabilize `type_name_of_val`

Make the following API stable:

```rust
// in core::any
pub fn type_name_of_val<T: ?Sized>(_val: &T) -> &'static str
```

This is a convenience method to get the type name of a value, as opposed to `type_name` that takes a type as a generic.

Const stability is not added because this relies on `type_name` which is also not const. That has a blocking issue rust-lang#97156.

Wording was also changed to direct most of the details to `type_name` so we don't have as much duplicated documentation.

Fixes tracking issue rust-lang#66359.

There were two main concerns in the tracking issue:

1. Naming: `type_name_of` and `type_name_of_val` seem like the only mentioned options. Differences in opinion here come from `std::mem::{size_of, align_of, size_of_val, align_of_val}`. This PR leaves the name as `type_name_of_val`, but I can change if desired since it is pretty verbose.
2. What this displays for `&dyn`: I don't think that having `type_name_of_val` function resolve those is worth the headache it would be, see rust-lang#66359 (comment) for some workarounds. I also amended the docs wording to leave it open-ended, in case we have means to change that behavior in the future.

``@rustbot`` label -T-libs +T-libs-api +needs-fcp
r? libs-api
@tgross35 tgross35 deleted the type_name_of_value branch December 15, 2023 21:30
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
needs-fcp This change is insta-stable, so needs a completed FCP to proceed. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants