-
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.
Rollup merge of #76524 - davidtwco:issue-76077-inaccessible-private-f…
…ields, r=estebank typeck: don't suggest inaccessible private fields Fixes #76077. This PR adjusts the missing field diagnostic logic in typeck so that when none of the missing fields in a struct expr are accessible then the error is less confusing. r? @estebank
- Loading branch information
Showing
7 changed files
with
244 additions
and
42 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
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 | ||
|
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,10 @@ | ||
pub mod foo { | ||
pub struct Foo { | ||
you_cant_use_this_field: bool, | ||
} | ||
} | ||
|
||
fn main() { | ||
foo::Foo {}; | ||
//~^ ERROR cannot construct `Foo` with struct literal syntax 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,8 @@ | ||
error: cannot construct `Foo` with struct literal syntax due to inaccessible fields | ||
--> $DIR/issue-76077.rs:8:5 | ||
| | ||
LL | foo::Foo {}; | ||
| ^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|