-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework visibility conflicts to avoid losing diagnostics
This defers conflict checking until the end so that every level can participate, and errors are consistently generated.
- Loading branch information
Showing
4 changed files
with
123 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#[macro_use] | ||
extern crate derive_builder; | ||
|
||
#[derive(Builder)] | ||
#[builder(public, vis = "pub(crate)")] | ||
pub struct Example { | ||
#[builder(public, private)] | ||
field: String, | ||
} | ||
|
||
#[derive(Builder)] | ||
#[builder(public, vis = "pub(crate)", build_fn(private, public))] | ||
pub struct SecondExample { | ||
#[builder(private, vis = "pub")] | ||
a_field: String, | ||
} | ||
|
||
fn main() { | ||
ExampleBuilder::default().build(); | ||
SecondExampleBuilder::default().build(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
error: `public` and `private` cannot be used together | ||
--> tests/compile-fail/vis_conflict.rs:7:15 | ||
| | ||
7 | #[builder(public, private)] | ||
| ^^^^^^ | ||
|
||
error: `vis="..."` cannot be used with `public` or `private` | ||
--> tests/compile-fail/vis_conflict.rs:5:25 | ||
| | ||
5 | #[builder(public, vis = "pub(crate)")] | ||
| ^^^^^^^^^^^^ | ||
|
||
error: `public` and `private` cannot be used together | ||
--> tests/compile-fail/vis_conflict.rs:12:57 | ||
| | ||
12 | #[builder(public, vis = "pub(crate)", build_fn(private, public))] | ||
| ^^^^^^ | ||
|
||
error: `vis="..."` cannot be used with `public` or `private` | ||
--> tests/compile-fail/vis_conflict.rs:14:30 | ||
| | ||
14 | #[builder(private, vis = "pub")] | ||
| ^^^^^ | ||
|
||
error: `vis="..."` cannot be used with `public` or `private` | ||
--> tests/compile-fail/vis_conflict.rs:12:25 | ||
| | ||
12 | #[builder(public, vis = "pub(crate)", build_fn(private, public))] | ||
| ^^^^^^^^^^^^ | ||
|
||
error[E0433]: failed to resolve: use of undeclared type `ExampleBuilder` | ||
--> tests/compile-fail/vis_conflict.rs:19:5 | ||
| | ||
19 | ExampleBuilder::default().build(); | ||
| ^^^^^^^^^^^^^^ use of undeclared type `ExampleBuilder` | ||
|
||
error[E0433]: failed to resolve: use of undeclared type `SecondExampleBuilder` | ||
--> tests/compile-fail/vis_conflict.rs:20:5 | ||
| | ||
20 | SecondExampleBuilder::default().build(); | ||
| ^^^^^^^^^^^^^^^^^^^^ use of undeclared type `SecondExampleBuilder` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters