-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
typeck: better diagnostics for missing inaccessible fields in struct …
…literals/patterns - typeck/expr: don't suggest adding fields in struct literals with inaccessible fields - typeck/pat: suggest ignoring inaccessible fields in struct patterns
- Loading branch information
Showing
6 changed files
with
77 additions
and
20 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
11 changes: 11 additions & 0 deletions
11
src/test/ui/typeck/issue-87872-missing-inaccessible-field-literal.rs
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,11 @@ | ||
pub mod foo { | ||
pub struct Foo { | ||
pub you_can_use_this_field: bool, | ||
you_cant_use_this_field: bool, | ||
} | ||
} | ||
|
||
fn main() { | ||
foo::Foo {}; | ||
//~^ ERROR cannot construct `Foo` with struct literal syntax due to inaccessible fields | ||
} |
8 changes: 8 additions & 0 deletions
8
src/test/ui/typeck/issue-87872-missing-inaccessible-field-literal.stderr
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-87872-missing-inaccessible-field-literal.rs:9:5 | ||
| | ||
LL | foo::Foo {}; | ||
| ^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
11 changes: 11 additions & 0 deletions
11
src/test/ui/typeck/issue-87872-missing-inaccessible-field-pattern.rs
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,11 @@ | ||
#![allow(dead_code, unused_variables)] | ||
|
||
pub mod foo { | ||
#[derive(Default)] | ||
pub struct Foo { pub visible: bool, invisible: bool, } | ||
} | ||
|
||
fn main() { | ||
let foo::Foo {} = foo::Foo::default(); | ||
//~^ ERROR pattern does not mention field `visible` and inaccessible fields | ||
} |
18 changes: 18 additions & 0 deletions
18
src/test/ui/typeck/issue-87872-missing-inaccessible-field-pattern.stderr
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 @@ | ||
error[E0027]: pattern does not mention field `visible` and inaccessible fields | ||
--> $DIR/issue-87872-missing-inaccessible-field-pattern.rs:9:9 | ||
| | ||
LL | let foo::Foo {} = foo::Foo::default(); | ||
| ^^^^^^^^^^^ missing field `visible` and inaccessible fields | ||
| | ||
help: include the missing field in the pattern and ignore the inaccessible fields | ||
| | ||
LL | let foo::Foo { visible, .. } = foo::Foo::default(); | ||
| ^^^^^^^^^^^^^^^ | ||
help: if you don't care about this missing field, you can explicitly ignore it | ||
| | ||
LL | let foo::Foo { .. } = foo::Foo::default(); | ||
| ^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0027`. |