-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Point at private fields in struct literal #98283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
error: cannot construct `Foo` with struct literal syntax due to inaccessible fields | ||
error: cannot construct `Foo` with struct literal syntax due to private fields | ||
--> $DIR/issue-76077.rs:8:5 | ||
| | ||
LL | foo::Foo {}; | ||
| ^^^^^^^^ | ||
| | ||
note: missing field `you_cant_use_this_field` is private | ||
--> $DIR/issue-76077.rs:3:9 | ||
| | ||
LL | you_cant_use_this_field: bool, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,17 @@ error[E0063]: missing field `y` in initializer of `Enum` | |
LL | Enum::Variant { x: () }; | ||
| ^^^^^^^^^^^^^ missing `y` | ||
|
||
error: cannot construct `Pub` with struct literal syntax due to inaccessible fields | ||
error: cannot construct `Pub` with struct literal syntax due to private fields | ||
--> $DIR/issue-79593.rs:18:5 | ||
| | ||
LL | foo::Pub {}; | ||
| ^^^^^^^^ | ||
| | ||
note: missing field `private` is private | ||
--> $DIR/issue-79593.rs:2:22 | ||
| | ||
LL | pub struct Pub { private: () } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, maybe we shouldn't actually point out private fields' definition. It seems like excessive info and showing a private field is kinda against its own purpose... |
||
| ^^^^^^^^^^^ | ||
|
||
error[E0063]: missing field `y` in initializer of `Enum` | ||
--> $DIR/issue-79593.rs:23:5 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
error: cannot construct `Foo` with struct literal syntax due to inaccessible fields | ||
error: cannot construct `Foo` with struct literal syntax due to private fields | ||
--> $DIR/issue-87872-missing-inaccessible-field-literal.rs:9:5 | ||
| | ||
LL | foo::Foo {}; | ||
| ^^^^^^^^ | ||
| | ||
note: missing field `you_cant_use_this_field` is private | ||
--> $DIR/issue-87872-missing-inaccessible-field-literal.rs:4:9 | ||
| | ||
LL | you_cant_use_this_field: bool, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
pub mod m { | ||
pub struct S { | ||
pub visible: bool, | ||
a: (), | ||
b: (), | ||
c: (), | ||
d: (), | ||
e: (), | ||
} | ||
} | ||
|
||
fn main() { | ||
let _ = m::S { //~ ERROR cannot construct `S` with struct literal syntax due to private fields | ||
visible: true, | ||
a: (), | ||
b: (), | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
error: cannot construct `S` with struct literal syntax due to private fields | ||
--> $DIR/missing-private-fields-in-struct-literal.rs:13:13 | ||
| | ||
LL | let _ = m::S { | ||
| ^^^^ | ||
LL | visible: true, | ||
LL | a: (), | ||
| ----- private field | ||
LL | b: (), | ||
| ----- private field | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe just a note with something like "... and other private fields that were not provided" instead of pointing out the actual fields in the struct definition? |
||
| | ||
note: missing fields `c`, `d` and `e` are private | ||
--> $DIR/missing-private-fields-in-struct-literal.rs:6:9 | ||
| | ||
LL | c: (), | ||
| ^^^^^ | ||
LL | d: (), | ||
| ^^^^^ | ||
LL | e: (), | ||
| ^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
Uh oh!
There was an error while loading. Please reload this page.