-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #79956 - camelid:variant-field-vis, r=petrochenkov
Resolve enum field visibility correctly Fixes #79593. 🎉 Previously, this code treated enum fields' visibility as if they were struct fields. However, that's not correct because the visibility of a struct field with `ast::VisibilityKind::Inherited` is private to the module it's defined in, whereas the visibility of an *enum* field with `ast::VisibilityKind::Inherited` is the visibility of the enum it belongs to.
- Loading branch information
Showing
5 changed files
with
75 additions
and
3 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
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,29 @@ | ||
mod foo { | ||
pub struct Pub { private: () } | ||
|
||
pub enum Enum { | ||
Variant { x: (), y: () }, | ||
Other | ||
} | ||
|
||
fn correct() { | ||
Pub {}; | ||
//~^ ERROR missing field `private` in initializer of `Pub` | ||
Enum::Variant { x: () }; | ||
//~^ ERROR missing field `y` in initializer of `Enum` | ||
} | ||
} | ||
|
||
fn correct() { | ||
foo::Pub {}; | ||
//~^ ERROR cannot construct `Pub` with struct literal syntax due to inaccessible fields | ||
} | ||
|
||
fn wrong() { | ||
foo::Enum::Variant { x: () }; | ||
//~^ ERROR missing field `y` in initializer of `Enum` | ||
foo::Enum::Variant { }; | ||
//~^ ERROR missing fields `x`, `y` in initializer of `Enum` | ||
} | ||
|
||
fn main() {} |
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,33 @@ | ||
error[E0063]: missing field `private` in initializer of `Pub` | ||
--> $DIR/issue-79593.rs:10:9 | ||
| | ||
LL | Pub {}; | ||
| ^^^ missing `private` | ||
|
||
error[E0063]: missing field `y` in initializer of `Enum` | ||
--> $DIR/issue-79593.rs:12:9 | ||
| | ||
LL | Enum::Variant { x: () }; | ||
| ^^^^^^^^^^^^^ missing `y` | ||
|
||
error: cannot construct `Pub` with struct literal syntax due to inaccessible fields | ||
--> $DIR/issue-79593.rs:18:5 | ||
| | ||
LL | foo::Pub {}; | ||
| ^^^^^^^^ | ||
|
||
error[E0063]: missing field `y` in initializer of `Enum` | ||
--> $DIR/issue-79593.rs:23:5 | ||
| | ||
LL | foo::Enum::Variant { x: () }; | ||
| ^^^^^^^^^^^^^^^^^^ missing `y` | ||
|
||
error[E0063]: missing fields `x`, `y` in initializer of `Enum` | ||
--> $DIR/issue-79593.rs:25:5 | ||
| | ||
LL | foo::Enum::Variant { }; | ||
| ^^^^^^^^^^^^^^^^^^ missing `x`, `y` | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0063`. |