Skip to content

Commit 7332e03

Browse files
Add test privacy-in-params.rs
1 parent c0b081c commit 7332e03

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Checks whether privacy of fields is checked in parameters
2+
3+
mod hidden {
4+
pub struct Record { secret: u8 }
5+
}
6+
7+
fn leak(hidden::Record { secret }: hidden::Record) -> u8 {
8+
//~^ ERROR field `secret` of struct `Record` is private
9+
secret
10+
}
11+
12+
fn f() -> [u8; { let _ = hidden::Record { secret: 1 }; 0 }] {
13+
//~^ ERROR field `secret` of struct `Record` is private
14+
[]
15+
}
16+
17+
trait Test {
18+
fn trait_method() -> [u8; { let _ = hidden::Record { secret: 1 }; 0 }];
19+
//~^ ERROR field `secret` of struct `Record` is private
20+
}
21+
22+
fn main() {}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0451]: field `secret` of struct `Record` is private
2+
--> $DIR/privacy-in-params.rs:7:26
3+
|
4+
LL | fn leak(hidden::Record { secret }: hidden::Record) -> u8 {
5+
| ^^^^^^ private field
6+
7+
error[E0451]: field `secret` of struct `Record` is private
8+
--> $DIR/privacy-in-params.rs:12:43
9+
|
10+
LL | fn f() -> [u8; { let _ = hidden::Record { secret: 1 }; 0 }] {
11+
| ^^^^^^ private field
12+
13+
error[E0451]: field `secret` of struct `Record` is private
14+
--> $DIR/privacy-in-params.rs:18:58
15+
|
16+
LL | fn trait_method() -> [u8; { let _ = hidden::Record { secret: 1 }; 0 }];
17+
| ^^^^^^ private field
18+
19+
error: aborting due to 3 previous errors
20+
21+
For more information about this error, try `rustc --explain E0451`.

0 commit comments

Comments
 (0)