-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Improve message when attempting to instantiate tuple structs with private fields #65153
Conversation
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
Should perhaps make the top line "tuple struct constructor |
AFAIR, we just didn't want to say "constructor" in error messages because it wasn't an official enough term. |
Is it really necessary to point to the specific private field? I would be great to avoid adding more state to |
We already have the |
It's not quite simple - even if we add to |
The type's |
Is this result good? I'm not sure yet how to get the span for just the fields. I've got the span for the struct itself.
|
|
One limitation I noticed is that it doesn't work well when the types are in an external crate. It wasn't trivial to work with the changes in Another limitation is that going to the parent |
The link below shows how to do that.
The note is irrelevant to variants (they cannot have private fields) and shouldn't be reported for them. What I wanted is a minimal patch addressing the issue and not spreading to other code not related to this specific message (i.e. not span manipulations in build_reduced_graph, etc): |
Your version looks much better - didn't know of |
At your discretion. |
Oh crap, committed with a work email. |
The changes are ready. |
@bors r+ Sorry for stealing the work. |
📌 Commit 48f8bed has been approved by |
@petrochenkov No problem - it had been educational anyway. And yes, I have the other suggested change queued up after this one is merged :) |
Improve message when attempting to instantiate tuple structs with private fields Fixes #58017, fixes #39703. ``` error[E0603]: tuple struct `Error` is private --> main.rs:22:16 | 2 | pub struct Error(usize, pub usize, usize); | ----- ----- field is private | | | field is private ... 22 | let x = a::Error(3, 1, 2); | ^^^^^ | = note: a tuple struct constructor is private if any of its fields is private ```
☀️ Test successful - checks-azure |
The constructor is private, not the type. Idea credit to @petrochenkov, discussed at rust-lang#65153
…nkov resolve: fix error title regarding private constructors One reason is that constructors can be private while their types can be public. Idea credit to @petrochenkov, discussed at rust-lang#65153
Fixes #58017, fixes #39703.