-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Fix diagnostic for cross crate private tuple struct constructors #85068
Changes from all commits
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 | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,8 +2,30 @@ error[E0532]: cannot match against a tuple struct which contains private fields | |||||||||||||||||||||||||||
--> $DIR/issue-75907_b.rs:9:9 | ||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||
LL | let Bar(x, y, z) = make_bar(); | ||||||||||||||||||||||||||||
| ^^^ constructor is not visible here due to private fields | ||||||||||||||||||||||||||||
| ^^^ | ||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||
note: constructor is not visible here due to private fields | ||||||||||||||||||||||||||||
--> $DIR/issue-75907_b.rs:9:16 | ||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||
LL | let Bar(x, y, z) = make_bar(); | ||||||||||||||||||||||||||||
| ^ ^ private field | ||||||||||||||||||||||||||||
| | | ||||||||||||||||||||||||||||
| private field | ||||||||||||||||||||||||||||
Comment on lines
+5
to
+13
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. While looking at this again, I think we could make this slightly different, but it is not introduced by you:
Suggested change
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
error[E0532]: cannot match against a tuple struct which contains private fields | ||||||||||||||||||||||||||||
--> $DIR/issue-75907_b.rs:12:9 | ||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||
LL | let Foo(x, y, z) = Foo::new(); | ||||||||||||||||||||||||||||
| ^^^ | ||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||
note: constructor is not visible here due to private fields | ||||||||||||||||||||||||||||
--> $DIR/issue-75907_b.rs:12:13 | ||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||
LL | let Foo(x, y, z) = Foo::new(); | ||||||||||||||||||||||||||||
| ^ ^ private field | ||||||||||||||||||||||||||||
| | | ||||||||||||||||||||||||||||
| private field | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
error: aborting due to previous error | ||||||||||||||||||||||||||||
error: aborting due to 2 previous errors | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
For more information about this error, try `rustc --explain E0532`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ error[E0423]: cannot initialize a tuple struct which contains private fields | |
--> $DIR/struct.rs:20:14 | ||
| | ||
LL | let ts = TupleStruct(640, 480); | ||
| ^^^^^^^^^^^ constructor is not visible here due to private fields | ||
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. It seems at first sight that the removed block might be responsible for the removal of this span_label. 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. The reason we actually had this span_label before was because this was one of the cases handled by the 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. In that case we should also change the error message. I would like us to keep the |
||
| ^^^^^^^^^^^ | ||
|
||
error[E0423]: expected value, found struct `UnitStruct` | ||
--> $DIR/struct.rs:29:14 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this block removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This match case would only get hit for non-re-exported structs' constructors which is why we would miss the cross-crate case to begin with. So for a given newtype constructor we would sometimes hit both the
DefKind::Ctor
andDefKind::Struct
arms or only hit theDefKind::Struct
arm. It is the latter case where we didn't have the good diagnostics.callback
here collects the Exports which end up processed by the methodbuild_reduced_graph_for_external_crate_res
above:rust/compiler/rustc_metadata/src/rmeta/decoder.rs
Lines 1084 to 1095 in 2bafe96
So my PR just handles collecting
struct_constructors
for diagnostics always in theDefKind::Struct
arm instead of relying on theCtor
arm which isn't always present.