mirror of
https://github.com/rust-lang/rust
synced 2024-09-05 16:57:03 +00:00
a5a60d75a8
Many, many projects use `size_of` to get the size of a type. However, it's also often equally easy to hardcode a size (e.g. `8` instead of `size_of::<u64>()`). Minimizing friction in the use of `size_of` helps ensure that people use it and make code more self-documenting. The name `size_of` is unambiguous: the name alone, without any prefix or path, is self-explanatory and unmistakeable for any other functionality. Adding it to the prelude cannot produce any name conflicts, as any local definition will silently shadow the one from the prelude. Thus, we don't need to wait for a new edition prelude to add it. Add `size_of_val`, `align_of`, and `align_of_val` as well, with similar justification: widely useful, self-explanatory, unmistakeable for anything else, won't produce conflicts.
11 lines
279 B
Rust
11 lines
279 B
Rust
fn main() {
|
|
// Should suggest only `std::mem::transmute`
|
|
let _ = transmute::<usize>();
|
|
//~^ ERROR cannot find
|
|
|
|
// Should suggest `std::intrinsics::fabsf64`,
|
|
// since there is no non-intrinsic to suggest.
|
|
let _ = fabsf64(1.0);
|
|
//~^ ERROR cannot find
|
|
}
|