From 3e407b3829edd85cde3338f63c223fd0868fce47 Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Wed, 19 Aug 2020 12:13:09 +0200 Subject: [PATCH] version specific failures --- derive_builder/Cargo.toml | 1 + .../{ => common}/deny_empty_default.rs | 0 .../{ => common}/deny_empty_default.stderr | 0 .../{ => nightly}/private_build_fn.rs | 0 .../{ => nightly}/private_build_fn.stderr | 0 .../{ => nightly}/private_builder.rs | 0 .../{ => nightly}/private_builder.stderr | 0 .../{ => nightly}/private_fields.rs | 0 .../{ => nightly}/private_fields.stderr | 0 .../rename_setter_struct_level.rs | 0 .../nightly/rename_setter_struct_level.stderr | 11 +++++++ .../since-1.40.0/private_build_fn.rs | 30 +++++++++++++++++++ .../since-1.40.0/private_build_fn.stderr | 13 ++++++++ .../since-1.40.0/private_builder.rs | 23 ++++++++++++++ .../since-1.40.0/private_builder.stderr | 11 +++++++ .../since-1.40.0/private_fields.rs | 26 ++++++++++++++++ .../since-1.40.0/private_fields.stderr | 5 ++++ .../rename_setter_struct_level.rs | 25 ++++++++++++++++ .../rename_setter_struct_level.stderr | 0 .../since-1.42.0/private_build_fn.rs | 30 +++++++++++++++++++ .../since-1.42.0/private_build_fn.stderr | 13 ++++++++ .../since-1.42.0/private_builder.rs | 23 ++++++++++++++ .../since-1.42.0/private_builder.stderr | 17 +++++++++++ .../since-1.42.0/private_fields.rs | 26 ++++++++++++++++ .../since-1.42.0/private_fields.stderr | 5 ++++ .../rename_setter_struct_level.rs | 25 ++++++++++++++++ .../rename_setter_struct_level.stderr | 11 +++++++ .../since-1.43.0/private_build_fn.rs | 30 +++++++++++++++++++ .../since-1.43.0/private_build_fn.stderr | 13 ++++++++ .../since-1.43.0/private_builder.rs | 23 ++++++++++++++ .../since-1.43.0/private_builder.stderr | 18 +++++++++++ .../since-1.43.0/private_fields.rs | 26 ++++++++++++++++ .../since-1.43.0/private_fields.stderr | 5 ++++ .../rename_setter_struct_level.rs | 25 ++++++++++++++++ .../rename_setter_struct_level.stderr | 11 +++++++ .../since-1.44.0/private_build_fn.rs | 30 +++++++++++++++++++ .../since-1.44.0/private_build_fn.stderr | 13 ++++++++ .../since-1.44.0/private_builder.rs | 23 ++++++++++++++ .../since-1.44.0/private_builder.stderr | 18 +++++++++++ .../since-1.44.0/private_fields.rs | 26 ++++++++++++++++ .../since-1.44.0/private_fields.stderr | 5 ++++ .../rename_setter_struct_level.rs | 25 ++++++++++++++++ .../rename_setter_struct_level.stderr | 11 +++++++ derive_builder/tests/compiletests.rs | 29 +++++++++++++++++- 44 files changed, 625 insertions(+), 1 deletion(-) rename derive_builder/tests/compile-fail/{ => common}/deny_empty_default.rs (100%) rename derive_builder/tests/compile-fail/{ => common}/deny_empty_default.stderr (100%) rename derive_builder/tests/compile-fail/{ => nightly}/private_build_fn.rs (100%) rename derive_builder/tests/compile-fail/{ => nightly}/private_build_fn.stderr (100%) rename derive_builder/tests/compile-fail/{ => nightly}/private_builder.rs (100%) rename derive_builder/tests/compile-fail/{ => nightly}/private_builder.stderr (100%) rename derive_builder/tests/compile-fail/{ => nightly}/private_fields.rs (100%) rename derive_builder/tests/compile-fail/{ => nightly}/private_fields.stderr (100%) rename derive_builder/tests/compile-fail/{ => nightly}/rename_setter_struct_level.rs (100%) create mode 100644 derive_builder/tests/compile-fail/nightly/rename_setter_struct_level.stderr create mode 100644 derive_builder/tests/compile-fail/since-1.40.0/private_build_fn.rs create mode 100644 derive_builder/tests/compile-fail/since-1.40.0/private_build_fn.stderr create mode 100644 derive_builder/tests/compile-fail/since-1.40.0/private_builder.rs create mode 100644 derive_builder/tests/compile-fail/since-1.40.0/private_builder.stderr create mode 100644 derive_builder/tests/compile-fail/since-1.40.0/private_fields.rs create mode 100644 derive_builder/tests/compile-fail/since-1.40.0/private_fields.stderr create mode 100644 derive_builder/tests/compile-fail/since-1.40.0/rename_setter_struct_level.rs rename derive_builder/tests/compile-fail/{ => since-1.40.0}/rename_setter_struct_level.stderr (100%) create mode 100644 derive_builder/tests/compile-fail/since-1.42.0/private_build_fn.rs create mode 100644 derive_builder/tests/compile-fail/since-1.42.0/private_build_fn.stderr create mode 100644 derive_builder/tests/compile-fail/since-1.42.0/private_builder.rs create mode 100644 derive_builder/tests/compile-fail/since-1.42.0/private_builder.stderr create mode 100644 derive_builder/tests/compile-fail/since-1.42.0/private_fields.rs create mode 100644 derive_builder/tests/compile-fail/since-1.42.0/private_fields.stderr create mode 100644 derive_builder/tests/compile-fail/since-1.42.0/rename_setter_struct_level.rs create mode 100644 derive_builder/tests/compile-fail/since-1.42.0/rename_setter_struct_level.stderr create mode 100644 derive_builder/tests/compile-fail/since-1.43.0/private_build_fn.rs create mode 100644 derive_builder/tests/compile-fail/since-1.43.0/private_build_fn.stderr create mode 100644 derive_builder/tests/compile-fail/since-1.43.0/private_builder.rs create mode 100644 derive_builder/tests/compile-fail/since-1.43.0/private_builder.stderr create mode 100644 derive_builder/tests/compile-fail/since-1.43.0/private_fields.rs create mode 100644 derive_builder/tests/compile-fail/since-1.43.0/private_fields.stderr create mode 100644 derive_builder/tests/compile-fail/since-1.43.0/rename_setter_struct_level.rs create mode 100644 derive_builder/tests/compile-fail/since-1.43.0/rename_setter_struct_level.stderr create mode 100644 derive_builder/tests/compile-fail/since-1.44.0/private_build_fn.rs create mode 100644 derive_builder/tests/compile-fail/since-1.44.0/private_build_fn.stderr create mode 100644 derive_builder/tests/compile-fail/since-1.44.0/private_builder.rs create mode 100644 derive_builder/tests/compile-fail/since-1.44.0/private_builder.stderr create mode 100644 derive_builder/tests/compile-fail/since-1.44.0/private_fields.rs create mode 100644 derive_builder/tests/compile-fail/since-1.44.0/private_fields.stderr create mode 100644 derive_builder/tests/compile-fail/since-1.44.0/rename_setter_struct_level.rs create mode 100644 derive_builder/tests/compile-fail/since-1.44.0/rename_setter_struct_level.stderr diff --git a/derive_builder/Cargo.toml b/derive_builder/Cargo.toml index 34308c4b..d3d4fd9b 100644 --- a/derive_builder/Cargo.toml +++ b/derive_builder/Cargo.toml @@ -48,3 +48,4 @@ env_logger = { version = "0.5", optional = true } [dev-dependencies] pretty_assertions = "0.6" trybuild = "1" +rustversion = "1" diff --git a/derive_builder/tests/compile-fail/deny_empty_default.rs b/derive_builder/tests/compile-fail/common/deny_empty_default.rs similarity index 100% rename from derive_builder/tests/compile-fail/deny_empty_default.rs rename to derive_builder/tests/compile-fail/common/deny_empty_default.rs diff --git a/derive_builder/tests/compile-fail/deny_empty_default.stderr b/derive_builder/tests/compile-fail/common/deny_empty_default.stderr similarity index 100% rename from derive_builder/tests/compile-fail/deny_empty_default.stderr rename to derive_builder/tests/compile-fail/common/deny_empty_default.stderr diff --git a/derive_builder/tests/compile-fail/private_build_fn.rs b/derive_builder/tests/compile-fail/nightly/private_build_fn.rs similarity index 100% rename from derive_builder/tests/compile-fail/private_build_fn.rs rename to derive_builder/tests/compile-fail/nightly/private_build_fn.rs diff --git a/derive_builder/tests/compile-fail/private_build_fn.stderr b/derive_builder/tests/compile-fail/nightly/private_build_fn.stderr similarity index 100% rename from derive_builder/tests/compile-fail/private_build_fn.stderr rename to derive_builder/tests/compile-fail/nightly/private_build_fn.stderr diff --git a/derive_builder/tests/compile-fail/private_builder.rs b/derive_builder/tests/compile-fail/nightly/private_builder.rs similarity index 100% rename from derive_builder/tests/compile-fail/private_builder.rs rename to derive_builder/tests/compile-fail/nightly/private_builder.rs diff --git a/derive_builder/tests/compile-fail/private_builder.stderr b/derive_builder/tests/compile-fail/nightly/private_builder.stderr similarity index 100% rename from derive_builder/tests/compile-fail/private_builder.stderr rename to derive_builder/tests/compile-fail/nightly/private_builder.stderr diff --git a/derive_builder/tests/compile-fail/private_fields.rs b/derive_builder/tests/compile-fail/nightly/private_fields.rs similarity index 100% rename from derive_builder/tests/compile-fail/private_fields.rs rename to derive_builder/tests/compile-fail/nightly/private_fields.rs diff --git a/derive_builder/tests/compile-fail/private_fields.stderr b/derive_builder/tests/compile-fail/nightly/private_fields.stderr similarity index 100% rename from derive_builder/tests/compile-fail/private_fields.stderr rename to derive_builder/tests/compile-fail/nightly/private_fields.stderr diff --git a/derive_builder/tests/compile-fail/rename_setter_struct_level.rs b/derive_builder/tests/compile-fail/nightly/rename_setter_struct_level.rs similarity index 100% rename from derive_builder/tests/compile-fail/rename_setter_struct_level.rs rename to derive_builder/tests/compile-fail/nightly/rename_setter_struct_level.rs diff --git a/derive_builder/tests/compile-fail/nightly/rename_setter_struct_level.stderr b/derive_builder/tests/compile-fail/nightly/rename_setter_struct_level.stderr new file mode 100644 index 00000000..7b36f402 --- /dev/null +++ b/derive_builder/tests/compile-fail/nightly/rename_setter_struct_level.stderr @@ -0,0 +1,11 @@ +error: Unknown field: `name` + --> $DIR/rename_setter_struct_level.rs:7:18 + | +7 | #[builder(setter(name = "foo"))] + | ^^^^^^^^^^^^ + +error[E0433]: failed to resolve: use of undeclared type or module `LoremBuilder` + --> $DIR/rename_setter_struct_level.rs:14:13 + | +14 | let x = LoremBuilder::default() + | ^^^^^^^^^^^^ use of undeclared type or module `LoremBuilder` diff --git a/derive_builder/tests/compile-fail/since-1.40.0/private_build_fn.rs b/derive_builder/tests/compile-fail/since-1.40.0/private_build_fn.rs new file mode 100644 index 00000000..4ee0222d --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.40.0/private_build_fn.rs @@ -0,0 +1,30 @@ +#[macro_use] +extern crate derive_builder; + +mod container { + /// `LoremBuilder` should be accessible outside the module, but its + /// build method should not be. + #[derive(Debug, Default, Builder)] + #[builder(default, public, build_fn(private))] + pub struct Lorem { + foo: usize, + bar: String, + } + + impl LoremBuilder { + /// Create a `Lorem` + pub fn my_build(&self) -> Lorem { + self.build().expect("All good") + } + } +} + +fn main() { + use container::{Lorem, LoremBuilder}; + + let lorem1 = LoremBuilder::default().my_build(); + + let lorem2 = LoremBuilder::default().build().unwrap(); + + println!("{:?} vs {:?}", lorem1, lorem2); +} diff --git a/derive_builder/tests/compile-fail/since-1.40.0/private_build_fn.stderr b/derive_builder/tests/compile-fail/since-1.40.0/private_build_fn.stderr new file mode 100644 index 00000000..79b96813 --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.40.0/private_build_fn.stderr @@ -0,0 +1,13 @@ +warning: unused import: `Lorem` + --> $DIR/private_build_fn.rs:23:21 + | +23 | use container::{Lorem, LoremBuilder}; + | ^^^^^ + | + = note: `#[warn(unused_imports)]` on by default + +error[E0624]: method `build` is private + --> $DIR/private_build_fn.rs:27:42 + | +27 | let lorem2 = LoremBuilder::default().build().unwrap(); + | ^^^^^ diff --git a/derive_builder/tests/compile-fail/since-1.40.0/private_builder.rs b/derive_builder/tests/compile-fail/since-1.40.0/private_builder.rs new file mode 100644 index 00000000..cd13e52d --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.40.0/private_builder.rs @@ -0,0 +1,23 @@ +#[macro_use] +extern crate derive_builder; + +pub mod foo { + /// The builder struct's declaration of privacy should override the field's + /// attempt to be public later on. + #[derive(Debug, PartialEq, Default, Builder, Clone)] + #[builder(private, setter(into))] + pub struct Lorem { + pub private: String, + #[builder(public)] + pub public: String, + } +} + +fn main() { + let x = foo::LoremBuilder::default() + .public("Hello") + .build() + .unwrap(); + + assert_eq!(x.public, "Hello".to_string()); +} diff --git a/derive_builder/tests/compile-fail/since-1.40.0/private_builder.stderr b/derive_builder/tests/compile-fail/since-1.40.0/private_builder.stderr new file mode 100644 index 00000000..4375da1b --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.40.0/private_builder.stderr @@ -0,0 +1,11 @@ +error[E0603]: struct `LoremBuilder` is private + --> $DIR/private_builder.rs:17:18 + | +17 | let x = foo::LoremBuilder::default() + | ^^^^^^^^^^^^ + +error[E0624]: method `build` is private + --> $DIR/private_builder.rs:19:10 + | +19 | .build() + | ^^^^^ diff --git a/derive_builder/tests/compile-fail/since-1.40.0/private_fields.rs b/derive_builder/tests/compile-fail/since-1.40.0/private_fields.rs new file mode 100644 index 00000000..74f074df --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.40.0/private_fields.rs @@ -0,0 +1,26 @@ +#[macro_use] +extern crate derive_builder; + +/// This builder is in an inner module to make sure private fields aren't accessible +/// from the `main` function. +mod inner { + /// The `LoremBuilder` struct will have private fields for `ipsum` and `dolor`, and + /// a public `sit` field. + #[derive(Debug, Builder)] + #[builder(field(private), setter(into))] + pub struct Lorem { + ipsum: String, + dolor: u16, + #[builder(field(public))] + sit: bool, + } +} + +fn main() { + use inner::LoremBuilder; + + let mut lorem = LoremBuilder::default(); + lorem.dolor(15u16); + lorem.sit = Some(true); // <-- public + lorem.dolor = Some(0); // <-- private +} diff --git a/derive_builder/tests/compile-fail/since-1.40.0/private_fields.stderr b/derive_builder/tests/compile-fail/since-1.40.0/private_fields.stderr new file mode 100644 index 00000000..821cc2b2 --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.40.0/private_fields.stderr @@ -0,0 +1,5 @@ +error[E0616]: field `dolor` of struct `inner::LoremBuilder` is private + --> $DIR/private_fields.rs:25:5 + | +25 | lorem.dolor = Some(0); // <-- private + | ^^^^^^^^^^^ diff --git a/derive_builder/tests/compile-fail/since-1.40.0/rename_setter_struct_level.rs b/derive_builder/tests/compile-fail/since-1.40.0/rename_setter_struct_level.rs new file mode 100644 index 00000000..7565efe6 --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.40.0/rename_setter_struct_level.rs @@ -0,0 +1,25 @@ +#[macro_use] +extern crate pretty_assertions; +#[macro_use] +extern crate derive_builder; + +#[derive(Debug, PartialEq, Default, Builder, Clone)] +#[builder(setter(name = "foo"))] +struct Lorem { + ipsum: &'static str, + pub dolor: &'static str, +} + +fn main() { + let x = LoremBuilder::default() + .ipsum("ipsum") + .foo("dolor") + .build() + .unwrap(); + + assert_eq!(x, + Lorem { + ipsum: "ipsum", + dolor: "dolor", + }); +} diff --git a/derive_builder/tests/compile-fail/rename_setter_struct_level.stderr b/derive_builder/tests/compile-fail/since-1.40.0/rename_setter_struct_level.stderr similarity index 100% rename from derive_builder/tests/compile-fail/rename_setter_struct_level.stderr rename to derive_builder/tests/compile-fail/since-1.40.0/rename_setter_struct_level.stderr diff --git a/derive_builder/tests/compile-fail/since-1.42.0/private_build_fn.rs b/derive_builder/tests/compile-fail/since-1.42.0/private_build_fn.rs new file mode 100644 index 00000000..4ee0222d --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.42.0/private_build_fn.rs @@ -0,0 +1,30 @@ +#[macro_use] +extern crate derive_builder; + +mod container { + /// `LoremBuilder` should be accessible outside the module, but its + /// build method should not be. + #[derive(Debug, Default, Builder)] + #[builder(default, public, build_fn(private))] + pub struct Lorem { + foo: usize, + bar: String, + } + + impl LoremBuilder { + /// Create a `Lorem` + pub fn my_build(&self) -> Lorem { + self.build().expect("All good") + } + } +} + +fn main() { + use container::{Lorem, LoremBuilder}; + + let lorem1 = LoremBuilder::default().my_build(); + + let lorem2 = LoremBuilder::default().build().unwrap(); + + println!("{:?} vs {:?}", lorem1, lorem2); +} diff --git a/derive_builder/tests/compile-fail/since-1.42.0/private_build_fn.stderr b/derive_builder/tests/compile-fail/since-1.42.0/private_build_fn.stderr new file mode 100644 index 00000000..79b96813 --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.42.0/private_build_fn.stderr @@ -0,0 +1,13 @@ +warning: unused import: `Lorem` + --> $DIR/private_build_fn.rs:23:21 + | +23 | use container::{Lorem, LoremBuilder}; + | ^^^^^ + | + = note: `#[warn(unused_imports)]` on by default + +error[E0624]: method `build` is private + --> $DIR/private_build_fn.rs:27:42 + | +27 | let lorem2 = LoremBuilder::default().build().unwrap(); + | ^^^^^ diff --git a/derive_builder/tests/compile-fail/since-1.42.0/private_builder.rs b/derive_builder/tests/compile-fail/since-1.42.0/private_builder.rs new file mode 100644 index 00000000..cd13e52d --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.42.0/private_builder.rs @@ -0,0 +1,23 @@ +#[macro_use] +extern crate derive_builder; + +pub mod foo { + /// The builder struct's declaration of privacy should override the field's + /// attempt to be public later on. + #[derive(Debug, PartialEq, Default, Builder, Clone)] + #[builder(private, setter(into))] + pub struct Lorem { + pub private: String, + #[builder(public)] + pub public: String, + } +} + +fn main() { + let x = foo::LoremBuilder::default() + .public("Hello") + .build() + .unwrap(); + + assert_eq!(x.public, "Hello".to_string()); +} diff --git a/derive_builder/tests/compile-fail/since-1.42.0/private_builder.stderr b/derive_builder/tests/compile-fail/since-1.42.0/private_builder.stderr new file mode 100644 index 00000000..71815b31 --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.42.0/private_builder.stderr @@ -0,0 +1,17 @@ +error[E0603]: struct `LoremBuilder` is private + --> $DIR/private_builder.rs:17:18 + | +17 | let x = foo::LoremBuilder::default() + | ^^^^^^^^^^^^ this struct is private + | +note: the struct `LoremBuilder` is defined here + --> $DIR/private_builder.rs:7:41 + | +7 | #[derive(Debug, PartialEq, Default, Builder, Clone)] + | ^^^^^^^ + +error[E0624]: method `build` is private + --> $DIR/private_builder.rs:19:10 + | +19 | .build() + | ^^^^^ diff --git a/derive_builder/tests/compile-fail/since-1.42.0/private_fields.rs b/derive_builder/tests/compile-fail/since-1.42.0/private_fields.rs new file mode 100644 index 00000000..74f074df --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.42.0/private_fields.rs @@ -0,0 +1,26 @@ +#[macro_use] +extern crate derive_builder; + +/// This builder is in an inner module to make sure private fields aren't accessible +/// from the `main` function. +mod inner { + /// The `LoremBuilder` struct will have private fields for `ipsum` and `dolor`, and + /// a public `sit` field. + #[derive(Debug, Builder)] + #[builder(field(private), setter(into))] + pub struct Lorem { + ipsum: String, + dolor: u16, + #[builder(field(public))] + sit: bool, + } +} + +fn main() { + use inner::LoremBuilder; + + let mut lorem = LoremBuilder::default(); + lorem.dolor(15u16); + lorem.sit = Some(true); // <-- public + lorem.dolor = Some(0); // <-- private +} diff --git a/derive_builder/tests/compile-fail/since-1.42.0/private_fields.stderr b/derive_builder/tests/compile-fail/since-1.42.0/private_fields.stderr new file mode 100644 index 00000000..821cc2b2 --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.42.0/private_fields.stderr @@ -0,0 +1,5 @@ +error[E0616]: field `dolor` of struct `inner::LoremBuilder` is private + --> $DIR/private_fields.rs:25:5 + | +25 | lorem.dolor = Some(0); // <-- private + | ^^^^^^^^^^^ diff --git a/derive_builder/tests/compile-fail/since-1.42.0/rename_setter_struct_level.rs b/derive_builder/tests/compile-fail/since-1.42.0/rename_setter_struct_level.rs new file mode 100644 index 00000000..7565efe6 --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.42.0/rename_setter_struct_level.rs @@ -0,0 +1,25 @@ +#[macro_use] +extern crate pretty_assertions; +#[macro_use] +extern crate derive_builder; + +#[derive(Debug, PartialEq, Default, Builder, Clone)] +#[builder(setter(name = "foo"))] +struct Lorem { + ipsum: &'static str, + pub dolor: &'static str, +} + +fn main() { + let x = LoremBuilder::default() + .ipsum("ipsum") + .foo("dolor") + .build() + .unwrap(); + + assert_eq!(x, + Lorem { + ipsum: "ipsum", + dolor: "dolor", + }); +} diff --git a/derive_builder/tests/compile-fail/since-1.42.0/rename_setter_struct_level.stderr b/derive_builder/tests/compile-fail/since-1.42.0/rename_setter_struct_level.stderr new file mode 100644 index 00000000..54d4c85c --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.42.0/rename_setter_struct_level.stderr @@ -0,0 +1,11 @@ +error: Unknown field: `name` + --> $DIR/rename_setter_struct_level.rs:7:18 + | +7 | #[builder(setter(name = "foo"))] + | ^^^^ + +error[E0433]: failed to resolve: use of undeclared type or module `LoremBuilder` + --> $DIR/rename_setter_struct_level.rs:14:13 + | +14 | let x = LoremBuilder::default() + | ^^^^^^^^^^^^ use of undeclared type or module `LoremBuilder` diff --git a/derive_builder/tests/compile-fail/since-1.43.0/private_build_fn.rs b/derive_builder/tests/compile-fail/since-1.43.0/private_build_fn.rs new file mode 100644 index 00000000..4ee0222d --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.43.0/private_build_fn.rs @@ -0,0 +1,30 @@ +#[macro_use] +extern crate derive_builder; + +mod container { + /// `LoremBuilder` should be accessible outside the module, but its + /// build method should not be. + #[derive(Debug, Default, Builder)] + #[builder(default, public, build_fn(private))] + pub struct Lorem { + foo: usize, + bar: String, + } + + impl LoremBuilder { + /// Create a `Lorem` + pub fn my_build(&self) -> Lorem { + self.build().expect("All good") + } + } +} + +fn main() { + use container::{Lorem, LoremBuilder}; + + let lorem1 = LoremBuilder::default().my_build(); + + let lorem2 = LoremBuilder::default().build().unwrap(); + + println!("{:?} vs {:?}", lorem1, lorem2); +} diff --git a/derive_builder/tests/compile-fail/since-1.43.0/private_build_fn.stderr b/derive_builder/tests/compile-fail/since-1.43.0/private_build_fn.stderr new file mode 100644 index 00000000..79b96813 --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.43.0/private_build_fn.stderr @@ -0,0 +1,13 @@ +warning: unused import: `Lorem` + --> $DIR/private_build_fn.rs:23:21 + | +23 | use container::{Lorem, LoremBuilder}; + | ^^^^^ + | + = note: `#[warn(unused_imports)]` on by default + +error[E0624]: method `build` is private + --> $DIR/private_build_fn.rs:27:42 + | +27 | let lorem2 = LoremBuilder::default().build().unwrap(); + | ^^^^^ diff --git a/derive_builder/tests/compile-fail/since-1.43.0/private_builder.rs b/derive_builder/tests/compile-fail/since-1.43.0/private_builder.rs new file mode 100644 index 00000000..cd13e52d --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.43.0/private_builder.rs @@ -0,0 +1,23 @@ +#[macro_use] +extern crate derive_builder; + +pub mod foo { + /// The builder struct's declaration of privacy should override the field's + /// attempt to be public later on. + #[derive(Debug, PartialEq, Default, Builder, Clone)] + #[builder(private, setter(into))] + pub struct Lorem { + pub private: String, + #[builder(public)] + pub public: String, + } +} + +fn main() { + let x = foo::LoremBuilder::default() + .public("Hello") + .build() + .unwrap(); + + assert_eq!(x.public, "Hello".to_string()); +} diff --git a/derive_builder/tests/compile-fail/since-1.43.0/private_builder.stderr b/derive_builder/tests/compile-fail/since-1.43.0/private_builder.stderr new file mode 100644 index 00000000..6fd9b418 --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.43.0/private_builder.stderr @@ -0,0 +1,18 @@ +error[E0603]: struct `LoremBuilder` is private + --> $DIR/private_builder.rs:17:18 + | +17 | let x = foo::LoremBuilder::default() + | ^^^^^^^^^^^^ this struct is private + | +note: the struct `LoremBuilder` is defined here + --> $DIR/private_builder.rs:7:41 + | +7 | #[derive(Debug, PartialEq, Default, Builder, Clone)] + | ^^^^^^^ + = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0624]: method `build` is private + --> $DIR/private_builder.rs:19:10 + | +19 | .build() + | ^^^^^ diff --git a/derive_builder/tests/compile-fail/since-1.43.0/private_fields.rs b/derive_builder/tests/compile-fail/since-1.43.0/private_fields.rs new file mode 100644 index 00000000..74f074df --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.43.0/private_fields.rs @@ -0,0 +1,26 @@ +#[macro_use] +extern crate derive_builder; + +/// This builder is in an inner module to make sure private fields aren't accessible +/// from the `main` function. +mod inner { + /// The `LoremBuilder` struct will have private fields for `ipsum` and `dolor`, and + /// a public `sit` field. + #[derive(Debug, Builder)] + #[builder(field(private), setter(into))] + pub struct Lorem { + ipsum: String, + dolor: u16, + #[builder(field(public))] + sit: bool, + } +} + +fn main() { + use inner::LoremBuilder; + + let mut lorem = LoremBuilder::default(); + lorem.dolor(15u16); + lorem.sit = Some(true); // <-- public + lorem.dolor = Some(0); // <-- private +} diff --git a/derive_builder/tests/compile-fail/since-1.43.0/private_fields.stderr b/derive_builder/tests/compile-fail/since-1.43.0/private_fields.stderr new file mode 100644 index 00000000..821cc2b2 --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.43.0/private_fields.stderr @@ -0,0 +1,5 @@ +error[E0616]: field `dolor` of struct `inner::LoremBuilder` is private + --> $DIR/private_fields.rs:25:5 + | +25 | lorem.dolor = Some(0); // <-- private + | ^^^^^^^^^^^ diff --git a/derive_builder/tests/compile-fail/since-1.43.0/rename_setter_struct_level.rs b/derive_builder/tests/compile-fail/since-1.43.0/rename_setter_struct_level.rs new file mode 100644 index 00000000..7565efe6 --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.43.0/rename_setter_struct_level.rs @@ -0,0 +1,25 @@ +#[macro_use] +extern crate pretty_assertions; +#[macro_use] +extern crate derive_builder; + +#[derive(Debug, PartialEq, Default, Builder, Clone)] +#[builder(setter(name = "foo"))] +struct Lorem { + ipsum: &'static str, + pub dolor: &'static str, +} + +fn main() { + let x = LoremBuilder::default() + .ipsum("ipsum") + .foo("dolor") + .build() + .unwrap(); + + assert_eq!(x, + Lorem { + ipsum: "ipsum", + dolor: "dolor", + }); +} diff --git a/derive_builder/tests/compile-fail/since-1.43.0/rename_setter_struct_level.stderr b/derive_builder/tests/compile-fail/since-1.43.0/rename_setter_struct_level.stderr new file mode 100644 index 00000000..54d4c85c --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.43.0/rename_setter_struct_level.stderr @@ -0,0 +1,11 @@ +error: Unknown field: `name` + --> $DIR/rename_setter_struct_level.rs:7:18 + | +7 | #[builder(setter(name = "foo"))] + | ^^^^ + +error[E0433]: failed to resolve: use of undeclared type or module `LoremBuilder` + --> $DIR/rename_setter_struct_level.rs:14:13 + | +14 | let x = LoremBuilder::default() + | ^^^^^^^^^^^^ use of undeclared type or module `LoremBuilder` diff --git a/derive_builder/tests/compile-fail/since-1.44.0/private_build_fn.rs b/derive_builder/tests/compile-fail/since-1.44.0/private_build_fn.rs new file mode 100644 index 00000000..4ee0222d --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.44.0/private_build_fn.rs @@ -0,0 +1,30 @@ +#[macro_use] +extern crate derive_builder; + +mod container { + /// `LoremBuilder` should be accessible outside the module, but its + /// build method should not be. + #[derive(Debug, Default, Builder)] + #[builder(default, public, build_fn(private))] + pub struct Lorem { + foo: usize, + bar: String, + } + + impl LoremBuilder { + /// Create a `Lorem` + pub fn my_build(&self) -> Lorem { + self.build().expect("All good") + } + } +} + +fn main() { + use container::{Lorem, LoremBuilder}; + + let lorem1 = LoremBuilder::default().my_build(); + + let lorem2 = LoremBuilder::default().build().unwrap(); + + println!("{:?} vs {:?}", lorem1, lorem2); +} diff --git a/derive_builder/tests/compile-fail/since-1.44.0/private_build_fn.stderr b/derive_builder/tests/compile-fail/since-1.44.0/private_build_fn.stderr new file mode 100644 index 00000000..e6e28162 --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.44.0/private_build_fn.stderr @@ -0,0 +1,13 @@ +warning: unused import: `Lorem` + --> $DIR/private_build_fn.rs:23:21 + | +23 | use container::{Lorem, LoremBuilder}; + | ^^^^^ + | + = note: `#[warn(unused_imports)]` on by default + +error[E0624]: associated function `build` is private + --> $DIR/private_build_fn.rs:27:42 + | +27 | let lorem2 = LoremBuilder::default().build().unwrap(); + | ^^^^^ private associated function diff --git a/derive_builder/tests/compile-fail/since-1.44.0/private_builder.rs b/derive_builder/tests/compile-fail/since-1.44.0/private_builder.rs new file mode 100644 index 00000000..cd13e52d --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.44.0/private_builder.rs @@ -0,0 +1,23 @@ +#[macro_use] +extern crate derive_builder; + +pub mod foo { + /// The builder struct's declaration of privacy should override the field's + /// attempt to be public later on. + #[derive(Debug, PartialEq, Default, Builder, Clone)] + #[builder(private, setter(into))] + pub struct Lorem { + pub private: String, + #[builder(public)] + pub public: String, + } +} + +fn main() { + let x = foo::LoremBuilder::default() + .public("Hello") + .build() + .unwrap(); + + assert_eq!(x.public, "Hello".to_string()); +} diff --git a/derive_builder/tests/compile-fail/since-1.44.0/private_builder.stderr b/derive_builder/tests/compile-fail/since-1.44.0/private_builder.stderr new file mode 100644 index 00000000..caafb24a --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.44.0/private_builder.stderr @@ -0,0 +1,18 @@ +error[E0603]: struct `LoremBuilder` is private + --> $DIR/private_builder.rs:17:18 + | +17 | let x = foo::LoremBuilder::default() + | ^^^^^^^^^^^^ private struct + | +note: the struct `LoremBuilder` is defined here + --> $DIR/private_builder.rs:7:41 + | +7 | #[derive(Debug, PartialEq, Default, Builder, Clone)] + | ^^^^^^^ + = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0624]: associated function `build` is private + --> $DIR/private_builder.rs:19:10 + | +19 | .build() + | ^^^^^ private associated function diff --git a/derive_builder/tests/compile-fail/since-1.44.0/private_fields.rs b/derive_builder/tests/compile-fail/since-1.44.0/private_fields.rs new file mode 100644 index 00000000..74f074df --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.44.0/private_fields.rs @@ -0,0 +1,26 @@ +#[macro_use] +extern crate derive_builder; + +/// This builder is in an inner module to make sure private fields aren't accessible +/// from the `main` function. +mod inner { + /// The `LoremBuilder` struct will have private fields for `ipsum` and `dolor`, and + /// a public `sit` field. + #[derive(Debug, Builder)] + #[builder(field(private), setter(into))] + pub struct Lorem { + ipsum: String, + dolor: u16, + #[builder(field(public))] + sit: bool, + } +} + +fn main() { + use inner::LoremBuilder; + + let mut lorem = LoremBuilder::default(); + lorem.dolor(15u16); + lorem.sit = Some(true); // <-- public + lorem.dolor = Some(0); // <-- private +} diff --git a/derive_builder/tests/compile-fail/since-1.44.0/private_fields.stderr b/derive_builder/tests/compile-fail/since-1.44.0/private_fields.stderr new file mode 100644 index 00000000..d325f93c --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.44.0/private_fields.stderr @@ -0,0 +1,5 @@ +error[E0616]: field `dolor` of struct `inner::LoremBuilder` is private + --> $DIR/private_fields.rs:25:11 + | +25 | lorem.dolor = Some(0); // <-- private + | ^^^^^ private field diff --git a/derive_builder/tests/compile-fail/since-1.44.0/rename_setter_struct_level.rs b/derive_builder/tests/compile-fail/since-1.44.0/rename_setter_struct_level.rs new file mode 100644 index 00000000..7565efe6 --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.44.0/rename_setter_struct_level.rs @@ -0,0 +1,25 @@ +#[macro_use] +extern crate pretty_assertions; +#[macro_use] +extern crate derive_builder; + +#[derive(Debug, PartialEq, Default, Builder, Clone)] +#[builder(setter(name = "foo"))] +struct Lorem { + ipsum: &'static str, + pub dolor: &'static str, +} + +fn main() { + let x = LoremBuilder::default() + .ipsum("ipsum") + .foo("dolor") + .build() + .unwrap(); + + assert_eq!(x, + Lorem { + ipsum: "ipsum", + dolor: "dolor", + }); +} diff --git a/derive_builder/tests/compile-fail/since-1.44.0/rename_setter_struct_level.stderr b/derive_builder/tests/compile-fail/since-1.44.0/rename_setter_struct_level.stderr new file mode 100644 index 00000000..54d4c85c --- /dev/null +++ b/derive_builder/tests/compile-fail/since-1.44.0/rename_setter_struct_level.stderr @@ -0,0 +1,11 @@ +error: Unknown field: `name` + --> $DIR/rename_setter_struct_level.rs:7:18 + | +7 | #[builder(setter(name = "foo"))] + | ^^^^ + +error[E0433]: failed to resolve: use of undeclared type or module `LoremBuilder` + --> $DIR/rename_setter_struct_level.rs:14:13 + | +14 | let x = LoremBuilder::default() + | ^^^^^^^^^^^^ use of undeclared type or module `LoremBuilder` diff --git a/derive_builder/tests/compiletests.rs b/derive_builder/tests/compiletests.rs index 8d95d838..326d71e1 100644 --- a/derive_builder/tests/compiletests.rs +++ b/derive_builder/tests/compiletests.rs @@ -1,8 +1,35 @@ extern crate trybuild; +extern crate rustversion; #[test] fn compile_test() { + #[rustversion::all(since(1.40), before(1.42))] + fn version_specific_fail(t: &trybuild::TestCases) { + t.compile_fail("tests/compile-fail/since-1.40.0/*.rs"); + } + + #[rustversion::all(since(1.42), before(1.43))] + fn version_specific_fail(t: &trybuild::TestCases) { + t.compile_fail("tests/compile-fail/since-1.42.0/*.rs"); + } + + #[rustversion::all(since(1.43), before(1.44))] + fn version_specific_fail(t: &trybuild::TestCases) { + t.compile_fail("tests/compile-fail/since-1.43.0/*.rs"); + } + + #[rustversion::all(since(1.44), not(nightly))] + fn version_specific_fail(t: &trybuild::TestCases) { + t.compile_fail("tests/compile-fail/since-1.44.0/*.rs"); + } + + #[rustversion::nightly] + fn version_specific_fail(t: &trybuild::TestCases) { + t.compile_fail("tests/compile-fail/nightly/*.rs"); + } + let t = trybuild::TestCases::new(); t.pass("tests/run-pass/*.rs"); - t.compile_fail("tests/compile-fail/*.rs"); + t.compile_fail("tests/compile-fail/common/*.rs"); + version_specific_fail(&t); }