forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#135700 - estebank:priv-field-dfv, r=wesleyw…
…iser Emit single privacy error for struct literal with multiple private fields and add test for `default_field_values` privacy Add test ensuring that struct with default field values is not constructable if the fields are not accessible. Collect all unreachable fields in a single struct literal struct and emit a single error, instead of one error per private field. ``` error[E0451]: fields `beta` and `gamma` of struct `Alpha` are private --> $DIR/visibility.rs:18:13 | LL | let _x = Alpha { | ----- in this type LL | beta: 0, | ^^^^^^^ private field LL | .. | ^^ field `gamma` is private ```
- Loading branch information
Showing
13 changed files
with
261 additions
and
48 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
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
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
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
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
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,42 @@ | ||
#![feature(default_field_values)] | ||
pub mod foo { | ||
#[derive(Default)] | ||
pub struct Alpha { | ||
beta: u8 = 42, | ||
gamma: bool = true, | ||
} | ||
} | ||
|
||
mod bar { | ||
use crate::foo::Alpha; | ||
fn baz() { | ||
let _x = Alpha { .. }; | ||
//~^ ERROR fields `beta` and `gamma` of struct `Alpha` are private | ||
let _x = Alpha { | ||
beta: 0, //~ ERROR fields `beta` and `gamma` of struct `Alpha` are private | ||
gamma: false, | ||
}; | ||
let _x = Alpha { | ||
beta: 0, //~ ERROR fields `beta` and `gamma` of struct `Alpha` are private | ||
.. | ||
}; | ||
let _x = Alpha { beta: 0, .. }; | ||
//~^ ERROR fields `beta` and `gamma` of struct `Alpha` are private | ||
let _x = Alpha { beta: 0, ..Default::default() }; | ||
//~^ ERROR fields `beta` and `gamma` of struct `Alpha` are private | ||
} | ||
} | ||
|
||
pub mod baz { | ||
pub struct S { | ||
x: i32 = 1, | ||
} | ||
} | ||
fn main() { | ||
let _a = baz::S { | ||
.. //~ ERROR field `x` of struct `S` is private | ||
}; | ||
let _b = baz::S { | ||
x: 0, //~ ERROR field `x` of struct `S` is private | ||
}; | ||
} |
Oops, something went wrong.