Skip to content

Commit

Permalink
version specific failures
Browse files Browse the repository at this point in the history
  • Loading branch information
andy128k committed Aug 19, 2020
1 parent 66aeee4 commit 3e407b3
Show file tree
Hide file tree
Showing 44 changed files with 625 additions and 1 deletion.
1 change: 1 addition & 0 deletions derive_builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ env_logger = { version = "0.5", optional = true }
[dev-dependencies]
pretty_assertions = "0.6"
trybuild = "1"
rustversion = "1"
Original file line number Diff line number Diff line change
@@ -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`
30 changes: 30 additions & 0 deletions derive_builder/tests/compile-fail/since-1.40.0/private_build_fn.rs
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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();
| ^^^^^
23 changes: 23 additions & 0 deletions derive_builder/tests/compile-fail/since-1.40.0/private_builder.rs
Original file line number Diff line number Diff line change
@@ -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());
}
Original file line number Diff line number Diff line change
@@ -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()
| ^^^^^
26 changes: 26 additions & 0 deletions derive_builder/tests/compile-fail/since-1.40.0/private_fields.rs
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
| ^^^^^^^^^^^
Original file line number Diff line number Diff line change
@@ -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",
});
}
30 changes: 30 additions & 0 deletions derive_builder/tests/compile-fail/since-1.42.0/private_build_fn.rs
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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();
| ^^^^^
23 changes: 23 additions & 0 deletions derive_builder/tests/compile-fail/since-1.42.0/private_builder.rs
Original file line number Diff line number Diff line change
@@ -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());
}
Original file line number Diff line number Diff line change
@@ -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()
| ^^^^^
26 changes: 26 additions & 0 deletions derive_builder/tests/compile-fail/since-1.42.0/private_fields.rs
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
| ^^^^^^^^^^^
Original file line number Diff line number Diff line change
@@ -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",
});
}
Original file line number Diff line number Diff line change
@@ -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`
30 changes: 30 additions & 0 deletions derive_builder/tests/compile-fail/since-1.43.0/private_build_fn.rs
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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();
| ^^^^^
23 changes: 23 additions & 0 deletions derive_builder/tests/compile-fail/since-1.43.0/private_builder.rs
Original file line number Diff line number Diff line change
@@ -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());
}
Loading

0 comments on commit 3e407b3

Please sign in to comment.