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

add fn type_name_of_val #65961

Merged
merged 1 commit into from
Nov 23, 2019
Merged

add fn type_name_of_val #65961

merged 1 commit into from
Nov 23, 2019

Conversation

lcnr
Copy link
Contributor

@lcnr lcnr commented Oct 30, 2019

This function is often useful during testing and mirrors align_of_val and size_of_val.

Example

Showing the default type of integers.

let x = 7;
println!("per default, integers have the type: {}", std::any::type_name_of_val(&x));

To my knowledge this can currently not be done without defining a function similar to type_name_of_val.

@rust-highfive
Copy link
Collaborator

r? @shepmaster

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 30, 2019
@lcnr
Copy link
Contributor Author

lcnr commented Oct 30, 2019

One alternative is type_name_of(&x) instead of type_name_of_val(&x).
type_name_of is shorter but is inconsistent with size_of and align_of, as they both do not need a function argument.

@joelpalmer
Copy link

Ping from Triage: any updates @shepmaster @lcnr?

@JohnCSimon
Copy link
Member

Pinging again from triage:
@shepmaster Can you please review this PR?
CC: @lcnr

Thanks!

@shepmaster
Copy link
Member

This seems reasonable enough to add an unstable method. Would you open a tracking issue and update the attribute to refer to it?

@Dylan-DPC-zz Dylan-DPC-zz added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 11, 2019
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-11-13T09:49:06.1053533Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-11-13T09:49:06.1264888Z ##[command]git config gc.auto 0
2019-11-13T09:49:06.1328627Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-11-13T09:49:06.1379007Z ##[command]git config --get-all http.proxy
2019-11-13T09:49:06.1515684Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/65961/merge:refs/remotes/pull/65961/merge
---
2019-11-13T10:44:40.8296007Z .................................................................................................... 1500/9234
2019-11-13T10:44:46.3520569Z .................................................................................................... 1600/9234
2019-11-13T10:44:54.7466195Z .................................................................................................... 1700/9234
2019-11-13T10:45:02.5740813Z ...i................................................................................................ 1800/9234
2019-11-13T10:45:08.7872523Z .......................................................................................iiiii........ 1900/9234
2019-11-13T10:45:28.0995549Z .................................................................................................... 2100/9234
2019-11-13T10:45:30.1686515Z .................................................................................................... 2200/9234
2019-11-13T10:45:32.4667753Z .................................................................................................... 2300/9234
2019-11-13T10:45:41.2567628Z .................................................................................................... 2400/9234
---
2019-11-13T10:48:21.5470244Z ....................................................................................i............... 4700/9234
2019-11-13T10:48:28.6636866Z i................................................................................................... 4800/9234
2019-11-13T10:48:37.4319222Z .................................................................................................... 4900/9234
2019-11-13T10:48:42.6606607Z .................................................................................................... 5000/9234
2019-11-13T10:48:53.6996610Z .......................................................................................ii.ii........ 5100/9234
2019-11-13T10:49:01.5607703Z ......................i............................................................................. 5300/9234
2019-11-13T10:49:09.3542987Z .................................................................................................... 5400/9234
2019-11-13T10:49:17.5432337Z .....................................................................i.............................. 5500/9234
2019-11-13T10:49:24.5991314Z .................................................................................................... 5600/9234
2019-11-13T10:49:24.5991314Z .................................................................................................... 5600/9234
2019-11-13T10:49:31.7355318Z .................................................................................................... 5700/9234
2019-11-13T10:49:40.6016124Z .......................................................ii...i..ii...........i....................... 5800/9234
2019-11-13T10:50:01.7257186Z .................................................................................................... 6000/9234
2019-11-13T10:50:07.9011451Z .................................................................................................... 6100/9234
2019-11-13T10:50:07.9011451Z .................................................................................................... 6100/9234
2019-11-13T10:50:12.5301438Z ..........................................................................i..ii..................... 6200/9234
2019-11-13T10:50:40.0554372Z .................................................................................................... 6400/9234
2019-11-13T10:50:42.1382227Z ..........................................i......................................................... 6500/9234
2019-11-13T10:50:44.1698591Z .................................................................................................... 6600/9234
2019-11-13T10:50:46.2755227Z ...........................i........................................................................ 6700/9234
---
2019-11-13T10:55:42.5342088Z  finished in 5.467
2019-11-13T10:55:42.5516168Z Check compiletest suite=codegen mode=codegen (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-11-13T10:55:42.7436638Z 
2019-11-13T10:55:42.7438058Z running 156 tests
2019-11-13T10:55:45.4492129Z iiii....iii......iii..iiii...i..............................i.i..................i....i...........ii 100/156
2019-11-13T10:55:47.2654328Z .i.i..iiii..............i.........iii.i.........ii......
2019-11-13T10:55:47.2655306Z 
2019-11-13T10:55:47.2659992Z  finished in 4.714
2019-11-13T10:55:47.2851337Z Check compiletest suite=codegen-units mode=codegen-units (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-11-13T10:55:47.4399746Z 
---
2019-11-13T10:55:49.2804681Z  finished in 1.995
2019-11-13T10:55:49.2968363Z Check compiletest suite=assembly mode=assembly (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-11-13T10:55:49.4452764Z 
2019-11-13T10:55:49.4453562Z running 9 tests
2019-11-13T10:55:49.4454965Z iiiiiiiii
2019-11-13T10:55:49.4455920Z 
2019-11-13T10:55:49.4459872Z  finished in 0.149
2019-11-13T10:55:49.4674497Z Check compiletest suite=incremental mode=incremental (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-11-13T10:55:49.6652721Z 
---
2019-11-13T10:56:07.7368560Z  finished in 18.270
2019-11-13T10:56:07.7565844Z Check compiletest suite=debuginfo mode=debuginfo-gdb+lldb (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-11-13T10:56:07.9333618Z 
2019-11-13T10:56:07.9333863Z running 123 tests
2019-11-13T10:56:29.5443871Z .iiiii...i.....i..i...i..i.i.i..i.ii..i.i.....i..i....ii..........iiii..........i...ii...i.......ii. 100/123
2019-11-13T10:56:33.7946779Z i.i.i......iii.i.....ii
2019-11-13T10:56:33.7948810Z 
2019-11-13T10:56:33.7948963Z  finished in 26.038
2019-11-13T10:56:33.7962133Z Uplifting stage1 rustc (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-11-13T10:56:33.7963345Z Copying stage2 rustc from stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
---
2019-11-13T11:07:46.4951324Z 
2019-11-13T11:07:46.4956101Z    Doc-tests core
2019-11-13T11:07:51.2830227Z 
2019-11-13T11:07:51.2836609Z running 2419 tests
2019-11-13T11:08:01.1692404Z ......iiiii..............F.......................................................................... 100/2419
2019-11-13T11:08:10.7849150Z .................................................................................ii................. 200/2419
2019-11-13T11:08:34.4449465Z ...i................................................................................................ 400/2419
2019-11-13T11:08:34.4449465Z ...i................................................................................................ 400/2419
2019-11-13T11:08:43.8202108Z ...................................................i..i.................iiii........................ 500/2419
2019-11-13T11:09:01.3606344Z .................................................................................................... 700/2419
2019-11-13T11:09:10.4717621Z .................................................................................................... 800/2419
2019-11-13T11:09:19.8006048Z .................................................................................................... 900/2419
2019-11-13T11:09:29.7564654Z .................................................................................................... 1000/2419
---
2019-11-13T11:11:48.4742065Z   |
2019-11-13T11:11:48.4742257Z 7 | println!("{}", type_name_of_val(&x));
2019-11-13T11:11:48.4742353Z   |                ^^^^^^^^^^^^^^^^
2019-11-13T11:11:48.4742676Z   |
2019-11-13T11:11:48.4743451Z   = note: for more information, see ***/issues/66359
2019-11-13T11:11:48.4743566Z   = help: add `#![feature(type_name_of_val)]` to the crate attributes to enable
2019-11-13T11:11:48.4743868Z error[E0658]: use of unstable library feature 'type_name_of_val'
2019-11-13T11:11:48.4744048Z  --> any.rs:498:16
2019-11-13T11:11:48.4744087Z   |
2019-11-13T11:11:48.4744087Z   |
2019-11-13T11:11:48.4744153Z 9 | println!("{}", type_name_of_val(&y));
2019-11-13T11:11:48.4744227Z   |
2019-11-13T11:11:48.4744227Z   |
2019-11-13T11:11:48.4744506Z   = note: for more information, see ***/issues/66359
2019-11-13T11:11:48.4744556Z   = help: add `#![feature(type_name_of_val)]` to the crate attributes to enable
2019-11-13T11:11:48.4744820Z error[E0658]: use of unstable library feature 'type_name_of_val'
2019-11-13T11:11:48.4744999Z  --> any.rs:493:5
2019-11-13T11:11:48.4745036Z   |
2019-11-13T11:11:48.4745073Z 4 | use std::any::type_name_of_val;
2019-11-13T11:11:48.4745073Z 4 | use std::any::type_name_of_val;
2019-11-13T11:11:48.4745129Z   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
2019-11-13T11:11:48.4745164Z   |
2019-11-13T11:11:48.4745420Z   = note: for more information, see ***/issues/66359
2019-11-13T11:11:48.4745485Z   = help: add `#![feature(type_name_of_val)]` to the crate attributes to enable
2019-11-13T11:11:48.4745551Z error: aborting due to 3 previous errors
2019-11-13T11:11:48.4745575Z 
2019-11-13T11:11:48.4745827Z For more information about this error, try `rustc --explain E0658`.
2019-11-13T11:11:48.4746009Z Couldn't compile the test.
---
2019-11-13T11:11:48.5002701Z   local time: Wed Nov 13 11:11:48 UTC 2019
2019-11-13T11:11:48.5859348Z   network time: Wed, 13 Nov 2019 11:11:48 GMT
2019-11-13T11:11:48.5864001Z == end clock drift check ==
2019-11-13T11:11:49.3295859Z 
2019-11-13T11:11:49.3355479Z ##[error]Bash exited with code '1'.
2019-11-13T11:11:49.3395382Z ##[section]Starting: Checkout
2019-11-13T11:11:49.3396977Z ==============================================================================
2019-11-13T11:11:49.3397045Z Task         : Get sources
2019-11-13T11:11:49.3397088Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@shepmaster
Copy link
Member

Great! Now, please squash the commits and we can merge!

@Dylan-DPC-zz
Copy link

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Nov 22, 2019

📌 Commit 985e663 has been approved by Dylan-DPC

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 22, 2019
Centril added a commit to Centril/rust that referenced this pull request Nov 23, 2019
add fn type_name_of_val

This function is often useful during testing and mirrors `align_of_val` and `size_of_val`.

# Example

Showing the default type of integers.

```rust
let x = 7;
println!("per default, integers have the type: {}", std::any::type_name_of_val(&x));
```

To my knowledge this can currently not be done without defining a function similar to `type_name_of_val`.
bors added a commit that referenced this pull request Nov 23, 2019
Rollup of 4 pull requests

Successful merges:

 - #65961 (add fn type_name_of_val)
 - #66574 (Update tidy check for error codes testing)
 - #66576 (made gdb pretty-printing more robust when printing uninitialized vec)
 - #66583 (Clarify Step Documentation)

Failed merges:

r? @ghost
@bors bors merged commit 985e663 into rust-lang:master Nov 23, 2019
@lcnr lcnr deleted the typename_of branch April 6, 2020 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants