-
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 |
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