Skip to content

Commit

Permalink
Merge pull request #8 from aldanor/feature/1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aldanor committed Oct 16, 2022
2 parents 02e5d6c + 6ccd2ec commit 2cc4460
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 31 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ jobs:
- run: cargo test

msrv:
name: Rust 1.45.0
name: Rust 1.61.0
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: dtolnay/rust-toolchain@1.45.0
- uses: dtolnay/rust-toolchain@1.61.0
- run: cargo check --tests
- run: cargo test test_fixed_macro

clippy:
name: Clippy
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

[package]
name = "fixed-macro"
version = "1.1.1" # !V
version = "1.2.0" # !V
authors = ["Ivan Smirnov <i.s.smirnov@gmail.com>"]
edition = "2018"
edition = "2021"
license = "MIT OR Apache-2.0"
repository = "https://github.com/aldanor/fixed-macro"
documentation = "https://docs.rs/fixed-macro"
Expand All @@ -23,8 +23,8 @@ members = [".", "impl", "types"]

[dependencies]
fixed = "1"
fixed-macro-impl = { version = "1.1.1", path = "impl" } # !V
fixed-macro-types = { version = "1.1.1", path = "types" } # !V
fixed-macro-impl = { version = "1.2.0", path = "impl" } # !V
fixed-macro-types = { version = "1.2.0", path = "types" } # !V

[dev-dependencies]
trybuild = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ easily creating fixed-point constants for all of the fixed-point types provided
fixed-macro = "1.1"
```

*Compiler support: rustc 1.45+.*
*Compiler support: rustc 1.61+.*

[fixed]: https://docs.rs/fixed
[fixed-types]: https://docs.rs/fixed/latest/fixed/types/index.html
Expand Down
2 changes: 1 addition & 1 deletion impl/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fixed-macro-impl"
version = "1.1.1" # !V
version = "1.2.0" # !V
authors = ["Ivan Smirnov <i.s.smirnov@gmail.com>"]
edition = "2018"
license = "MIT OR Apache-2.0"
Expand Down
6 changes: 2 additions & 4 deletions impl/src/dispatch.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use std::str::FromStr;

use paste::paste;
use proc_macro2::Literal;

macro_rules! fixed_to_literal {
($int_bits:expr, $frac_bits:expr, $signed:expr, $s:expr, $w:expr, $i:expr, $f:expr) => {
if ($int_bits, $frac_bits, $signed) == ($i, $f, true) {
return paste![fixed::types::[<I $i F $f>]::from_str]($s)
return paste![<fixed::types::[<I $i F $f>] as std::str::FromStr>::from_str]($s)
.map(|x| x.to_bits()).map(paste![Literal::[<i $w _unsuffixed>]])
} else if ($int_bits, $frac_bits, $signed) == ($i, $f, false) {
return paste![fixed::types::[<U $i F $f>]::from_str]($s)
return paste![<fixed::types::[<U $i F $f>] as std::str::FromStr>::from_str]($s)
.map(|x| x.to_bits()).map(paste![Literal::[<u $w _unsuffixed>]])
}
};
Expand Down
4 changes: 2 additions & 2 deletions impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl FixedType {

pub fn from_ident(ident: &Ident) -> Result<Self, &'static str> {
fn parse_size(s: &str) -> Option<u8> {
if s.chars().next()?.is_digit(10) {
if s.chars().next()?.is_ascii_digit() {
let num = u8::from_str(s).ok()?;
if num <= 128 {
return Some(num);
Expand Down Expand Up @@ -64,7 +64,7 @@ fn normalize_float(float: &str) -> Result<String, &'static str> {
}
_ => 0,
};
let idx = float.find('.').unwrap_or_else(|| float.len());
let idx = float.find('.').unwrap_or(float.len());
let mut int = float[..idx].to_owned();
let mut frac = float[idx + 1..].to_owned();
while exp > 0 {
Expand Down
6 changes: 3 additions & 3 deletions tests/compile-fail/literal-and-semi.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error: unexpected end of input, expected identifier
--> $DIR/literal-and-semi.rs:2:5
--> tests/compile-fail/literal-and-semi.rs:2:5
|
2 | fixed_macro::fixed!(123.45:);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `fixed_macro::fixed` (in Nightly builds, run with -Z macro-backtrace for more info)
6 changes: 3 additions & 3 deletions tests/compile-fail/no-input.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error: unexpected end of input, expected literal
--> $DIR/no-input.rs:2:5
--> tests/compile-fail/no-input.rs:2:5
|
2 | fixed_macro::fixed!();
| ^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `fixed_macro::fixed` (in Nightly builds, run with -Z macro-backtrace for more info)
6 changes: 3 additions & 3 deletions tests/compile-fail/only-literal.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error: expected `:`
--> $DIR/only-literal.rs:2:5
--> tests/compile-fail/only-literal.rs:2:5
|
2 | fixed_macro::fixed!(123.45);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `fixed_macro::fixed` (in Nightly builds, run with -Z macro-backtrace for more info)
6 changes: 3 additions & 3 deletions tests/compile-fail/single-minus.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error: unexpected end of input, expected literal
--> $DIR/single-minus.rs:2:5
--> tests/compile-fail/single-minus.rs:2:5
|
2 | fixed_macro::fixed!(-);
| ^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `fixed_macro::fixed` (in Nightly builds, run with -Z macro-backtrace for more info)
4 changes: 1 addition & 3 deletions tests/test_fixed_macro.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use std::str::FromStr;

use fixed_macro::fixed;

macro_rules! check_fixed {
($ty:ident, $repr:expr, $($value:tt)+) => {{
const X: $ty = fixed!($($value)+: $ty);
assert_eq!(X, $ty::from_str($repr).unwrap());
assert_eq!(X, <$ty as std::str::FromStr>::from_str($repr).unwrap());
assert_eq!(format!("{}", X), $repr);
const Y: $ty = fixed_macro::types::$ty!($($value)+);
assert_eq!(X, Y);
Expand Down
4 changes: 2 additions & 2 deletions types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fixed-macro-types"
version = "1.1.1" # !V
version = "1.2.0" # !V
authors = ["Ivan Smirnov <i.s.smirnov@gmail.com>"]
edition = "2018"
license = "MIT OR Apache-2.0"
Expand All @@ -10,7 +10,7 @@ description = "Macro aliases used in the `fixed-macro` crate."

[dependencies]
fixed = "1"
fixed-macro-impl = { version = "1.1.1", path = "../impl" } # !V
fixed-macro-impl = { version = "1.2.0", path = "../impl" } # !V

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

0 comments on commit 2cc4460

Please sign in to comment.