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

Update to bitflags v2 #746

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [#843]: `defmt`: Sort IDs of log msgs by severity to allow runtime filtering by severity
- [#822]: `CI`: Run `cargo semver-checks` on every PR
- [#856]: `defmt`: Add a `Format` impl for `PanicInfo` and related types.
- [#746]: Update to `bitflags v2.0`

[#859]: https://github.com/knurling-rs/defmt/pull/859
[#858]: https://github.com/knurling-rs/defmt/pull/858
Expand All @@ -30,6 +31,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
[#843]: https://github.com/knurling-rs/defmt/pull/843
[#822]: https://github.com/knurling-rs/defmt/pull/822
[#856]: https://github.com/knurling-rs/defmt/pull/856
[#746]: https://github.com/knurling-rs/defmt/pull/746

## [v0.3.8] - 2024-05-17

Expand Down
2 changes: 1 addition & 1 deletion defmt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ unstable-test = [ "defmt-macros/unstable-test" ]

[dependencies]
defmt-macros = { path = "../macros", version = "0.3.2" }
bitflags = "1"
bitflags = "2"

[dev-dependencies]
rustc_version = "0.4"
Expand Down
2 changes: 1 addition & 1 deletion defmt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ pub use defmt_macros::timestamp;
/// const A = 0b00000001;
/// const B = 0b00000010;
/// const C = 0b00000100;
/// const ABC = Self::A.bits | Self::B.bits | Self::C.bits;
/// const ABC = Self::A.bits() | Self::B.bits() | Self::C.bits();
/// }
/// }
///
Expand Down
12 changes: 6 additions & 6 deletions firmware/qemu/src/bin/bitflags.out
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
INFO Flags::empty(): FLAG_0
INFO Flags::empty(): FLAG_0 (fmt::Debug)
INFO Flags::empty(): Flags(0x0) (fmt::Debug)
INFO Flags::all(): FLAG_1 | FLAG_2 | FLAG_7 | FLAG_7_COPY
INFO Flags::all(): FLAG_1 | FLAG_2 | FLAG_7 | FLAG_7_COPY (fmt::Debug)
INFO Flags::all(): Flags(FLAG_1 | FLAG_2 | FLAG_7) (fmt::Debug)
INFO Flags::FLAG_1: FLAG_1
INFO Flags::FLAG_1: FLAG_1 (fmt::Debug)
INFO Flags::FLAG_1: Flags(FLAG_1) (fmt::Debug)
INFO Flags::FLAG_7: FLAG_7 | FLAG_7_COPY
INFO Flags::FLAG_7: FLAG_7 | FLAG_7_COPY (fmt::Debug)
INFO Flags::FLAG_7: Flags(FLAG_7) (fmt::Debug)
INFO LargeFlags::ALL: MSB | ALL | NON_LITERAL
INFO LargeFlags::ALL: MSB | ALL | NON_LITERAL (fmt::Debug)
INFO LargeFlags::ALL: LargeFlags(MSB | ALL) (fmt::Debug)
INFO LargeFlags::empty(): (empty)
INFO LargeFlags::empty(): (empty) (fmt::Debug)
INFO LargeFlags::empty(): LargeFlags(0x0) (fmt::Debug)
4 changes: 3 additions & 1 deletion firmware/qemu/src/bin/bitflags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@ use defmt::{bitflags, Debug2Format};
use defmt_semihosting as _; // global logger

bitflags! {
#[derive(Debug)]
struct Flags: u8 {
#[cfg(not(never))]
const FLAG_0 = 0b00;
const FLAG_1 = 0b01;
const FLAG_2 = 0b10;
const FLAG_7 = 1 << 7;

const FLAG_7_COPY = Self::FLAG_7.bits;
const FLAG_7_COPY = Self::FLAG_7.bits();

#[cfg(never)]
const CFGD_OUT = 1;
}
}

bitflags! {
#[derive(Debug)]
struct LargeFlags: u128 {
const MSB = 1 << 127;
const ALL = !0;
Expand Down
2 changes: 1 addition & 1 deletion macros/src/items/bitflags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn codegen_flag_statics(input: &Input) -> Vec<TokenStream2> {
// causes a value such as `1 << 127` to be evaluated as an `i32`, which
// overflows. So we instead coerce (but don't cast) it to the bitflags' raw
// type, and then cast that to u128.
let coerced_value: #repr_ty = #struct_name::#var_name.bits;
let coerced_value: #repr_ty = #struct_name::#var_name.bits();
coerced_value as u128
};
}
Expand Down
Loading