Closed
Description
Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=dc1180286b0a5d9e0f1dbac02ccdb7b3
fn main() {
let sz = size_of::<usize>();
println!("Hello, world! A usize is {}", sz);
}
The current output is:
error[[E0425]](https://doc.rust-lang.org/stable/error-index.html#E0425): cannot find function `size_of` in this scope
--> src/main.rs:2:14
|
2 | let sz = size_of::<usize>();
| ^^^^^^^ not found in this scope
|
help: consider importing one of these items
|
1 | [use core::intrinsics::size_of;](https://play.rust-lang.org/#)
|
1 | [use core::mem::size_of;](https://play.rust-lang.org/#)
|
1 | [use memoffset::__priv::mem::size_of;](https://play.rust-lang.org/#)
|
1 | [use pin_utils::core_reexport::intrinsics::size_of;](https://play.rust-lang.org/#)
|
and 3 other candidates
Ideally the output should look like:
error[[E0425]](https://doc.rust-lang.org/stable/error-index.html#E0425): cannot find function `size_of` in this scope
--> src/main.rs:2:14
|
2 | let sz = size_of::<usize>();
| ^^^^^^^ not found in this scope
|
help: consider importing one of these items
|
1 | [use core::mem::size_of;](https://play.rust-lang.org/#)
|
1 | [use core::intrinsics::size_of;](https://play.rust-lang.org/#)
|
1 | [use memoffset::__priv::mem::size_of;](https://play.rust-lang.org/#)
|
1 | [use pin_utils::core_reexport::intrinsics::size_of;](https://play.rust-lang.org/#)
|
and 3 other candidates
In cases where intrinsics have been stabilised in core
|std
it would be useful to suggest these to users first.
Especially as using intrinsics generates another rustc
error that tells you to prefer stabilized functions in std
.
This would hopefully make handling this error easier for new rust users coming from languages like C/C++ and looking for the equivalent of sizeof()
The output is the same on stable, beta and nightly