Conversation
|
r? @Nadrieril rustbot has assigned @Nadrieril. Use |
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
|
Unknown labels: L-unnecessary-transmute |
|
Unknown labels: L-unnecessary-transmutes |
|
Is there context/discussions that led to this change? |
|
I don't know how we decide on this sort of thing. I personally expect that this suggestion is useful, I can see myself thinking in terms of bytes and forgetting that there's a safe way to do this conversion. At the same time if I'm really doing byte-conversion shenanigans, writing I'd personally err on the beginner-friendlier side, I've seen colleagues reach for |
|
well this already exists in clippy, as |
|
ok, that convinces me. very unsure on what basis I should decide whether to merge tho; @oli-obk do you know the etiquette? also wdyt of this? |
|
Personally i think that when you're trying to give the compiler more information to optimize with, you should expect to have to write a little more or silence a warning because you're effectively saying "no, i really mean to do this, compiler." I don't know whether this should be demoted to only being in clippy, as the suggested change produces something with identical semantics and no possibility of UB on misuse. |
The alternative is UB, so I don't see why we'd remove this lint. As asquared said, when you want this opt hint, use expect and state why you consider this sound |
|
@scottmcm do you want to argue this? |
Identical observable semantics, yes, but potentially very different performance behaviour. I'm strongly in favour of rustc saying "use this non- But for That means to me it's a "which is the recommended way to write it, even though both are in a sense fine" lint, which is more clippy's domain than rustc's. If the only way to avoid the lint is to TL/DR:
|
scottmcm
left a comment
There was a problem hiding this comment.
I think this PR is good as currently written. The current == 1 suggestion is mediocre (!= 0 would be a bit better, as it's less confusing to optimizers because you probably didn't want 1 and 2/3 to be different) and leaving it to clippy -- especially when clippy already has this -- sounds good to me.
|
Trying to summarize:
I'm on team "this belongs in clippy", but also not ready to override other's opinions on this. I'll note that at the very least, this PR should add a comment saying "We chose not to lint |
changelog: [`transmute_float_to_int, transmute_int_to_char, transmute_int_to_float`, `transmute_num_to_bytes`]: remove lints, now in rustc these lints are now mostly in rustc, so they dont need to be in clippy anymore rust-lang/rust#136083 (comment) pending rust-lang/rust#140431: transmute_int_to_bool <!-- TRIAGEBOT_START --> <!-- TRIAGEBOT_SUMMARY_START --> ### Summary Notes - ["Rust version of new lints should be checked" by @samueltardieu](#14703 (comment)) Generated by triagebot, see [help](https://forge.rust-lang.org/triagebot/note.html) for how to add more <!-- TRIAGEBOT_SUMMARY_DATA_START$${"entries_by_url":{"https://github.com/rust-lang/rust-clippy/pull/14703#issuecomment-2861982576":{"title":"Rust version of new lints should be checked","comment_url":"https://github.com/rust-lang/rust-clippy/pull/14703#issuecomment-2861982576","author":"samueltardieu"}}}$$TRIAGEBOT_SUMMARY_DATA_END --> <!-- TRIAGEBOT_SUMMARY_END --> <!-- TRIAGEBOT_END -->
025f76b to
ccc8ce5
Compare
ccc8ce5 to
de8e864
Compare
|
@Nadrieril so regarding not wanting to override other's opinions, what do we do now? do we want approval from @oli-obk? |
|
I understand y'all's points, so it's ok with me. Me having a different opinion shouldn't block this. |
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#140431 (dont handle bool transmute) - rust-lang#140868 (rustdoc: Fix links with inline code in trait impl docs) - rust-lang#141323 (Add bors environment to CI) - rust-lang#141337 (bump stdarch) - rust-lang#141364 (rustdoc-json: Remove false docs and add test for inline attribute) - rust-lang#141370 (add doc alias `replace_first` for `str::replacen`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#140431 - bend-n:dont_handle_bool_transmute, r=Nadrieril dont handle bool transmute removes `transmute(u8) -> bool` suggestion due to ambiguity, leave it for clippy elaboration on ambiguity in question: `transmute::<u8, bool>(x)` will codegen to an `assume(u8 < 2)`; `_ == 1` or `_ != 0` or `_ % 2 == 0` would remove that assumption `match _ { x @ (0 | 1) => x == 1, _ => std::hint::unreachable_unchecked() }` is very verbose `@rustbot` label L-unnecessary_transmutes
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#140431 (dont handle bool transmute) - rust-lang#140868 (rustdoc: Fix links with inline code in trait impl docs) - rust-lang#141323 (Add bors environment to CI) - rust-lang#141337 (bump stdarch) - rust-lang#141364 (rustdoc-json: Remove false docs and add test for inline attribute) - rust-lang#141370 (add doc alias `replace_first` for `str::replacen`) r? `@ghost` `@rustbot` modify labels: rollup
changelog: [`transmute_float_to_int, transmute_int_to_char, transmute_int_to_float`, `transmute_num_to_bytes`]: remove lints, now in rustc these lints are now mostly in rustc, so they dont need to be in clippy anymore rust-lang#136083 (comment) pending rust-lang#140431: transmute_int_to_bool <!-- TRIAGEBOT_START --> <!-- TRIAGEBOT_SUMMARY_START --> - ["Rust version of new lints should be checked" by @samueltardieu](rust-lang/rust-clippy#14703 (comment)) Generated by triagebot, see [help](https://forge.rust-lang.org/triagebot/note.html) for how to add more <!-- TRIAGEBOT_SUMMARY_DATA_START$${"entries_by_url":{"https://github.com/rust-lang/rust-clippy/pull/14703#issuecomment-2861982576":{"title":"Rust version of new lints should be checked","comment_url":"https://github.com/rust-lang/rust-clippy/pull/14703#issuecomment-2861982576","author":"samueltardieu"}}}$$TRIAGEBOT_SUMMARY_DATA_END --> <!-- TRIAGEBOT_SUMMARY_END --> <!-- TRIAGEBOT_END -->
changelog: [`transmute_float_to_int, transmute_int_to_char, transmute_int_to_float`, `transmute_num_to_bytes`]: remove lints, now in rustc these lints are now mostly in rustc, so they dont need to be in clippy anymore rust-lang#136083 (comment) pending rust-lang#140431: transmute_int_to_bool <!-- TRIAGEBOT_START --> <!-- TRIAGEBOT_SUMMARY_START --> - ["Rust version of new lints should be checked" by @samueltardieu](rust-lang/rust-clippy#14703 (comment)) Generated by triagebot, see [help](https://forge.rust-lang.org/triagebot/note.html) for how to add more <!-- TRIAGEBOT_SUMMARY_DATA_START$${"entries_by_url":{"https://github.com/rust-lang/rust-clippy/pull/14703#issuecomment-2861982576":{"title":"Rust version of new lints should be checked","comment_url":"https://github.com/rust-lang/rust-clippy/pull/14703#issuecomment-2861982576","author":"samueltardieu"}}}$$TRIAGEBOT_SUMMARY_DATA_END --> <!-- TRIAGEBOT_SUMMARY_END --> <!-- TRIAGEBOT_END -->
changelog: [`transmute_float_to_int, transmute_int_to_char, transmute_int_to_float`, `transmute_num_to_bytes`]: remove lints, now in rustc these lints are now mostly in rustc, so they dont need to be in clippy anymore rust-lang#136083 (comment) pending rust-lang#140431: transmute_int_to_bool <!-- TRIAGEBOT_START --> <!-- TRIAGEBOT_SUMMARY_START --> - ["Rust version of new lints should be checked" by @samueltardieu](rust-lang/rust-clippy#14703 (comment)) Generated by triagebot, see [help](https://forge.rust-lang.org/triagebot/note.html) for how to add more <!-- TRIAGEBOT_SUMMARY_DATA_START$${"entries_by_url":{"https://github.com/rust-lang/rust-clippy/pull/14703#issuecomment-2861982576":{"title":"Rust version of new lints should be checked","comment_url":"https://github.com/rust-lang/rust-clippy/pull/14703#issuecomment-2861982576","author":"samueltardieu"}}}$$TRIAGEBOT_SUMMARY_DATA_END --> <!-- TRIAGEBOT_SUMMARY_END --> <!-- TRIAGEBOT_END -->
changelog: [`transmute_float_to_int, transmute_int_to_char, transmute_int_to_float`, `transmute_num_to_bytes`]: remove lints, now in rustc these lints are now mostly in rustc, so they dont need to be in clippy anymore rust-lang#136083 (comment) pending rust-lang#140431: transmute_int_to_bool <!-- TRIAGEBOT_START --> <!-- TRIAGEBOT_SUMMARY_START --> - ["Rust version of new lints should be checked" by @samueltardieu](rust-lang/rust-clippy#14703 (comment)) Generated by triagebot, see [help](https://forge.rust-lang.org/triagebot/note.html) for how to add more <!-- TRIAGEBOT_SUMMARY_DATA_START$${"entries_by_url":{"https://github.com/rust-lang/rust-clippy/pull/14703#issuecomment-2861982576":{"title":"Rust version of new lints should be checked","comment_url":"https://github.com/rust-lang/rust-clippy/pull/14703#issuecomment-2861982576","author":"samueltardieu"}}}$$TRIAGEBOT_SUMMARY_DATA_END --> <!-- TRIAGEBOT_SUMMARY_END --> <!-- TRIAGEBOT_END -->
removes
transmute(u8) -> boolsuggestion due to ambiguity, leave it for clippyelaboration on ambiguity in question:
transmute::<u8, bool>(x)will codegen to anassume(u8 < 2);_ == 1or_ != 0or_ % 2 == 0would remove that assumptionmatch _ { x @ (0 | 1) => x == 1, _ => std::hint::unreachable_unchecked() }is very verbose@rustbot label L-unnecessary_transmutes