diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dd99af62..3979e416 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -125,6 +125,10 @@ jobs: cargo test ${{ matrix.locked }} --workspace --all-features \ --exclude runtime-benchmarks --doc + - run: | + cd bon && cargo test ${{ matrix.locked }} \ + --features=experimental-overwritable + - run: | cd bon && cargo test ${{ matrix.locked }} --no-default-features \ --features=experimental-overwritable diff --git a/bon/tests/integration/builder/attr_with/mod.rs b/bon/tests/integration/builder/attr_with/mod.rs index ac7eb0bf..1fb7b8a0 100644 --- a/bon/tests/integration/builder/attr_with/mod.rs +++ b/bon/tests/integration/builder/attr_with/mod.rs @@ -1,5 +1,6 @@ mod from_iter; mod multi_arg; +#[cfg(feature = "experimental-overwritable")] mod overwritable; mod single_arg; mod some; diff --git a/bon/tests/integration/builder/mod.rs b/bon/tests/integration/builder/mod.rs index 1dd46038..9f6a86d1 100644 --- a/bon/tests/integration/builder/mod.rs +++ b/bon/tests/integration/builder/mod.rs @@ -9,6 +9,7 @@ mod attr_getter; mod attr_into; mod attr_into_future; mod attr_on; +#[cfg(feature = "experimental-overwritable")] mod attr_overwritable; mod attr_required; mod attr_setters; diff --git a/bon/tests/integration/ui/compile_fail/attr_getter.rs b/bon/tests/integration/ui/compile_fail/attr_getter.rs index 3fe7a5b9..de3550f6 100644 --- a/bon/tests/integration/ui/compile_fail/attr_getter.rs +++ b/bon/tests/integration/ui/compile_fail/attr_getter.rs @@ -18,12 +18,6 @@ struct SkipCompat { x: u32, } -#[derive(Builder)] -struct OverwritableCompat { - #[builder(getter, overwritable)] - x: u32, -} - #[derive(Builder)] struct NegativeTest { #[builder(getter)] diff --git a/bon/tests/integration/ui/compile_fail/attr_getter.stderr b/bon/tests/integration/ui/compile_fail/attr_getter.stderr index 535844bd..1ac799e7 100644 --- a/bon/tests/integration/ui/compile_fail/attr_getter.stderr +++ b/bon/tests/integration/ui/compile_fail/attr_getter.stderr @@ -16,12 +16,6 @@ error: `skip` attribute can't be specified together with `getter` 17 | #[builder(getter, skip)] | ^^^^ -error: `getter` attribute can't be specified together with `overwritable` - --> tests/integration/ui/compile_fail/attr_getter.rs:23:15 - | -23 | #[builder(getter, overwritable)] - | ^^^^^^ - error: can't infer the `Deref::Target` for the getter from the member's type; please specify the return type (target of the deref coercion) explicitly in parentheses without the leading `&`; example: `#[builder(getter(deref(TargetTypeHere))]` @@ -35,33 +29,33 @@ error: can't infer the `Deref::Target` for the getter from the member's type; pl - OsString - PathBuf - Cow - --> tests/integration/ui/compile_fail/attr_getter.rs:80:22 + --> tests/integration/ui/compile_fail/attr_getter.rs:74:22 | -80 | #[builder(getter(deref))] +74 | #[builder(getter(deref))] | ^^^^^ error: `copy` can't be specified together with `clone` - --> tests/integration/ui/compile_fail/attr_getter.rs:86:22 + --> tests/integration/ui/compile_fail/attr_getter.rs:80:22 | -86 | #[builder(getter(copy, clone))] +80 | #[builder(getter(copy, clone))] | ^^^^ error: `copy` can't be specified together with `deref` - --> tests/integration/ui/compile_fail/attr_getter.rs:92:22 + --> tests/integration/ui/compile_fail/attr_getter.rs:86:22 | -92 | #[builder(getter(copy, deref))] +86 | #[builder(getter(copy, deref))] | ^^^^ error: `clone` can't be specified together with `deref` - --> tests/integration/ui/compile_fail/attr_getter.rs:98:22 + --> tests/integration/ui/compile_fail/attr_getter.rs:92:22 | -98 | #[builder(getter(clone, deref))] +92 | #[builder(getter(clone, deref))] | ^^^^^ error[E0277]: the trait bound `String: std::marker::Copy` is not satisfied - --> tests/integration/ui/compile_fail/attr_getter.rs:42:9 + --> tests/integration/ui/compile_fail/attr_getter.rs:36:9 | -42 | x1: String, +36 | x1: String, | ^^^^^^ the trait `std::marker::Copy` is not implemented for `String` | note: required by a bound in `copy_member` @@ -71,9 +65,9 @@ note: required by a bound in `copy_member` | ^^^^ required by this bound in `copy_member` error[E0277]: the trait bound `String: std::marker::Copy` is not satisfied - --> tests/integration/ui/compile_fail/attr_getter.rs:45:16 + --> tests/integration/ui/compile_fail/attr_getter.rs:39:16 | -45 | x2: Option, +39 | x2: Option, | ^^^^^^ the trait `std::marker::Copy` is not implemented for `String` | note: required by a bound in `copy_member` @@ -83,9 +77,9 @@ note: required by a bound in `copy_member` | ^^^^ required by this bound in `copy_member` error[E0277]: the trait bound `String: std::marker::Copy` is not satisfied - --> tests/integration/ui/compile_fail/attr_getter.rs:48:9 + --> tests/integration/ui/compile_fail/attr_getter.rs:42:9 | -48 | x3: String, +42 | x3: String, | ^^^^^^ the trait `std::marker::Copy` is not implemented for `String` | note: required by a bound in `copy_member` @@ -95,73 +89,73 @@ note: required by a bound in `copy_member` | ^^^^ required by this bound in `copy_member` error[E0277]: the trait bound `NonClone: Clone` is not satisfied - --> tests/integration/ui/compile_fail/attr_getter.rs:57:9 + --> tests/integration/ui/compile_fail/attr_getter.rs:51:9 | -57 | x1: NonClone, +51 | x1: NonClone, | ^^^^^^^^ the trait `Clone` is not implemented for `NonClone` | help: consider annotating `NonClone` with `#[derive(Clone)]` | -52 + #[derive(Clone)] -53 | struct NonClone; +46 + #[derive(Clone)] +47 | struct NonClone; | error[E0277]: the trait bound `NonClone: Clone` is not satisfied - --> tests/integration/ui/compile_fail/attr_getter.rs:60:16 + --> tests/integration/ui/compile_fail/attr_getter.rs:54:16 | -60 | x2: Option, +54 | x2: Option, | ^^^^^^^^ the trait `Clone` is not implemented for `NonClone` | = note: required for `Option` to implement `Clone` help: consider annotating `NonClone` with `#[derive(Clone)]` | -52 + #[derive(Clone)] -53 | struct NonClone; +46 + #[derive(Clone)] +47 | struct NonClone; | error[E0277]: the trait bound `NonClone: Clone` is not satisfied - --> tests/integration/ui/compile_fail/attr_getter.rs:63:9 + --> tests/integration/ui/compile_fail/attr_getter.rs:57:9 | -63 | x3: NonClone, +57 | x3: NonClone, | ^^^^^^^^ the trait `Clone` is not implemented for `NonClone` | = note: required for `Option` to implement `Clone` help: consider annotating `NonClone` with `#[derive(Clone)]` | -52 + #[derive(Clone)] -53 | struct NonClone; +46 + #[derive(Clone)] +47 | struct NonClone; | error[E0308]: mismatched types - --> tests/integration/ui/compile_fail/attr_getter.rs:68:28 + --> tests/integration/ui/compile_fail/attr_getter.rs:62:28 | -66 | #[derive(Builder)] +60 | #[derive(Builder)] | ------- expected `&u64` because of return type -67 | struct NoDeref { -68 | #[builder(getter(deref(u64)))] +61 | struct NoDeref { +62 | #[builder(getter(deref(u64)))] | ^^^ expected `&u64`, found `&String` | = note: expected reference `&u64` found reference `&String` error[E0308]: mismatched types - --> tests/integration/ui/compile_fail/attr_getter.rs:71:28 + --> tests/integration/ui/compile_fail/attr_getter.rs:65:28 | -66 | #[derive(Builder)] +60 | #[derive(Builder)] | ------- arguments to this enum variant are incorrect ... -71 | #[builder(getter(deref(u64)))] +65 | #[builder(getter(deref(u64)))] | ^^^ expected `&u64`, found `&String` | = note: expected reference `&u64` found reference `&String` help: the type constructed contains `&String` due to the type of the argument passed - --> tests/integration/ui/compile_fail/attr_getter.rs:66:10 + --> tests/integration/ui/compile_fail/attr_getter.rs:60:10 | -66 | #[derive(Builder)] +60 | #[derive(Builder)] | ^^^^^^^ ... -71 | #[builder(getter(deref(u64)))] +65 | #[builder(getter(deref(u64)))] | --- this argument influences the type of `Some` note: tuple variant defined here --> $RUST/core/src/option.rs @@ -171,23 +165,23 @@ note: tuple variant defined here = note: this error originates in the derive macro `Builder` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0308]: mismatched types - --> tests/integration/ui/compile_fail/attr_getter.rs:74:28 + --> tests/integration/ui/compile_fail/attr_getter.rs:68:28 | -66 | #[derive(Builder)] +60 | #[derive(Builder)] | ------- arguments to this enum variant are incorrect ... -74 | #[builder(getter(deref(u64)), default)] +68 | #[builder(getter(deref(u64)), default)] | ^^^ expected `&u64`, found `&String` | = note: expected reference `&u64` found reference `&String` help: the type constructed contains `&String` due to the type of the argument passed - --> tests/integration/ui/compile_fail/attr_getter.rs:66:10 + --> tests/integration/ui/compile_fail/attr_getter.rs:60:10 | -66 | #[derive(Builder)] +60 | #[derive(Builder)] | ^^^^^^^ ... -74 | #[builder(getter(deref(u64)), default)] +68 | #[builder(getter(deref(u64)), default)] | --- this argument influences the type of `Some` note: tuple variant defined here --> $RUST/core/src/option.rs @@ -197,55 +191,55 @@ note: tuple variant defined here = note: this error originates in the derive macro `Builder` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the member `Unset` was not set, but this method requires it to be set - --> tests/integration/ui/compile_fail/attr_getter.rs:105:13 - | -105 | builder.get_x1(); - | ^^^^^^ the member `Unset` was not set, but this method requires it to be set - | - = help: the trait `IsSet` is not implemented for `Unset` - = help: the trait `IsSet` is implemented for `Set` + --> tests/integration/ui/compile_fail/attr_getter.rs:99:13 + | +99 | builder.get_x1(); + | ^^^^^^ the member `Unset` was not set, but this method requires it to be set + | + = help: the trait `IsSet` is not implemented for `Unset` + = help: the trait `IsSet` is implemented for `Set` note: required by a bound in `NegativeTestBuilder::::get_x1` - --> tests/integration/ui/compile_fail/attr_getter.rs:27:10 - | -27 | #[derive(Builder)] - | ^^^^^^^ required by this bound in `NegativeTestBuilder::::get_x1` + --> tests/integration/ui/compile_fail/attr_getter.rs:21:10 + | +21 | #[derive(Builder)] + | ^^^^^^^ required by this bound in `NegativeTestBuilder::::get_x1` ... -30 | x1: u32, - | -- required by a bound in this associated function - = note: this error originates in the derive macro `Builder` (in Nightly builds, run with -Z macro-backtrace for more info) +24 | x1: u32, + | -- required by a bound in this associated function + = note: this error originates in the derive macro `Builder` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the member `Unset` was not set, but this method requires it to be set - --> tests/integration/ui/compile_fail/attr_getter.rs:106:13 + --> tests/integration/ui/compile_fail/attr_getter.rs:100:13 | -106 | builder.get_x2(); +100 | builder.get_x2(); | ^^^^^^ the member `Unset` was not set, but this method requires it to be set | = help: the trait `IsSet` is not implemented for `Unset` = help: the trait `IsSet` is implemented for `Set` note: required by a bound in `NegativeTestBuilder::::get_x2` - --> tests/integration/ui/compile_fail/attr_getter.rs:27:10 + --> tests/integration/ui/compile_fail/attr_getter.rs:21:10 | -27 | #[derive(Builder)] +21 | #[derive(Builder)] | ^^^^^^^ required by this bound in `NegativeTestBuilder::::get_x2` ... -33 | x2: Option, +27 | x2: Option, | -- required by a bound in this associated function = note: this error originates in the derive macro `Builder` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the member `Unset` was not set, but this method requires it to be set - --> tests/integration/ui/compile_fail/attr_getter.rs:107:13 + --> tests/integration/ui/compile_fail/attr_getter.rs:101:13 | -107 | builder.get_x3(); +101 | builder.get_x3(); | ^^^^^^ the member `Unset` was not set, but this method requires it to be set | = help: the trait `IsSet` is not implemented for `Unset` = help: the trait `IsSet` is implemented for `Set` note: required by a bound in `NegativeTestBuilder::::get_x3` - --> tests/integration/ui/compile_fail/attr_getter.rs:27:10 + --> tests/integration/ui/compile_fail/attr_getter.rs:21:10 | -27 | #[derive(Builder)] +21 | #[derive(Builder)] | ^^^^^^^ required by this bound in `NegativeTestBuilder::::get_x3` ... -36 | x3: u32, +30 | x3: u32, | -- required by a bound in this associated function = note: this error originates in the derive macro `Builder` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/bon/tests/integration/ui/compile_fail/attr_on.rs b/bon/tests/integration/ui/compile_fail/attr_on.rs index c91c1931..0023c69e 100644 --- a/bon/tests/integration/ui/compile_fail/attr_on.rs +++ b/bon/tests/integration/ui/compile_fail/attr_on.rs @@ -3,9 +3,6 @@ use bon::builder; #[builder(on(String, into))] fn unnecessary_into(#[builder(into)] _x: String) {} -#[builder(on(String, overwritable))] -fn unnecessary_overwritable(#[builder(overwritable)] _x: String) {} - #[builder(on(&dyn std::fmt::Debug, into))] fn invalid_type_pattern() {} diff --git a/bon/tests/integration/ui/compile_fail/attr_on.stderr b/bon/tests/integration/ui/compile_fail/attr_on.stderr index dc8e7530..b681cbf9 100644 --- a/bon/tests/integration/ui/compile_fail/attr_on.stderr +++ b/bon/tests/integration/ui/compile_fail/attr_on.stderr @@ -4,76 +4,70 @@ error: this `#[builder(into)]` attribute is redundant, because `into` is already 4 | fn unnecessary_into(#[builder(into)] _x: String) {} | ^^^^ -error: this `#[builder(overwritable)]` attribute is redundant, because `overwritable` is already implied for this member via the `#[builder(on(...))]` at the top of the function - --> tests/integration/ui/compile_fail/attr_on.rs:7:39 - | -7 | fn unnecessary_overwritable(#[builder(overwritable)] _x: String) {} - | ^^^^^^^^^^^^ - error: this syntax is not supported in type patterns yet. If you have a use case for this, please open an issue at https://github.com/elastio/bon/issues. - --> tests/integration/ui/compile_fail/attr_on.rs:9:15 + --> tests/integration/ui/compile_fail/attr_on.rs:6:15 | -9 | #[builder(on(&dyn std::fmt::Debug, into))] +6 | #[builder(on(&dyn std::fmt::Debug, into))] | ^^^ error: nested attributes are not allowed in the type pattern of #[builder(on(type_pattern, ...))] - --> tests/integration/ui/compile_fail/attr_on.rs:12:17 - | -12 | #[builder(on(fn(#[attr] a: u32), into))] - | ^ + --> tests/integration/ui/compile_fail/attr_on.rs:9:17 + | +9 | #[builder(on(fn(#[attr] a: u32), into))] + | ^ error: this empty `on` attribute is unexpected; remove it or pass parameters in parentheses: `on(...)` - --> tests/integration/ui/compile_fail/attr_on.rs:15:11 + --> tests/integration/ui/compile_fail/attr_on.rs:12:11 | -15 | #[builder(on)] +12 | #[builder(on)] | ^^ error: expected parameters in parentheses - --> tests/integration/ui/compile_fail/attr_on.rs:18:13 + --> tests/integration/ui/compile_fail/attr_on.rs:15:13 | -18 | #[builder(on())] +15 | #[builder(on())] | ^^ error: expected `,` - --> tests/integration/ui/compile_fail/attr_on.rs:21:1 + --> tests/integration/ui/compile_fail/attr_on.rs:18:1 | -21 | #[builder(on(_))] +18 | #[builder(on(_))] | ^^^^^^^^^^^^^^^^^ | = note: this error originates in the attribute macro `builder` (in Nightly builds, run with -Z macro-backtrace for more info) error: expected at least one parameter after the comma in `on(type_pattern, ...)` - --> tests/integration/ui/compile_fail/attr_on.rs:24:15 + --> tests/integration/ui/compile_fail/attr_on.rs:21:15 | -24 | #[builder(on(_,))] +21 | #[builder(on(_,))] | ^ error: this `on(...)` clause is out of order; all `on(...)` clauses must be consecutive; there shouldn't be any other parameters between them - --> tests/integration/ui/compile_fail/attr_on.rs:30:5 + --> tests/integration/ui/compile_fail/attr_on.rs:27:5 | -30 | on(String, into), +27 | on(String, into), | ^^ error: this `on(...)` clause is out of order; all `on(...)` clauses must be consecutive; there shouldn't be any other parameters between them - --> tests/integration/ui/compile_fail/attr_on.rs:38:5 + --> tests/integration/ui/compile_fail/attr_on.rs:35:5 | -38 | on(String, into), +35 | on(String, into), | ^^ error: this `on(...)` clause is out of order; all `on(...)` clauses must be consecutive; there shouldn't be any other parameters between them - --> tests/integration/ui/compile_fail/attr_on.rs:46:5 + --> tests/integration/ui/compile_fail/attr_on.rs:43:5 | -46 | on(String, into), +43 | on(String, into), | ^^ error: `required` can only be specified in the first `on(...)` clause; this restriction may be lifted in the future - --> tests/integration/ui/compile_fail/attr_on.rs:51:30 + --> tests/integration/ui/compile_fail/attr_on.rs:48:30 | -51 | #[builder(on(_, into), on(_, required))] +48 | #[builder(on(_, into), on(_, required))] | ^^^^^^^^ error: `required` can only be used with the wildcard type pattern i.e. `on(_, required)`; this restriction may be lifted in the future - --> tests/integration/ui/compile_fail/attr_on.rs:54:14 + --> tests/integration/ui/compile_fail/attr_on.rs:51:14 | -54 | #[builder(on(u8, required))] +51 | #[builder(on(u8, required))] | ^^ diff --git a/bon/tests/integration/ui/compile_fail/overwritable/attr_getter.rs b/bon/tests/integration/ui/compile_fail/overwritable/attr_getter.rs new file mode 100644 index 00000000..2cf2e65e --- /dev/null +++ b/bon/tests/integration/ui/compile_fail/overwritable/attr_getter.rs @@ -0,0 +1,9 @@ +use bon::Builder; + +#[derive(Builder)] +struct OverwritableCompat { + #[builder(getter, overwritable)] + x: u32, +} + +fn main() {} diff --git a/bon/tests/integration/ui/compile_fail/overwritable/attr_getter.stderr b/bon/tests/integration/ui/compile_fail/overwritable/attr_getter.stderr new file mode 100644 index 00000000..63722fa0 --- /dev/null +++ b/bon/tests/integration/ui/compile_fail/overwritable/attr_getter.stderr @@ -0,0 +1,5 @@ +error: `getter` attribute can't be specified together with `overwritable` + --> tests/integration/ui/compile_fail/overwritable/attr_getter.rs:5:15 + | +5 | #[builder(getter, overwritable)] + | ^^^^^^ diff --git a/bon/tests/integration/ui/compile_fail/overwritable/attr_on.rs b/bon/tests/integration/ui/compile_fail/overwritable/attr_on.rs new file mode 100644 index 00000000..84e9d9cc --- /dev/null +++ b/bon/tests/integration/ui/compile_fail/overwritable/attr_on.rs @@ -0,0 +1,6 @@ +use bon::builder; + +#[builder(on(String, overwritable))] +fn unnecessary_overwritable(#[builder(overwritable)] _x: String) {} + +fn main() {} diff --git a/bon/tests/integration/ui/compile_fail/overwritable/attr_on.stderr b/bon/tests/integration/ui/compile_fail/overwritable/attr_on.stderr new file mode 100644 index 00000000..aeed163c --- /dev/null +++ b/bon/tests/integration/ui/compile_fail/overwritable/attr_on.stderr @@ -0,0 +1,5 @@ +error: this `#[builder(overwritable)]` attribute is redundant, because `overwritable` is already implied for this member via the `#[builder(on(...))]` at the top of the function + --> tests/integration/ui/compile_fail/overwritable/attr_on.rs:4:39 + | +4 | fn unnecessary_overwritable(#[builder(overwritable)] _x: String) {} + | ^^^^^^^^^^^^ diff --git a/bon/tests/integration/ui/mod.rs b/bon/tests/integration/ui/mod.rs index 9ecee3fc..2ae7515a 100644 --- a/bon/tests/integration/ui/mod.rs +++ b/bon/tests/integration/ui/mod.rs @@ -8,4 +8,8 @@ fn ui() { let t = trybuild::TestCases::new(); t.compile_fail("tests/integration/ui/compile_fail/std_or_alloc/*.rs"); } + + if cfg!(feature = "experimental-overwritable") { + t.compile_fail("tests/integration/ui/compile_fail/overwritable/*.rs"); + } }