-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
bit shift operators take odd types #1570
Comments
At the LLVM IR level bitshifting is undefined for negative values, or values greater than or equal to the value size. Even more reason to restrict them to a small unsigned type. |
I like uint, just for aesthetic reasons. |
We can define negative shifts as "positive in the opposite direction" or such, don't need to be bound by LLVM here. I'd prefer to support them, but agree that we should probably accept a wide variety of types for shift-amount. |
If we stray from LLVM it just means that "x >> y" will compile down to having some ifs and so forth. But then the common case is to shift by a constant, so perhaps that's a non-issue. I'd rather not have undefined results for bitshifts if we can help it. Ideally, something like |
Having the common case |
I just ran into this today within minutes of starting to use rust. Having to suffix all constant shifts with u32 just because I happen to be shifting a 32-bit unsigned quantity is a huge pain.... |
It doesn't make much sense to me that in the expression
x >> y
(resp.x << y
) bothx
andy
have to be the same types. After all, it's not like a u32 value as 2^32 bits!I think
y
should always beu8
(or perhapsuint
if we want to be nice, much as we allow int in array lookups). Actually, doesx >> -3
do something sensible, or is-3
just treated as a real big unsigned value?The text was updated successfully, but these errors were encountered: