Skip to content

Display traits don't mask #52

@bbaldino

Description

@bbaldino

Today I noticed the following code:

let mut x = u1::new(1);
x <<= 1;
println("{x}");

prints 2, which is an invalid value for u1.

I looked at the implementation of ShlAssign and saw:

fn shl_assign(&mut self, rhs: T) {
    *self = self.mask();
    self.0.shl_assign(rhs);
}

I think the mask call should be after the shl_assign call (or, perhaps, in both places)? If that sounds right, happy to open a PR. There are unit tests for ShlAssign, but none involve shifting beyond the type's 'size'.

EDIT: Updated the title of this ticket after discovering the current strategy is to mask on read, so the issue isn't with ShlAssign, but actually with the various display traits. See discussion below.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions