diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 746bc83..49755fa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/Cargo.toml b/Cargo.toml index a2df83d..a392cd3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,9 +7,9 @@ [package] name = "fixed-macro" -version = "1.1.1" # !V +version = "1.2.0" # !V authors = ["Ivan Smirnov "] -edition = "2018" +edition = "2021" license = "MIT OR Apache-2.0" repository = "https://github.com/aldanor/fixed-macro" documentation = "https://docs.rs/fixed-macro" @@ -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" diff --git a/README.md b/README.md index c2313a9..0a00671 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/impl/Cargo.toml b/impl/Cargo.toml index 2004816..d639287 100644 --- a/impl/Cargo.toml +++ b/impl/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fixed-macro-impl" -version = "1.1.1" # !V +version = "1.2.0" # !V authors = ["Ivan Smirnov "] edition = "2018" license = "MIT OR Apache-2.0" diff --git a/impl/src/dispatch.rs b/impl/src/dispatch.rs index 79420af..8df73cb 100644 --- a/impl/src/dispatch.rs +++ b/impl/src/dispatch.rs @@ -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::[]::from_str]($s) + return paste![] as std::str::FromStr>::from_str]($s) .map(|x| x.to_bits()).map(paste![Literal::[]]) } else if ($int_bits, $frac_bits, $signed) == ($i, $f, false) { - return paste![fixed::types::[]::from_str]($s) + return paste![] as std::str::FromStr>::from_str]($s) .map(|x| x.to_bits()).map(paste![Literal::[]]) } }; diff --git a/impl/src/lib.rs b/impl/src/lib.rs index cf200a1..68983b6 100644 --- a/impl/src/lib.rs +++ b/impl/src/lib.rs @@ -25,7 +25,7 @@ impl FixedType { pub fn from_ident(ident: &Ident) -> Result { fn parse_size(s: &str) -> Option { - 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); @@ -64,7 +64,7 @@ fn normalize_float(float: &str) -> Result { } _ => 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 { diff --git a/tests/compile-fail/literal-and-semi.stderr b/tests/compile-fail/literal-and-semi.stderr index 476e016..e21e493 100644 --- a/tests/compile-fail/literal-and-semi.stderr +++ b/tests/compile-fail/literal-and-semi.stderr @@ -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) diff --git a/tests/compile-fail/no-input.stderr b/tests/compile-fail/no-input.stderr index 95108b4..cea1201 100644 --- a/tests/compile-fail/no-input.stderr +++ b/tests/compile-fail/no-input.stderr @@ -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) diff --git a/tests/compile-fail/only-literal.stderr b/tests/compile-fail/only-literal.stderr index a6d937b..766676e 100644 --- a/tests/compile-fail/only-literal.stderr +++ b/tests/compile-fail/only-literal.stderr @@ -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) diff --git a/tests/compile-fail/single-minus.stderr b/tests/compile-fail/single-minus.stderr index 21b9d87..7204df3 100644 --- a/tests/compile-fail/single-minus.stderr +++ b/tests/compile-fail/single-minus.stderr @@ -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) diff --git a/tests/test_fixed_macro.rs b/tests/test_fixed_macro.rs index 3fe39f2..52c0426 100644 --- a/tests/test_fixed_macro.rs +++ b/tests/test_fixed_macro.rs @@ -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); diff --git a/types/Cargo.toml b/types/Cargo.toml index 823605b..2264961 100644 --- a/types/Cargo.toml +++ b/types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fixed-macro-types" -version = "1.1.1" # !V +version = "1.2.0" # !V authors = ["Ivan Smirnov "] edition = "2018" license = "MIT OR Apache-2.0" @@ -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"]