Skip to content

from_bits_(truncate) fail with composite flags#276

Merged
KodrAus merged 8 commits intobitflags:mainfrom
arturoc:fix_from_bits
Apr 28, 2022
Merged

from_bits_(truncate) fail with composite flags#276
KodrAus merged 8 commits intobitflags:mainfrom
arturoc:fix_from_bits

Conversation

@arturoc
Copy link
Copy Markdown

@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

arturoc added 5 commits April 19, 2022 11:53
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Author

arturoc commented Apr 26, 2022

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

changed on last commit
Copy link
Copy Markdown
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