E4001#
A field with incompatible visibility cannot be declared within a struct.
The following visibility combinations are allowed:
A public field within a public struct, although it will emit a warning E1008.
A private field within a public struct.
A private field within a private struct, emitting E1008 as well.
Erroneous Example#
priv struct S {
pub field: Int
}
This example declares a field with public visibility within a struct with private visibility, which is not allowed and will give the following error on line 2:
A public field cannot be declared within a private struct.
Suggestion#
Change the visibility of the field to match the visibility of the struct:
priv struct S {
field: Int
}
We could have written priv field: Int
instead of field: Int
as well,
but it is not necessary, as all fields in a private struct are private
by default.