repo stringclasses 1
value | problem_statement stringlengths 79 2.53k | hints_text stringlengths 0 2.82k | instance_id stringlengths 21 22 | issue_numbers listlengths 1 2 | base_commit stringlengths 40 40 | test_patch stringlengths 336 78k | version stringlengths 3 3 | pull_number int64 24 380 | created_at stringlengths 20 20 | patch stringlengths 251 103k | environment_setup_commit stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
bitflags/bitflags | Implement Arbitrary for bitflags?
Would it be worth it to have an optional implementation of [`Arbitrary`](https://docs.rs/arbitrary/1.0.1/arbitrary/trait.Arbitrary.html) (in the [arbitrary crate](https://crates.io/crates/arbitrary)) for bitflags types, to make it easier to use them in fuzzing?
I'm imagining somethi... | Can we think of any other implementation for `Arbitrary` that a consumer might want to add themselves? If not then this seems like a reasonable addition to me, since as I understand it, `Arbitrary` is meant to be a general API that different fuzzer implementations can lean on. Anything that makes fuzzing easier to get ... | bitflags__bitflags-324 | [
"248"
] | 11640f19a7644f3967631733f33ec87b9f911951 | diff --git /dev/null b/src/external/arbitrary_support.rs
new file mode 100644
--- /dev/null
+++ b/src/external/arbitrary_support.rs
@@ -0,0 +1,19 @@
+#[cfg(test)]
+mod tests {
+ use arbitrary::Arbitrary;
+
+ bitflags! {
+ #[derive(Arbitrary)]
+ struct Color: u32 {
+ const RED = 0x1;
+ ... | 2.0 | 324 | 2023-03-25T01:34:21Z | diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -49,7 +49,7 @@ jobs:
run: cargo install cargo-hack
- name: Powerset
- run: cargo hack test --feature-powerset --lib --optional-deps "std serde" --depth 3 --skip ru... | 11640f19a7644f3967631733f33ec87b9f911951 |
bitflags/bitflags | Support bytemuck
From #310
Add a `bytemuck` Cargo feature that derives `bytemuck` traits on the generated inner flags type so end-users can then `#[derive(bytemuck::*)]` traits on their own flags types.
| bitflags__bitflags-336 | [
"311"
] | 597d40749224d3eee125a6ea9d6ac4c92b898ee8 | diff --git /dev/null b/src/external/bytemuck_support.rs
new file mode 100644
--- /dev/null
+++ b/src/external/bytemuck_support.rs
@@ -0,0 +1,19 @@
+#[cfg(test)]
+mod tests {
+ use bytemuck::{Pod, Zeroable};
+
+ bitflags! {
+ #[derive(Pod, Zeroable, Clone, Copy)]
+ #[repr(transparent)]
+ s... | 2.1 | 336 | 2023-04-11T01:30:12Z | diff --git a/Cargo.toml b/Cargo.toml
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -22,6 +22,7 @@ exclude = ["tests", ".github"]
[dependencies]
serde = { version = "1.0", optional = true, default-features = false }
arbitrary = { version = "1.0", optional = true }
+bytemuck = { version = "1.0", optional = true }
core = { ver... | dc971042c8132a5381ab3e2165983ee7f9d44c63 | |
bitflags/bitflags | `usize` / `isize` aren't supported anymore in `v2.0`
This doesn't seem intentional at least and isn't mentioned in the changelog.
| In what way are they not supported? What error message do they give? Or is there some other problem with them?
They don't implement the new `Bits` trait, which is required to use bitflags: https://github.com/bitflags/bitflags/blob/main/src/traits.rs#L135-L141
Thanks for pointing this out @CryZe. This is a total oversig... | bitflags__bitflags-321 | [
"319"
] | 8b43d2bb7efbd3d4189fdac92e411ad20c5140b5 | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1548,4 +1548,57 @@ mod tests {
assert_eq!(flags, rebuilt);
}
+
+ #[test]
+ fn bits_types() {
+ bitflags! {
+ pub struct I8: i8 {
+ const A = 1;
+ }
+
+ pub struct I16: ... | 2.0 | 321 | 2023-03-19T08:31:22Z | diff --git a/src/traits.rs b/src/traits.rs
--- a/src/traits.rs
+++ b/src/traits.rs
@@ -138,6 +138,7 @@ impl_bits! {
u32, i32,
u64, i64,
u128, i128,
+ usize, isize,
}
/// A trait for referencing the `bitflags`-owned internal type
| 11640f19a7644f3967631733f33ec87b9f911951 |
bitflags/bitflags | Display missing extra bits for multi-bit flags
See: https://github.com/bitflags/bitflags/issues/310#issuecomment-1470122112
Given a flags type with two flags, `BIT = 0b0000_0001` and `MASK = 0b0001_1110`, formatting the value `3` should result in `BIT | 0x2`, but instead it gives `BIT`. That extra bit gets lost, so ... | bitflags__bitflags-316 | [
"315"
] | ad0271116e28a79ea880334dd3d06212a224ec09 | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1154,17 +1154,39 @@ mod tests {
#[test]
fn test_display_from_str_roundtrip() {
- fn format_parse_case(flags: FmtFlags) {
+ fn format_parse_case<T: fmt::Debug + fmt::Display + str::FromStr + PartialEq>(flags: T) where <T... | 2.0 | 316 | 2023-03-16T00:19:13Z | diff --git a/src/internal.rs b/src/internal.rs
--- a/src/internal.rs
+++ b/src/internal.rs
@@ -89,7 +89,8 @@ macro_rules! __impl_internal_bitflags {
// Iterate over the valid flags
let mut first = true;
- for (name, _) in self.iter_names() {
+ let mut it... | 11640f19a7644f3967631733f33ec87b9f911951 | |
bitflags/bitflags | Cannot use `#[doc(alias)]`
The following code:
```rs
bitflags::bitflags! {
#[doc(alias = "SYMBOLIC_LINK_FLAGS")]
pub struct SymbolicLinkFlags:u32 {
#[doc(alias = "SYMBOLIC_LINK_FLAG_DIRECTORY")]
const DIRECTORY = 0x1;
#[doc(alias = "SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE")]
const ALLOW... | This is a general problem for attributes that can't be applied to expressions now. In methods like `from_name` we now generate code like this:
```rust
#[inline]
pub fn from_name(name: &str) -> ::bitflags::__private::core::option::Option<Self> {
match name {
#[doc(alias = "SYMBOLIC_LINK_FLAG_DIRECTORY... | bitflags__bitflags-341 | [
"308"
] | dc971042c8132a5381ab3e2165983ee7f9d44c63 | diff --git /dev/null b/tests/compile-pass/doc_alias.rs
new file mode 100644
--- /dev/null
+++ b/tests/compile-pass/doc_alias.rs
@@ -0,0 +1,14 @@
+#[macro_use]
+extern crate bitflags;
+
+bitflags! {
+ #[doc(alias = "FLAG")]
+ pub struct Flags: u8 {
+ #[doc(alias = "FLAG_A")]
+ const A = 1;
+ }
+}
... | 2.1 | 341 | 2023-04-18T00:36:26Z | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -558,6 +558,315 @@ macro_rules! bitflags {
}
$($t:tt)*
+ ) => {
+ __declare_bitflags!(
+ $(#[$outer])*
+ $vis struct $BitFlags: $T {
+ $(
+ $(#[$inner $($args)*... | dc971042c8132a5381ab3e2165983ee7f9d44c63 |
bitflags/bitflags | Clippy warnings around "manual implementation of an assign operation"
Hi.
I've run into a new clippy lint warnings such as the following:
> manual implementation of an assign operation
> for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern
> `#[warn(clippy::a... | bitflags__bitflags-355 | [
"357"
] | 31d3e4afefc964045156d7fe3622733f48511353 | diff --git a/tests/compile-fail/bitflags_custom_bits.rs b/tests/compile-fail/bitflags_custom_bits.rs
--- a/tests/compile-fail/bitflags_custom_bits.rs
+++ b/tests/compile-fail/bitflags_custom_bits.rs
@@ -19,7 +19,7 @@ use std::{
},
};
-use bitflags::{bitflags, Bits, parser::{ParseError, FromHex}};
+use bitflags:... | 2.3 | 355 | 2023-05-17T11:22:15Z | diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -81,6 +81,23 @@ jobs:
- name: Default features
run: cross test --target mips-unknown-linux-gnu
+ clippy:
+ name: Clippy
+ runs-on: ubuntu-latest
+ steps:
... | 09f71f492d0f76d63cd286c3869c70676297e204 | |
bitflags/bitflags | Bug: debug pretty-printing unknown flags display 0x0x
main.rs
```rust
use bitflags::bitflags;
bitflags! {
struct Flags: u8 {
const TWO = 0x2;
}
}
fn main() {
let value = 0b11;
let flags = unsafe { Flags::from_bits_unchecked(value) };
println!("{:?}", flags);
println!("---... | bitflags__bitflags-268 | [
"267"
] | 1aa25e1b3baf35d3d3840f12fe7e8b55adc0164a | diff --git a/tests/compile-fail/trait/custom_impl.rs b/tests/compile-fail/trait/custom_impl.rs
--- a/tests/compile-fail/trait/custom_impl.rs
+++ b/tests/compile-fail/trait/custom_impl.rs
@@ -62,4 +62,4 @@ impl BitFlags for BootlegFlags {
}
}
-fn main() { }
+fn main() {}
diff --git a/tests/compile-pass/impls/co... | 1.3 | 268 | 2022-01-02T17:22:14Z | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -494,8 +494,7 @@ macro_rules! __impl_bitflags {
f.write_str(" | ")?;
}
first = false;
- f.write_str("0x")?;
- $crate::_core::fmt::LowerHex::f... | 810dc35aba3df7314de01b93c7aa137968e925d4 | |
bitflags/bitflags | The bitflags macro is not sanitary wrt. standard library types and enumerations
The `bitflags` macro, expanded in the prescence of a definition of the type/value `Ok` errors.
Reproduction code:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=3fda3e36c7c6a57e0f7a83c84e56df20
Interestingly, t... | bitflags__bitflags-266 | [
"265"
] | 1aa25e1b3baf35d3d3840f12fe7e8b55adc0164a | diff --git /dev/null b/tests/compile-pass/redefinition/result.rs
new file mode 100644
--- /dev/null
+++ b/tests/compile-pass/redefinition/result.rs
@@ -0,0 +1,15 @@
+use bitflags::bitflags;
+
+// Checks for possible errors caused by overriding names used by `bitflags!` internally.
+
+// bug #265 (https://github.com/bit... | 1.3 | 266 | 2021-12-16T09:38:14Z | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -500,7 +500,7 @@ macro_rules! __impl_bitflags {
if first {
f.write_str("(empty)")?;
}
- Ok(())
+ $crate::_core::fmt::Result::Ok(())
}
}
... | 810dc35aba3df7314de01b93c7aa137968e925d4 | |
bitflags/bitflags | Documenting bitflags: how to get documentation for the generated bitflags
Some code that I'm writing uses the `#![warn(missing_docs)]` macro to enforce a requirement that all public interfaces have documentation. I haven't been able to figure out how to generate documentation when using the `bitflags!` macro; I also ha... | https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=530756068e54aa56eb519dd66c9fdfc5
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=f782c74e49e8c4c4ae940125265eb7ed
Thanks @rusty-snake! Those would actually make some great compile-pass tests 🤔 | bitflags__bitflags-380 | [
"378"
] | 472e392c0d082c0894b18fb31f4e68e0b145e29c | diff --git a/src/tests/iter.rs b/src/tests/iter.rs
--- a/src/tests/iter.rs
+++ b/src/tests/iter.rs
@@ -3,6 +3,7 @@ use super::*;
use crate::Flags;
#[test]
+#[cfg(not(miri))] // Very slow in miri
fn roundtrip() {
for a in 0u8..=255 {
for b in 0u8..=255 {
diff --git a/src/tests/parser.rs b/src/tests/p... | 2.4 | 380 | 2023-10-09T04:48:32Z | diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -84,18 +84,19 @@ jobs:
cd ./tests/smoke-test
cargo +$msrv build
- mips:
- name: Tests / MIPS (Big Endian)
+ miri:
+ name: "Miri"
runs-on: ubuntu-... | 472e392c0d082c0894b18fb31f4e68e0b145e29c |
bitflags/bitflags | Empty bitflags definitions fail to parse
This doesn't parse:
```rust
bitflags::bitflags! {
pub struct BoxFlags: u8 {
}
}
```
| Hmm, it looks like we're using `+` rather than `*` as the repetition control. I can't imagine an empty set of `bitflags` would be very useful. Do you have a case where you've run into this?
It might useful when introducing the type and designing the API first, before you even actually add the various bitflags
Yeh that ... | bitflags__bitflags-225 | [
"179"
] | bd24f9d8d266bfb2dfe4b8238b196ecf5e37dee1 | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -992,6 +1026,11 @@ mod tests {
}
}
+ bitflags! {
+ struct EmptyFlags: u32 {
+ }
+ }
+
#[test]
fn test_bits() {
assert_eq!(Flags::empty().bits(), 0b00000000);
diff --git a/src/lib.rs b/src/li... | 1.2 | 225 | 2020-10-01T16:10:42Z | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -360,7 +360,7 @@ macro_rules! bitflags {
$(
$(#[$inner:ident $($args:tt)*])*
const $Flag:ident = $value:expr;
- )+
+ )*
}
$($t:tt)*
) => {
diff --git a/s... | bd24f9d8d266bfb2dfe4b8238b196ecf5e37dee1 |
bitflags/bitflags | from_bits accepts non existing flags
```rs
#[test]
fn test_from_bits_edge_cases() {
bitflags! {
struct Flags: u8 {
const A = 0b00000001;
const BC = 0b00000110;
}
}
let flags = Flags::from_bits(0b00000100);
asse... | bitflags__bitflags-276 | [
"275"
] | 0141a07e55184304857384b0093d00959f0acfa6 | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1891,6 +1907,37 @@ mod tests {
}
}
+ #[test]
+ fn test_from_bits_edge_cases() {
+ bitflags! {
+ struct Flags: u8 {
+ const A = 0b00000001;
+ const BC = 0b00000110;
+ ... | 1.3 | 276 | 2022-04-19T09:54:30Z | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -559,10 +559,11 @@ macro_rules! __impl_bitflags {
/// representation contains bits that do not correspond to a flag.
#[inline]
pub const fn from_bits(bits: $T) -> $crate::_core::option::Option<Self> {
- ... | 810dc35aba3df7314de01b93c7aa137968e925d4 | |
bitflags/bitflags | `cargo build --test` fails on Windows
[One of the tests](https://github.com/bitflags/bitflags/blob/8a10bdc144bb2a4b97c63cfa76be90228954d029/src/lib.rs#L920) for `bitflags-1.1.0` fails to compile on Windows with a stable rustc (version 1.36.0).
```
[INFO] [stderr] error[E0425]: cannot find value `_CFG_A` in this sco... | Thanks for the report @ecstatic-morse! I'm not in front of my Windows box right now, but will look into this when I am, unless somebody else checks it first.
I would guess that swapping `#[cfg(unix)]` and `#[cfg(windows)]` in that test will result in a failure on *nix. Btw, this arose while testing out `crater` runs on... | bitflags__bitflags-186 | [
"185"
] | 8a10bdc144bb2a4b97c63cfa76be90228954d029 | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1111,7 +1111,7 @@ mod tests {
#[cfg(bitflags_const_fn)]
#[test]
fn test_const_fn() {
- const M1: Flags = Flags::empty();
+ const _M1: Flags = Flags::empty();
const M2: Flags = Flags::A;
assert_eq!... | 1.1 | 186 | 2019-07-20T12:27:25Z | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -919,12 +919,12 @@ mod tests {
bitflags! {
struct _CfgFlags: u32 {
- #[cfg(windows)]
- const _CFG_A = 0b01;
#[cfg(unix)]
- const _CFG_B = 0b01;
+ const _CFG_A = 0b01;
... | 8a10bdc144bb2a4b97c63cfa76be90228954d029 |
bitflags/bitflags | Bitflags values of zero are considered always present
When a bitflag is built with a zero valued item then it is treated as always present by bitflags functions.
This may cause bugs but it definitely causes confusion when printing such a value. See the following for an example:
```
#[macro_use]
extern crate bitfl... | I agree, a zero value should only show up in Debug output if no bits are set. Would you be interested in sending a PR to fix this?
I would definitely be interested in doing so, where should I start?
The Debug impls are constructed [here](https://github.com/rust-lang-nursery/bitflags/blob/1.0.2/src/lib.rs#L401).
After l... | bitflags__bitflags-157 | [
"151"
] | 74aa397b0e6899c8b5131da34351e7d87d247038 | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1157,4 +1191,22 @@ mod tests {
assert_eq!(module::value(), 1)
}
+
+ #[test]
+ fn test_zero_value_flags() {
+ bitflags! {
+ struct Flags: u32 {
+ const NONE = 0b0;
+ const SOME... | 1.0 | 157 | 2018-04-30T12:18:19Z | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -215,6 +215,36 @@
//! assert_eq!(implemented_default, (Flags::A | Flags::C));
//! }
//! ```
+//!
+//! # Zero Flags
+//!
+//! Flags with a value equal to zero will have some strange behavior that one should be aware of.
+//!
+//! ```
+//! #... | 74aa397b0e6899c8b5131da34351e7d87d247038 |
bitflags/bitflags | pub(restricted) bitflags
cc https://github.com/rust-lang/rust/issues/32409 - maybe no action is warranted until this feature is stable.
```rust
bitflags! {
pub(super) flags Flags: u8 {
const A = 1
}
}
```
| pub(restricted) is now stable. But I think it is still blocked by `:vis` matcher (rust-lang/rust#41022) to allow a proper fix.
----
Currently the straightforward fix using `:vis` causes an error in `example_generated.rs`
```rust
error: local ambiguity: multiple parsing options: built-in NTs vis ('vis') or 1 o... | bitflags__bitflags-135 | [
"72"
] | 8e163c64ec3ce242a9fef0347c73a82f5ea84b90 | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1092,4 +1111,46 @@ mod tests {
}
}
}
+
+ #[test]
+ fn test_pub_crate() {
+ mod module {
+ bitflags! {
+ pub (crate) struct Test: u8 {
+ const FOO = 1;
+ ... | 1.0 | 135 | 2017-11-08T05:38:51Z | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -336,6 +336,25 @@ macro_rules! bitflags {
}
}
};
+ (
+ $(#[$outer:meta])*
+ pub ($($vis:tt)+) struct $BitFlags:ident: $T:ty {
+ $(
+ $(#[$inner:ident $($args:tt)*])*
+ ... | 74aa397b0e6899c8b5131da34351e7d87d247038 |
bitflags/bitflags | Bitflags reverses order of multiline doc comments
When compiling code like
```
bitflags! {
pub struct AdjustFlags: u32 {
/// Add buf.time to the current time. If buf.status includes the ADJ_NANO flag, then buf.time.tv_usec is interpreted as a nanosecond value;
/// otherwise it is interpreted as... | This should be trivially fixed by swapping the order attributes are "pushed" in `__declare_bitflags`. We've already yanked `2.2.0` because it requires a lot more recursion, but will keep this open to make sure any new approach doesn't reverse the order of attributes. | bitflags__bitflags-345 | [
"344"
] | cbcafa710fc31172511e62efa06ad9eb214e4734 | diff --git /dev/null b/tests/compile-pass/large.rs
new file mode 100644
--- /dev/null
+++ b/tests/compile-pass/large.rs
@@ -0,0 +1,311 @@
+/*
+Copyright (c) 2016 Anatoly Ikorsky
+
+Permission is hereby granted, free of charge, to any
+person obtaining a copy of this software and associated
+documentation files (the "So... | 2.2 | 345 | 2023-04-24T04:29:26Z | diff --git a/src/example_generated.rs b/src/example_generated.rs
--- a/src/example_generated.rs
+++ b/src/example_generated.rs
@@ -33,8 +33,17 @@ __impl_public_bitflags! {
__impl_public_bitflags_consts! {
Flags {
+ /// Field `A`.
+ ///
+ /// This flag has the value `0b00000001`.
A ... | cbcafa710fc31172511e62efa06ad9eb214e4734 |
bitflags/bitflags | serde support
Are there any plans to support `Serialize` and `Deserialize` for generated types? I'm writing the impls manually in my code, but this falls apart once there's a ton of `bitflags` generated types. If others are interested in such a feature, maybe I can find the time to implement it myself and submit a pull... | During the libs blitz evaluation we saw that a grand total of 8 crates have dependencies on both bitflags and Serde, so we decided not to pursue it at the time. I would welcome a PR that adds Serialize and Deserialize impls behind a cfg.
Adding `#[derive(Serialize, Deserialize)]` to the struct seems to work fine, I'm n... | bitflags__bitflags-125 | [
"108"
] | 29e60b23708123121a540fa9bde3254260952511 | diff --git /dev/null b/tests/serde.rs
new file mode 100644
--- /dev/null
+++ b/tests/serde.rs
@@ -0,0 +1,35 @@
+#[macro_use]
+extern crate bitflags;
+
+#[macro_use]
+extern crate serde_derive;
+extern crate serde;
+extern crate serde_json;
+
+bitflags! {
+ #[derive(Serialize, Deserialize)]
+ struct Flags: u32 {
+... | 1.0 | 125 | 2017-10-11T15:27:55Z | diff --git a/Cargo.toml b/Cargo.toml
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -28,5 +28,8 @@ example_generated = []
[dev-dependencies]
# Trick Cargo into testing this crate when we run `cargo test --all`.
bitflags-compiletest = { path = "compiletest" }
+serde = "1.0"
+serde_derive = "1.0"
+serde_json = "1.0"
[workspa... | 74aa397b0e6899c8b5131da34351e7d87d247038 |
bitflags/bitflags | is_all() vs. from_bits_unchecked()
[`unsafe from_bits_unchecked()`](https://docs.rs/bitflags/1.2.1/bitflags/example_generated/struct.Flags.html#method.from_bits_unchecked) allows creating instances with extra bits. The caller of the `bitflags!` macro can decide if this is allowed for their type. Let's assume it is for ... | bitflags__bitflags-211 | [
"208"
] | 15e911c304d5bd8805af55d7e4f8c5324ed798ee | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1048,6 +1048,11 @@ mod tests {
assert!(!Flags::A.is_all());
assert!(Flags::ABC.is_all());
+ let extra = unsafe { Flags::from_bits_unchecked(0b1000) };
+ assert!(!extra.is_all());
+ assert!(!(Flags::A | ex... | 1.2 | 211 | 2020-02-04T10:52:16Z | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -664,7 +664,7 @@ macro_rules! __impl_bitflags {
/// Returns `true` if all flags are currently set.
#[inline]
pub const fn is_all(&self) -> bool {
- self.bits == $BitFlags::all(... | bd24f9d8d266bfb2dfe4b8238b196ecf5e37dee1 | |
bitflags/bitflags | Create a test suite crate
#61 adds an `unstable_testing` feature that is only considered by tests. It seems unfortunate to leak this into the public API.
Having a separate crate for tests ([like in Serde](https://github.com/serde-rs/serde/tree/master/test_suite)) would avoid this.
| bitflags__bitflags-127 | [
"68"
] | 862582d107bb74ce4c7b505b2490eb815bc3a8c2 | diff --git a/.travis.yml b/.travis.yml
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,23 +10,14 @@ rust:
- beta
- nightly
sudo: false
-before_script:
- - pip install -v 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH
- - if [[ -e ~/Library/Python/2.7/bin ]]; then export PATH=~/Library/Python/2.7/bin... | 1.0 | 127 | 2017-10-17T16:27:59Z | diff --git a/.gitignore b/.gitignore
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,2 @@
-/target
-/Cargo.lock
+target
+Cargo.lock
diff --git a/.travis.yml b/.travis.yml
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,6 +2,7 @@ os:
- linux
- osx
language: rust
+cache: cargo
rust:
# This version is tested to avoid u... | 74aa397b0e6899c8b5131da34351e7d87d247038 | |
bitflags/bitflags | Debug formatting leads to less desireable output
[Link to rust playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=%23%5Bmacro_use%5D%0Aextern%20crate%20bitflags%3B%0A%0Abitflags!%20%7B%0A%20%20%20%20struct%20Flags%3A%20u32%20%7B%0A%20%20%20%20%20%20%20%20const%20A%20%3D%200b00000001%3B%... | I think the current algorithm used for debug output is to loop over all flags and append identifiers that correspond to set bits. I think an alternative here that could work would be to short-circuit when we’ve built a format that covers all the set bits. As an implementation note we wouldn’t be able to work off a sing... | bitflags__bitflags-281 | [
"215"
] | f38ce72d11ef3e264d4b62f360bd8a5597b916d9 | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1353,7 +1321,10 @@ mod tests {
assert_eq!(UNION, Flags::A | Flags::C);
assert_eq!(DIFFERENCE, Flags::all() - Flags::A);
assert_eq!(COMPLEMENT, !Flags::C);
- assert_eq!(SYM_DIFFERENCE, (Flags::A | Flags::C) ^ (Fl... | 1.3 | 281 | 2022-05-03T06:59:46Z | diff --git a/src/bitflags_trait.rs b/src/bitflags_trait.rs
--- a/src/bitflags_trait.rs
+++ b/src/bitflags_trait.rs
@@ -1,3 +1,5 @@
+use core::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Not};
+
#[doc(hidden)]
pub trait ImplementedByBitFlagsMacro {}
diff --git a/src/bitflags_trait.rs b/src... | 810dc35aba3df7314de01b93c7aa137968e925d4 |
bitflags/bitflags | Empty bitflags has unhelpful Debug representation
The Debug representation is the empty string. This is not very debuggable. I think "(empty)" would be more helpful.
```rust
#[macro_use]
extern crate bitflags;
bitflags! {
pub flags Flags: u8 {
const A = 0,
}
}
fn main() {
println!("{... | Do as suggested in the op. | bitflags__bitflags-85 | [
"64"
] | 7acacb4e869a6a0c8b427c25ade53086e5f024a1 | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -765,6 +764,7 @@ mod tests {
#[test]
fn test_debug() {
assert_eq!(format!("{:?}", FlagA | FlagB), "FlagA | FlagB");
+ assert_eq!(format!("{:?}", Flags::empty()), "(empty)");
assert_eq!(format!("{:?}", FlagABC), ... | 0.8 | 85 | 2017-03-22T12:28:53Z | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -252,8 +252,7 @@ macro_rules! bitflags {
}
)+
if first {
- // TODO: should not be the empty string
- // https://github.com/rust-lang-nursery/bitflags/iss... | 7acacb4e869a6a0c8b427c25ade53086e5f024a1 |
bitflags/bitflags | Bitflags should be private by default
Bitflags should match the semantics of structs, which are private by default unless explicitly exported using `pub`.
Since this is a compat-breaking change, it would make sense to do it at the same time as the switch to associated constants and namespaced flags (#24).
Example:
`... | bitflags__bitflags-38 | [
"25"
] | 95a521ddd2d4ae36df7a91d22be8b5f89c620e59 | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -661,4 +745,27 @@ mod tests {
assert_eq!(format!("{:?}", FlagA | FlagB), "FlagA | FlagB");
assert_eq!(format!("{:?}", FlagABC), "FlagA | FlagB | FlagC | FlagABC");
}
+
+ mod submodule {
+ bitflags! {
+ ... | 0.4 | 38 | 2016-01-16T10:00:58Z | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -101,6 +101,35 @@ pub use std as __core;
/// }
/// ```
///
+/// # Visibility
+///
+/// The generated struct and its associated flag constants are not exported
+/// out of the current module by default. A definition can be exported out of
+/// ... | 95a521ddd2d4ae36df7a91d22be8b5f89c620e59 | |
bitflags/bitflags | Function-local bitflags
Is there any hope of supporting usage like this? The error here is inconsistent with being able to declare structs and other types of items local to a function.
```rust
#[macro_use]
extern crate bitflags;
fn main() {
bitflags! {
flags Flags: u8 {
const A = 1,
... | bitflags__bitflags-74 | [
"71"
] | 2fecde2b33c34659bd37d82f64b9c07f002d6a30 | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -837,4 +807,17 @@ mod tests {
}
}
}
+
+ #[test]
+ fn test_in_function() {
+ bitflags! {
+ flags Flags: u8 {
+ const A = 1,
+ #[cfg(any())] // false
+ ... | 0.8 | 74 | 2017-03-08T02:00:24Z | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -216,63 +216,46 @@ macro_rules! bitflags {
impl $crate::__core::fmt::Debug for $BitFlags {
fn fmt(&self, f: &mut $crate::__core::fmt::Formatter) -> $crate::__core::fmt::Result {
// This convoluted approach i... | 7acacb4e869a6a0c8b427c25ade53086e5f024a1 | |
bitflags/bitflags | Possibly unintended breakage between 0.8 and 0.9 involving use of the `#[deprecated]` attribute
Given the following snippet of code compiled with bitflags 0.8:
```rust
#![allow(deprecated)]
#[macro_use]
extern crate bitflags;
bitflags! {
pub flags TestFlags: u32 {
#[deprecated(note = "test note... | bitflags__bitflags-112 | [
"109"
] | 8ee624463bb29c3a749ef134fda7cc0fa1192552 | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -988,4 +1075,14 @@ mod tests {
assert_eq!(Flags::all(), A);
assert_eq!(format!("{:?}", A), "A");
}
+
+ #[test]
+ fn test_deprecated() {
+ bitflags! {
+ pub struct TestFlags: u32 {
+ #[... | 0.9 | 112 | 2017-08-06T08:33:36Z | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -305,49 +305,77 @@ pub extern crate core as _core;
/// ```
#[macro_export]
macro_rules! bitflags {
- ($(#[$attr:meta])* pub struct $BitFlags:ident: $T:ty {
- $($(#[$Flag_attr:meta])* const $Flag:ident = $value:expr;)+
- }) => {
+ ... | 8ee624463bb29c3a749ef134fda7cc0fa1192552 | |
bitflags/bitflags | Add an option for checking for valid bits is in the getter rather than constructor
Hi, I want to use bitflags for generated code that interacts with data in other languages, some of which are bitflags (https://github.com/google/flatbuffers/pull/6098). I don't want to drop data so I'd like to use `from_bits_unchecked`. ... | Related: #188, #200, #207, #208, #211
@niklasf @KodrAus worked on #200
Bump!
I'll do the PR if needed
Hi @CasperN! :wave:
We can't consider any changes to the `bits()` method, because the library is already stable.
The way we modeled this originally was that the flags represents a closed enum, where the set s... | bitflags__bitflags-282 | [
"228"
] | 810dc35aba3df7314de01b93c7aa137968e925d4 | diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -46,8 +46,17 @@ jobs:
profile: minimal
toolchain: ${{ matrix.channel }}-${{ matrix.rust_target }}
- - name: Tests
- run: cargo test --features example_gen... | 1.3 | 282 | 2022-05-25T04:14:38Z | diff --git a/Cargo.toml b/Cargo.toml
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -16,16 +16,16 @@ categories = ["no-std"]
description = """
A macro to generate structures which behave like bitflags.
"""
-exclude = ["bors.toml"]
+exclude = ["tests", ".github"]
[dependencies]
-core = { version = '1.0.0', optional = true, ... | 810dc35aba3df7314de01b93c7aa137968e925d4 |
bitflags/bitflags | Implement Hex, Octal, and Binary
These formatting options should be available.
| bitflags__bitflags-86 | [
"82"
] | 7acacb4e869a6a0c8b427c25ade53086e5f024a1 | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -529,6 +549,12 @@ mod tests {
}
}
+ bitflags! {
+ flags LongFlags: u32 {
+ const LongFlagA = 0b1111111111111111,
+ }
+ }
+
#[test]
fn test_bits(){
assert_eq!(Flags::empty().bits(),... | 0.8 | 86 | 2017-03-22T15:50:46Z | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -139,8 +139,8 @@ pub use core as __core;
/// too: `Extend` adds the union of the instances of the `struct` iterated over,
/// while `FromIterator` calculates the union.
///
-/// The `Debug` trait is also implemented by displaying the bits valu... | 7acacb4e869a6a0c8b427c25ade53086e5f024a1 | |
bitflags/bitflags | Allow namespaced flags
It would be nice to have `FlagType::FlagName` be the pattern rather than dumping the flag values into the top-level namespace. Is this possible?
associated constants
This crate really wants to use associated constants (see https://github.com/rust-lang/rust/pull/24921) but the tricks introduced i... | bitflags__bitflags-24 | [
"20",
"21"
] | d0884fa853eadd800fef198d9e71c8758b292db5 | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -723,71 +717,71 @@ mod tests {
#[doc = "> "]
#[doc = "> - Richard Feynman"]
struct Flags: u32 {
- const FlagA = 0b00000001;
+ const FLAG_A = 0b00000001;
#[doc = "<pcwalton>... | 0.9 | 24 | 2015-11-28T01:15:59Z | diff --git a/src/example_generated.rs b/src/example_generated.rs
--- a/src/example_generated.rs
+++ b/src/example_generated.rs
@@ -9,8 +9,8 @@ bitflags! {
const FLAG_A = 0b00000001;
const FLAG_B = 0b00000010;
const FLAG_C = 0b00000100;
- const FLAG_ABC = FLAG_A.bi... | 8ee624463bb29c3a749ef134fda7cc0fa1192552 | |
bitflags/bitflags | Inconsistent debug output for flag with no bits
In a bitflags type where one of the named value has the value 0, the debug output for the type sometimes includes that value by name, and sometimes doesn't, apparently depending on whether any unrecognized bits are present. For example, this:
```rust
use bitflags::bitfl... | The value `0` isn’t recommended as a flag value because it behaves surprisingly with formatting, and with `is_any`.
If you do want to define a zero-valued flag I’d suggest defining the constant outside of the `bitflags!` macro. | bitflags__bitflags-366 | [
"364"
] | 09f71f492d0f76d63cd286c3869c70676297e204 | diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1045,1105 +1024,4 @@ mod external;
pub mod example_generated;
#[cfg(test)]
-mod tests {
- use std::{
- collections::hash_map::DefaultHasher,
- fmt,
- hash::{Hash, Hasher},
- str,
- };
-
- #[derive(Debug, ... | 2.3 | 366 | 2023-06-26T07:21:41Z | diff --git a/examples/custom_bits_type.rs b/examples/custom_bits_type.rs
--- a/examples/custom_bits_type.rs
+++ b/examples/custom_bits_type.rs
@@ -1,6 +1,6 @@
use std::ops::{BitAnd, BitOr, BitXor, Not};
-use bitflags::{Flags, Flag, Bits};
+use bitflags::{Bits, Flag, Flags};
// Define a custom container that can b... | 09f71f492d0f76d63cd286c3869c70676297e204 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.