From 4ecdbb3339a4250bc66a25398ddaa44f6fc47eeb Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Fri, 28 Mar 2025 13:59:08 +0100 Subject: [PATCH 1/7] Update deps and compiler version Signed-off-by: Oliver Tale-Yazdi --- Cargo.toml | 6 +++--- README.md | 5 +++-- rust-toolchain.toml | 2 +- typesafe-builders/Cargo.toml | 2 +- .../ui/reject/field_attr/ctor/missing_arg.stderr | 4 ++-- .../tests/ui/reject/field_missing_required_2.rs | 4 ++-- .../ui/reject/field_missing_required_2.stderr | 16 ---------------- 7 files changed, 12 insertions(+), 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d99459d..c144072 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,6 @@ typesafe-builders-derive = { path = "typesafe-builders-derive", version = "0.5.0 # External deps derive-syn-parse = { version = "0.1.5", default-features = false } -proc-macro2 = { version = "1.0.56", default-features = false } -quote = { version = "1.0.26", default-features = false } -syn = "2.0.15" +proc-macro2 = { version = "1.0.94", default-features = false } +quote = { version = "1.0.40", default-features = false } +syn = "2.0.100" diff --git a/README.md b/README.md index 71a3991..b8d8181 100644 --- a/README.md +++ b/README.md @@ -120,7 +120,8 @@ pub struct Struct { fn main() { Struct::builder(4).build(); - // does not work: + + // This does not compile since `x` is already set: // Struct::builder(4).x(5).build(); } ``` @@ -139,7 +140,7 @@ pub struct Struct { } fn main() { - // Use `4` instead of `Some(4)` + // You can use `4` now instead of `Some(4)`: Struct::builder().x(4).build(); } ``` diff --git a/rust-toolchain.toml b/rust-toolchain.toml index eddf09d..1dad9bb 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2023-05-04" +channel = "nightly-2025-03-27" components = [ "rustfmt", "clippy" ] profile = "minimal" diff --git a/typesafe-builders/Cargo.toml b/typesafe-builders/Cargo.toml index ab57920..aa9c7e0 100644 --- a/typesafe-builders/Cargo.toml +++ b/typesafe-builders/Cargo.toml @@ -18,4 +18,4 @@ typesafe-builders-core.workspace = true typesafe-builders-derive.workspace = true [dev-dependencies] -trybuild = "1.0.80" +trybuild = "1.0.90" diff --git a/typesafe-builders/tests/ui/reject/field_attr/ctor/missing_arg.stderr b/typesafe-builders/tests/ui/reject/field_attr/ctor/missing_arg.stderr index fc8c338..841c3f3 100644 --- a/typesafe-builders/tests/ui/reject/field_attr/ctor/missing_arg.stderr +++ b/typesafe-builders/tests/ui/reject/field_attr/ctor/missing_arg.stderr @@ -2,7 +2,7 @@ error[E0061]: this function takes 1 argument but 0 arguments were supplied --> tests/ui/reject/field_attr/ctor/missing_arg.rs:10:2 | 10 | Struct::builder().build(); - | ^^^^^^^^^^^^^^^-- an argument of type `u8` is missing + | ^^^^^^^^^^^^^^^-- argument #1 of type `u8` is missing | note: associated function defined here --> tests/ui/reject/field_attr/ctor/missing_arg.rs:3:10 @@ -16,4 +16,4 @@ note: associated function defined here help: provide the argument | 10 | Struct::builder(/* u8 */).build(); - | ~~~~~~~~~~ + | ++++++++ diff --git a/typesafe-builders/tests/ui/reject/field_missing_required_2.rs b/typesafe-builders/tests/ui/reject/field_missing_required_2.rs index bff9c04..151ed20 100644 --- a/typesafe-builders/tests/ui/reject/field_missing_required_2.rs +++ b/typesafe-builders/tests/ui/reject/field_missing_required_2.rs @@ -1,7 +1,7 @@ -use typesafe_builders::prelude::*; - //! `Option` is *not* treated as optional. +use typesafe_builders::prelude::*; + #[derive(Builder)] struct Struct { x: Option, diff --git a/typesafe-builders/tests/ui/reject/field_missing_required_2.stderr b/typesafe-builders/tests/ui/reject/field_missing_required_2.stderr index 19bfa33..bf3d90e 100644 --- a/typesafe-builders/tests/ui/reject/field_missing_required_2.stderr +++ b/typesafe-builders/tests/ui/reject/field_missing_required_2.stderr @@ -1,19 +1,3 @@ -error[E0753]: expected outer doc comment - --> tests/ui/reject/field_missing_required_2.rs:3:1 - | -3 | //! `Option` is *not* treated as optional. - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -6 | / struct Struct { -7 | | x: Option, -8 | | } - | |_- the inner doc comment doesn't annotate this struct - | -help: to annotate the struct, change the doc comment from inner to outer style - | -3 | /// `Option` is *not* treated as optional. - | ~ - error[E0599]: no method named `build` found for struct `GenericStructBuilder` in the current scope --> tests/ui/reject/field_missing_required_2.rs:11:20 | From f104e718516561b958da2b806e87a919fa4d6bc9 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Fri, 28 Mar 2025 14:00:17 +0100 Subject: [PATCH 2/7] Bump to 0.5.1 Signed-off-by: Oliver Tale-Yazdi --- Cargo.toml | 2 +- MAINTAIN | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c144072..2c927e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace.package] edition = "2021" -version = "0.5.0" +version = "0.5.1" authors = ["Oliver Tale-Yazdi "] license = "GPL-3.0-only" repository = "https://github.com/ggwpez/typesafe-builders" diff --git a/MAINTAIN b/MAINTAIN index 1578826..c77843b 100644 --- a/MAINTAIN +++ b/MAINTAIN @@ -1,9 +1,9 @@ Without any un-staged changes: ```bash -git tag -s -f typesafe-builders@0.4.1 -m "typesafe-builders v0.4.1" -git tag -s -f typesafe-builders-core@0.4.1 -m "typesafe-builders-core v0.4.1" -git tag -s -f typesafe-builders-derive@0.4.1 -m "typesafe-builders-derive v0.4.1" +git tag -s -f typesafe-builders@0.5.1 -m "typesafe-builders v0.5.1" +git tag -s -f typesafe-builders-core@0.5.1 -m "typesafe-builders-core v0.5.1" +git tag -s -f typesafe-builders-derive@0.5.1 -m "typesafe-builders-derive v0.5.1" cargo publish -p typesafe-builders-core && cargo publish -p typesafe-builders-derive && cargo publish -p typesafe-builders ``` From 78d6f802c2c18ed050cd5f93414219bf3bd6c4ce Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Fri, 28 Mar 2025 14:03:03 +0100 Subject: [PATCH 3/7] fmt Signed-off-by: Oliver Tale-Yazdi --- typesafe-builders-core/src/lib.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/typesafe-builders-core/src/lib.rs b/typesafe-builders-core/src/lib.rs index 4f2df0f..df86cb5 100644 --- a/typesafe-builders-core/src/lib.rs +++ b/typesafe-builders-core/src/lib.rs @@ -51,11 +51,8 @@ struct ParsedFieldAttr { pub fn impl_derive_builder(ast: &syn::DeriveInput) -> syn::Result { let syn::Data::Struct(ref s) = ast.data else { - return Err(syn::Error::new_spanned( - ast, - "derive(Builder) can only be used on structs", - )); - }; + return Err(syn::Error::new_spanned(ast, "derive(Builder) can only be used on structs")); + }; let mut user_generics_def = Vec::<&syn::GenericParam>::new(); let mut user_generics_impl = Vec::::new(); let mut user_generics_alias = Vec::::new(); From 592acb1793f699bd61c2720a92cb725e03aa1fb1 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Fri, 28 Mar 2025 14:20:44 +0100 Subject: [PATCH 4/7] clippy Signed-off-by: Oliver Tale-Yazdi --- README.md | 74 ++++++++++++++++++++++--------------------------------- 1 file changed, 30 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index b8d8181..1d7850a 100644 --- a/README.md +++ b/README.md @@ -27,29 +27,27 @@ No more worrying whether the `build` call on your builder will return `Ok` or no ```rust use typesafe_builders::prelude::*; -fn main() { - #[derive(Builder)] - struct Point { - #[builder(constructor)] - x: u8, - y: u8, - #[builder(optional)] - z: Option, - } +#[derive(Builder)] +struct Point { + #[builder(constructor)] + x: u8, + y: u8, + #[builder(optional)] + z: Option, +} - // `builder` requires `x` since it is marked as `constructor`. - let builder = Point::builder(1); - // These do not compile: - // partial.x(6); // `x` is already set - // partial.build(); // `y` is not set +// `builder` requires `x` since it is marked as `constructor`. +let builder = Point::builder(1); +// These do not compile: +// partial.x(6); // `x` is already set +// partial.build(); // `y` is not set - // `build` is only available once all required fields are set: - let result = builder.y(2).build(); +// `build` is only available once all required fields are set: +let result = builder.y(2).build(); - assert_eq!(result.x, 1); - assert_eq!(result.y, 2); - assert_eq!(result.z, None); -} +assert_eq!(result.x, 1); +assert_eq!(result.y, 2); +assert_eq!(result.z, None); ``` @@ -97,12 +95,10 @@ pub struct Struct { x: u8, } -fn main() { - // without x - Struct::builder().build(); - // with x - Struct::builder().x(4).build(); -} +// without x +Struct::builder().build(); + // with x +Struct::builder().x(4).build(); ``` ### Constructor @@ -118,12 +114,10 @@ pub struct Struct { x: u8, } -fn main() { - Struct::builder(4).build(); +Struct::builder(4).build(); - // This does not compile since `x` is already set: - // Struct::builder(4).x(5).build(); -} +// This does not compile since `x` is already set: +// Struct::builder(4).x(5).build(); ``` ### Decay @@ -139,10 +133,8 @@ pub struct Struct { x: Option, } -fn main() { - // You can use `4` now instead of `Some(4)`: - Struct::builder().x(4).build(); -} +// You can use `4` now instead of `Some(4)`: +Struct::builder().x(4).build(); ``` # How does it work? @@ -189,9 +181,7 @@ pub struct Struct<'a, 'b, 'c> { x: &'a Box<&'b Option<&'c str>>, // yikes } -fn main() { - Struct::builder().x(&Box::new(&Some("hi"))).build(); -} +Struct::builder().x(&Box::new(&Some("hi"))).build(); ``` ### Generics @@ -208,9 +198,7 @@ mod other { } } -fn main() { - other::Struct::::builder().y(Some(4)).build(); -} +other::Struct::::builder().y(Some(4)).build(); ``` ### Const Generics @@ -227,9 +215,7 @@ mod other { } } -fn main() { - other::Struct::<1>::builder().x([1]).build(); -} +other::Struct::<1>::builder().x([1]).build(); ``` # TODOs From aad50d414b27a8bcd0a48b83e33e86327b5d910a Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Wed, 3 Sep 2025 22:59:27 +0200 Subject: [PATCH 5/7] Fix test Signed-off-by: Oliver Tale-Yazdi --- .github/workflows/rust.yml | 2 +- Cargo.toml | 6 +++--- rust-toolchain.toml | 2 +- typesafe-builders/tests/ui/reject/builder_priv.stderr | 2 +- .../tests/ui/reject/field_attr/ctor/missing_arg.stderr | 4 ++-- .../tests/ui/reject/field_missing_required_2.stderr | 6 +++--- .../tests/ui/reject/field_set_constructor.stderr | 6 +++--- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 312bf69..2fc7860 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -27,7 +27,7 @@ jobs: run: cargo fmt --all -- --check - name: Build - run: cargo build --all-targets --all-features # --locked TODO + run: cargo build --all-targets --all-features --locked - name: Test run: cargo test --locked --all-targets --all-features diff --git a/Cargo.toml b/Cargo.toml index 2c927e6..99c5276 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ typesafe-builders-core = { path = "typesafe-builders-core", version = "0.5.0" } typesafe-builders-derive = { path = "typesafe-builders-derive", version = "0.5.0" } # External deps -derive-syn-parse = { version = "0.1.5", default-features = false } -proc-macro2 = { version = "1.0.94", default-features = false } +derive-syn-parse = { version = "0.2.0", default-features = false } +proc-macro2 = { version = "1.0.101", default-features = false } quote = { version = "1.0.40", default-features = false } -syn = "2.0.100" +syn = "2.0.106" diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 1dad9bb..e5d0b33 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2025-03-27" +channel = "nightly-2025-09-01" components = [ "rustfmt", "clippy" ] profile = "minimal" diff --git a/typesafe-builders/tests/ui/reject/builder_priv.stderr b/typesafe-builders/tests/ui/reject/builder_priv.stderr index d489364..ba3a5f7 100644 --- a/typesafe-builders/tests/ui/reject/builder_priv.stderr +++ b/typesafe-builders/tests/ui/reject/builder_priv.stderr @@ -7,5 +7,5 @@ error[E0603]: struct `Struct` is private note: the struct `Struct` is defined here --> tests/ui/reject/builder_priv.rs:5:2 | -5 | struct Struct { + 5 | struct Struct { | ^^^^^^^^^^^^^ diff --git a/typesafe-builders/tests/ui/reject/field_attr/ctor/missing_arg.stderr b/typesafe-builders/tests/ui/reject/field_attr/ctor/missing_arg.stderr index 841c3f3..765036e 100644 --- a/typesafe-builders/tests/ui/reject/field_attr/ctor/missing_arg.stderr +++ b/typesafe-builders/tests/ui/reject/field_attr/ctor/missing_arg.stderr @@ -7,10 +7,10 @@ error[E0061]: this function takes 1 argument but 0 arguments were supplied note: associated function defined here --> tests/ui/reject/field_attr/ctor/missing_arg.rs:3:10 | -3 | #[derive(Builder)] + 3 | #[derive(Builder)] | ^^^^^^^ ... -6 | x: u8, + 6 | x: u8, | ----- = note: this error originates in the derive macro `Builder` (in Nightly builds, run with -Z macro-backtrace for more info) help: provide the argument diff --git a/typesafe-builders/tests/ui/reject/field_missing_required_2.stderr b/typesafe-builders/tests/ui/reject/field_missing_required_2.stderr index bf3d90e..8524d4a 100644 --- a/typesafe-builders/tests/ui/reject/field_missing_required_2.stderr +++ b/typesafe-builders/tests/ui/reject/field_missing_required_2.stderr @@ -1,7 +1,7 @@ error[E0599]: no method named `build` found for struct `GenericStructBuilder` in the current scope - --> tests/ui/reject/field_missing_required_2.rs:11:20 - | -5 | #[derive(Builder)] + --> tests/ui/reject/field_missing_required_2.rs:11:20 + | + 5 | #[derive(Builder)] | ------- method `build` not found for this struct ... 11 | Struct::builder().build(); diff --git a/typesafe-builders/tests/ui/reject/field_set_constructor.stderr b/typesafe-builders/tests/ui/reject/field_set_constructor.stderr index cd0fe79..9a35b9b 100644 --- a/typesafe-builders/tests/ui/reject/field_set_constructor.stderr +++ b/typesafe-builders/tests/ui/reject/field_set_constructor.stderr @@ -1,7 +1,7 @@ error[E0599]: no method named `x` found for struct `GenericStructBuilder` in the current scope - --> tests/ui/reject/field_set_constructor.rs:10:29 - | -3 | #[derive(Builder)] + --> tests/ui/reject/field_set_constructor.rs:10:29 + | + 3 | #[derive(Builder)] | ------- method `x` not found for this struct ... 10 | let r = Struct::builder(2).x(3).build(); From 5d5c84079d9dbfcd9ae96c390eac5100ba3911f4 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Wed, 3 Sep 2025 23:00:16 +0200 Subject: [PATCH 6/7] Bump version Signed-off-by: Oliver Tale-Yazdi --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 99c5276..739ab9b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace.package] edition = "2021" -version = "0.5.1" +version = "0.5.2" authors = ["Oliver Tale-Yazdi "] license = "GPL-3.0-only" repository = "https://github.com/ggwpez/typesafe-builders" From a4586a6b426878ccdfaa0bb65e3d9f2e5fc446f8 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Wed, 3 Sep 2025 23:00:52 +0200 Subject: [PATCH 7/7] no lockfile Signed-off-by: Oliver Tale-Yazdi --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 2fc7860..312bf69 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -27,7 +27,7 @@ jobs: run: cargo fmt --all -- --check - name: Build - run: cargo build --all-targets --all-features --locked + run: cargo build --all-targets --all-features # --locked TODO - name: Test run: cargo test --locked --all-targets --all-features