actually checked bitshifts (original) (raw)

Proposal

Problem statement

For every integer operation with a symbolic operator, there is a corresponding checked_* method that returns None if an overflow occurs...

except for bitshifts, whose checked_* functions do something entirely different.

For example, 255_u8.checked_shl(1) evaluates to Some(254).

The closest existing functions are overflowing_{shl,shr}, but those must also return a result in the overflowing case, ruling out implementations that check for overflow before doing the shift. EDIT: the overflowing_* functions ALSO don't do what you would expect.

Motivating examples or use cases

This could be used to detect overflow when parsing certain types of positional integer notation, from ascii decimal to certain VLQs.

Solution Sketch

What happens now?

This issue contains an API change proposal (or ACP) and is part of the libs-api team feature lifecycle. Once this issue is filed, the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.

Possible responses

The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):

Second, if there's a concrete solution: