Uh oh!
There was an error while loading. Please reload this page.
Improve message when attempting to instantiate tuple structs with private fields - #65153
Conversation
rust-highfive
commented
Oct 6, 2019
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
petrochenkov
commented
Oct 6, 2019
Should perhaps make the top line "tuple struct constructor |
petrochenkov
commented
Oct 8, 2019
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 |
petrochenkov
commented
Oct 8, 2019
We already have the |
Uh oh!
There was an error while loading. Please reload this page.
da-x
commented
Oct 8, 2019
It's not quite simple - even if we add to |
petrochenkov
commented
Oct 8, 2019
The type's |
da-x
commented
Oct 8, 2019
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. |
petrochenkov
commented
Oct 8, 2019
|
da-x
commented
Oct 9, 2019
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): |
da-x
commented
Oct 9, 2019
Your version looks much better - didn't know of |
petrochenkov
commented
Oct 9, 2019
At your discretion. |
Oh crap, committed with a work email. |
da-x
commented
Oct 9, 2019
The changes are ready. |
petrochenkov
commented
Oct 9, 2019
@bors r+ Sorry for stealing the work. |
bors
commented
Oct 9, 2019
📌 Commit 48f8bed has been approved by |
da-x
commented
Oct 9, 2019
@petrochenkov No problem - it had been educational anyway. And yes, I have the other suggested change queued up after this one is merged :) |
bors
commented
Oct 10, 2019
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 ```
bors
commented
Oct 10, 2019
☀️ 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.