Skip to content

Don't use a mask when not needed #537

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

Merged
merged 1 commit into from
Aug 20, 2021
Merged

Conversation

thvdveld
Copy link
Contributor

When the mask has the same size as the parent register of a field, then
a mask is not required. This removes the clippy warnings/errors where
for example an operation of inverting a mask results in zero

error: this operation will always return zero. This is likely not the intended outcome
   |
61 |         self.w.bits = (self.w.bits & !0xffff_ffff) | (value as u32 & 0xffff_ffff);
   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |

or when the operation of using a mask is ineffective.

warning: the operation is ineffective. Consider reducing it to `value as u32`
   |
61 |         self.w.bits = (self.w.bits & !0xffff_ffff) | (value as u32 & 0xffff_ffff);
   |                                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |

@thvdveld thvdveld requested a review from a team as a code owner August 20, 2021 10:22
@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Emilgardis (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-tools labels Aug 20, 2021
burrbull
burrbull previously approved these changes Aug 20, 2021
@burrbull
Copy link
Member

bors r+

bors bot added a commit that referenced this pull request Aug 20, 2021
537: Don't use a mask when not needed r=burrbull a=thibautvdv

When the mask has the same size as the parent register of a field, then
a mask is not required. This removes the clippy warnings/errors where
for example an operation of inverting a mask results in zero

```
error: this operation will always return zero. This is likely not the intended outcome
   |
61 |         self.w.bits = (self.w.bits & !0xffff_ffff) | (value as u32 & 0xffff_ffff);
   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
```

or when the operation of using a mask is ineffective.

```
warning: the operation is ineffective. Consider reducing it to `value as u32`
   |
61 |         self.w.bits = (self.w.bits & !0xffff_ffff) | (value as u32 & 0xffff_ffff);
   |                                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
```

Co-authored-by: Thibaut Vandervelden <thvdveld@vub.be>
@burrbull
Copy link
Member

bors r-

@bors
Copy link
Contributor

bors bot commented Aug 20, 2021

Canceled.

@burrbull
Copy link
Member

Squash commits, please.

When the mask has the same size as the parent register of a field, then
a mask is not required. This removes the clippy warnings/errors where
for example an operation of inverting a mask results in zero

```
error: this operation will always return zero. This is likely not the intended outcome
   |
61 |         self.w.bits = (self.w.bits & !0xffff_ffff) | (value as u32 & 0xffff_ffff);
   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
```

or when the operation of using a mask is ineffective.

```
warning: the operation is ineffective. Consider reducing it to `value as u32`
   |
61 |         self.w.bits = (self.w.bits & !0xffff_ffff) | (value as u32 & 0xffff_ffff);
   |                                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
```
Copy link
Member

@Emilgardis Emilgardis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

bors r+

@bors bors bot merged commit f53648c into rust-embedded:master Aug 20, 2021
@thvdveld thvdveld deleted the dont_use_mask branch August 21, 2021 06:17
burrbull added a commit that referenced this pull request Nov 9, 2021
@Emilgardis Emilgardis mentioned this pull request Nov 9, 2021
burrbull added a commit that referenced this pull request Nov 9, 2021
bors bot added a commit that referenced this pull request Nov 9, 2021
549: fix bug in #537 r=Emilgardis a=burrbull

resolves #547 

Co-authored-by: Andrey Zgarbul <zgarbul.andrey@gmail.com>
bors bot added a commit that referenced this pull request Jan 15, 2022
570: don't cast if not use_mask r=adamgreig a=burrbull

#537 

Co-authored-by: Andrey Zgarbul <zgarbul.andrey@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-tools
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants