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

Make macro more robust against empty identifiers that come in while being used in an IDE #54

Merged
merged 1 commit into from
Mar 2, 2024
Merged
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
31 changes: 23 additions & 8 deletions bitbybit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# Changelog

## bitbybit 1.3.2

### Fixed

- Fixed macro behavior when used within an IDE. The macro sees empty identifiers which don't happen
during regular compilation. These are now ignored to allow proper autocomplete again.

## bitbybit 1.3.1

### Fixed

- Fixed a compilation error when non-contiguous ranges would produce a regular int (u8, u16, etc.).

## bitbybit 1.3.0
Expand All @@ -11,7 +19,9 @@

- Support for non-contiguous bitranges
- Removed experimental_builder_syntax feature; this is now always enabled
- Switched default attribute argument syntax from field type to assignment type (colon field style is still allowed, but might be deprecated in the future):
- Switched default attribute argument syntax from field type to assignment type (colon field style
is still allowed, but might be deprecated in the future):

```rs
#[bitenum(u2, exhaustive = true)]
enum ExhaustiveEnum {
Expand All @@ -35,7 +45,9 @@ struct BitfieldWithEnum {

### Added

- Bitfields can support any arbitrary-int as a base-data-type, not just built-ins. For example, this is now supported:
- Bitfields can support any arbitrary-int as a base-data-type, not just built-ins. For example, this
is now supported:

```rs
#[bitfield(u12)]
struct Bitfield {
Expand All @@ -47,32 +59,35 @@ struct Bitfield {

### Fixed

- Multi-line doc-comments on fields are now fully put into the resulting accessors (previously, just the last line was)
- Multi-line doc-comments on fields are now fully put into the resulting accessors (previously, just
the last line was)
- Masking of signed fields setters is now correct


## bitbybit 1.2.1

### Added

- Experimental new `builder()`...`build()` syntax, which allows setting all values without the risk of forgetting any. Requires opt-in via new `experimental_builder_syntax` feature
- Experimental new `builder()`...`build()` syntax, which allows setting all values without the risk
of forgetting any. Requires opt-in via new `experimental_builder_syntax` feature
- Bump to [arbitrary-int](https://crates.io/crates/arbitrary-int) version 1.2.6

### Changed

### Fixed

- Accessors for array fields now assert that the index is within the size of the array.
- Most usage errors are now associated correctly to the line where they happen, instead of at the top of the declaration.

- Most usage errors are now associated correctly to the line where they happen, instead of at the
top of the declaration.

## bitbybit 1.2.0

### Added

### Changed

- `new()` has caused some confusion - it's a harmless way to create a default. In practice, this wasn't really clear and people thought the function might read e.g. from hardware. `new()` is now deprecated. `default()` (or `DEFAULT` in const contexts) take its place.
- `new()` has caused some confusion - it's a harmless way to create a default. In practice, this
wasn't really clear and people thought the function might read e.g. from hardware. `new()` is now
deprecated. `default()` (or `DEFAULT` in const contexts) take its place.

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion bitbybit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bitbybit"
version = "1.3.1"
version = "1.3.2"
authors = ["Daniel Lehmann <[email protected]>"]
edition = "2021"
description = "Efficient implementation of bit-fields where several numbers are packed within a larger number and bit-enums. Useful for drivers, so it works in no_std environments"
Expand Down
7 changes: 5 additions & 2 deletions bitbybit/src/bitfield/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,15 +491,18 @@ impl ArgumentParser {
}

fn take_ident(&self, id: Ident) -> Result<ArgumentParser, Error> {
let s = id.span().source_text().unwrap_or("".to_string());
let s = id.to_string();
match self {
ArgumentParser::Reset if s == "rw" => Ok(ArgumentParser::ReadWrite),
ArgumentParser::Reset if s == "r" => Ok(ArgumentParser::Read),
ArgumentParser::Reset if s == "w" => Ok(ArgumentParser::Write),
ArgumentParser::Reset if s == "stride" => Ok(ArgumentParser::StrideStarted),
_ => Err(Error::new_spanned(
&id,
"bitfield!: Invalid ident. Expected r, rw, w or stride",
format!(
"bitfield!: Invalid ident '{}'. Expected r, rw, w or stride",
s
),
)),
}
}
Expand Down
Loading