Skip to content

Commit 3e99055

Browse files
committed
Add test for construction of struct with private field with default value
``` error[E0451]: field `beta` of struct `Alpha` is private --> $DIR/visibility.rs:11:37 | LL | let x = crate::foo::Alpha { .. }; | ^^ field `beta` is private ```
1 parent bcd0683 commit 3e99055

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#![feature(default_field_values)]
2+
pub mod foo {
3+
pub struct Alpha {
4+
beta: u8 = 42,
5+
gamma: bool = true,
6+
}
7+
}
8+
9+
mod bar {
10+
fn baz() {
11+
let x = crate::foo::Alpha { .. };
12+
//~^ ERROR field `beta` of struct `Alpha` is private
13+
//~| ERROR field `gamma` of struct `Alpha` is private
14+
}
15+
}
16+
17+
pub mod baz {
18+
pub struct S {
19+
x: i32 = 1,
20+
}
21+
}
22+
fn main() {
23+
let a = baz::S {
24+
.. //~ ERROR field `x` of struct `S` is private
25+
};
26+
let b = baz::S {
27+
x: 0, //~ ERROR field `x` of struct `S` is private
28+
};
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0451]: field `x` of struct `S` is private
2+
--> $DIR/visibility.rs:24:9
3+
|
4+
LL | ..
5+
| ^^ field `x` is private
6+
7+
error[E0451]: field `x` of struct `S` is private
8+
--> $DIR/visibility.rs:27:9
9+
|
10+
LL | x: 0,
11+
| ^^^^ private field
12+
13+
error[E0451]: field `beta` of struct `Alpha` is private
14+
--> $DIR/visibility.rs:11:37
15+
|
16+
LL | let x = crate::foo::Alpha { .. };
17+
| ^^ field `beta` is private
18+
19+
error[E0451]: field `gamma` of struct `Alpha` is private
20+
--> $DIR/visibility.rs:11:37
21+
|
22+
LL | let x = crate::foo::Alpha { .. };
23+
| ^^ field `gamma` is private
24+
25+
error: aborting due to 4 previous errors
26+
27+
For more information about this error, try `rustc --explain E0451`.

0 commit comments

Comments
 (0)