-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-visibilityArea: Visibility / privacyArea: Visibility / privacyC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
mod first {
#[derive(Debug)]
pub struct SomeId(u32);
}
mod second {
use ::first::SomeId;
#[derive(Debug)]
pub enum MyEnum {
Variant1 {
id: SomeId
}
}
}
fn main() {
use first::SomeId;
use second::MyEnum;
let test = MyEnum::Variant1 {
id: SomeId(32),
};
println!("{:?}", test);
}
This gave me the following error message:
error[E0423]: expected function, found struct `SomeId`
--> src/main.rs:22:13
|
22 | id: SomeId(32),
| ^^^^^^
| |
| did you mean `Some`?
| constructor is not visible here due to private fields
help: possible better candidate is found in another module, you can import it into scope
|
1 | use first::SomeId;
|
It turns out the fix for this was to change my struct definition to pub struct SomeId(pub u32);
. This was not obvious to me for several reasons:
- The
expected function, found struct SomeId
is odd because that's what I'm trying to perform, so it appears like it's erroring because it's doing what I want. - The suggestion for the use statement is completely incorrect, as that use statement already exists and won't fix the problem
- The
constructor is not visible here due to private fields
didn't make sense to me as the rust book never gives an example of theStruct(pub fieldType)
syntax, so I assumed tuple fields had the same visibility as the struct itself.
It probably needs a recommendation for tuple structs to show that all fields should be marked as pub
max-sixty, ens-ds23, Farkal, MaxNanasy, hammypants and 4 more
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-visibilityArea: Visibility / privacyArea: Visibility / privacyC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.