Skip to content
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

from_bits_(truncate) fail with composite flags #276

Merged
merged 8 commits into from Apr 28, 2022

Conversation

arturoc
Copy link

@arturoc arturoc commented Apr 19, 2022

When a bitflags type contains composite flags like:

bitflags! {
    struct Flags: u8 {
            const A = 0b00000001;
            const BC = 0b00000110;
    }
}

from_bits and from_bits_truncate would not work as expected allowing flags that are not declared.

Fixes #275

When a bitflags type contains composite flags like:

```rs
bitflags! {
    struct Flags: u8 {
            const A = 0b00000001;
            const BC = 0b00000110;
    }
}
```

from_bits and from_bits_truncate would not work as expected allowing flags that are not declared.

Fixes bitflags#275
extra brace commited accidentally due to partial staging
serde:: doesn't work on tests on CI
@arturoc
Copy link
Author

arturoc commented Apr 20, 2022

This one introduced some new errors in the should fail tests, the last commit updates the corresponding .err file

src/lib.rs Outdated


let flags = Flags::from_bits(0b00000100);
assert!(flags.is_none());
Copy link
Member

Choose a reason for hiding this comment

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

Would this still return None if the input was 0b00000101?

was still wrong for some edge cases
@arturoc
Copy link
Author

arturoc commented Apr 26, 2022

That was failing, it's now working and have added a test

changed on last commit
Copy link
Member

@KodrAus KodrAus left a comment

Choose a reason for hiding this comment

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

Thanks @arturoc! This looks good to me.

We need to keep the paths for Some and None mangled like they were, but I'll submit a follow-up that does that.

@KodrAus KodrAus merged commit 31401a1 into bitflags:main Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

from_bits accepts non existing flags
3 participants