-
Notifications
You must be signed in to change notification settings - Fork 13.3k
dont handle bool transmute #140431
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
base: master
Are you sure you want to change the base?
dont handle bool transmute #140431
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:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 -->
removes
transmute(u8) -> bool
suggestion due to ambiguity, leave it for clippyelaboration on ambiguity in question:
transmute::<u8, bool>(x)
will codegen to anassume(u8 < 2)
;_ == 1
or_ != 0
or_ % 2 == 0
would remove that assumptionmatch _ { x @ (0 | 1) => x == 1, _ => std::hint::unreachable_unchecked() }
is very verbose@rustbot label L-unnecessary_transmutes