-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
typeck/pat: inaccessible private fields
This commit adjusts the missing field diagnostic logic for struct patterns in typeck to improve the diagnostic when the missing fields are inaccessible. Signed-off-by: David Wood <david@davidtw.co>
- Loading branch information
Showing
4 changed files
with
141 additions
and
9 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,18 @@ | ||
// run-rustfix | ||
#![allow(dead_code, unused_variables)] | ||
|
||
pub mod foo { | ||
#[derive(Default)] | ||
pub struct Foo { invisible: bool, } | ||
|
||
#[derive(Default)] | ||
pub struct Bar { pub visible: bool, invisible: bool, } | ||
} | ||
|
||
fn main() { | ||
let foo::Foo { .. } = foo::Foo::default(); | ||
//~^ ERROR pattern requires `..` due to inaccessible fields | ||
|
||
let foo::Bar { visible, .. } = foo::Bar::default(); | ||
//~^ ERROR pattern requires `..` due to inaccessible fields | ||
} |
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,18 @@ | ||
// run-rustfix | ||
#![allow(dead_code, unused_variables)] | ||
|
||
pub mod foo { | ||
#[derive(Default)] | ||
pub struct Foo { invisible: bool, } | ||
|
||
#[derive(Default)] | ||
pub struct Bar { pub visible: bool, invisible: bool, } | ||
} | ||
|
||
fn main() { | ||
let foo::Foo {} = foo::Foo::default(); | ||
//~^ ERROR pattern requires `..` due to inaccessible fields | ||
|
||
let foo::Bar { visible } = foo::Bar::default(); | ||
//~^ ERROR pattern requires `..` due to inaccessible fields | ||
} |
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,24 @@ | ||
error: pattern requires `..` due to inaccessible fields | ||
--> $DIR/issue-76077-1.rs:13:9 | ||
| | ||
LL | let foo::Foo {} = foo::Foo::default(); | ||
| ^^^^^^^^^^^ | ||
| | ||
help: ignore the inaccessible and unused fields | ||
| | ||
LL | let foo::Foo { .. } = foo::Foo::default(); | ||
| ^^^^^^ | ||
|
||
error: pattern requires `..` due to inaccessible fields | ||
--> $DIR/issue-76077-1.rs:16:9 | ||
| | ||
LL | let foo::Bar { visible } = foo::Bar::default(); | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: ignore the inaccessible and unused fields | ||
| | ||
LL | let foo::Bar { visible, .. } = foo::Bar::default(); | ||
| ^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|