-
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
New error codes #42614
New error codes #42614
Conversation
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
src/librustc_typeck/diagnostics.rs
Outdated
@@ -4152,6 +4152,252 @@ println!("x: {}, y: {}", variable.x, variable.y); | |||
For more information see The Rust Book: https://doc.rust-lang.org/book/ | |||
"##, | |||
|
|||
E0611: r##" | |||
Attempted to access to a private field on a tuple-struct. |
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.
Should be "Attempted to access a private field on a tuple-struct."
src/librustc_typeck/diagnostics.rs
Outdated
|
||
Since the field is private, you have two solutions: | ||
|
||
First one: set the field public: |
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.
Use "make" instead of "set"
src/librustc_typeck/diagnostics.rs
Outdated
println!("{}", y.0); // So we can access it directly. | ||
``` | ||
|
||
Second one: add a getter function to keep the field private but allow to access |
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.
Instead "add a getter function to keep the field private but allow for accessing its value:".
src/librustc_typeck/diagnostics.rs
Outdated
// on type `Foo` | ||
``` | ||
|
||
If a tuple/tuple-struct type has x fields, you can only try to access these x |
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.
I'd suggest using "n" here instead of "x" as "n" is commonly used for referring to integer values.
src/librustc_typeck/diagnostics.rs
Outdated
println!("({}, {}, {}, {})", x.0, x.1, x.2, x.3); | ||
``` | ||
|
||
If you want to index an array, use `[]` instead: |
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.
Instead "If you want to index into an array, use []
instead:"
src/librustc_typeck/diagnostics.rs
Outdated
f.method(); | ||
``` | ||
|
||
However, if you wanted to access a field, of the struct, check if you didn't |
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.
Too many commas and incorrect conjugation. Instead "However, if you wanted to access a field of a struct check that the field name is spelled correctly."
src/librustc_typeck/diagnostics.rs
Outdated
"##, | ||
|
||
E0616: r##" | ||
Attempted to access to a private field on a struct. |
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.
Instead "Attempted to access a private field on a struct."
src/librustc_typeck/diagnostics.rs
Outdated
|
||
If you want to access this field, you have two options: | ||
|
||
First one: set the field public: |
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.
Instead: "1) Set the field public:"
I don't like the double-colons on this line.
src/librustc_typeck/diagnostics.rs
Outdated
println!("{}", f.x); // ok! | ||
``` | ||
|
||
Second one: add a getter function: |
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.
Instead "2) Add a getter function:"
src/librustc_typeck/check/mod.rs
Outdated
idx.node, expr_t).emit(); | ||
} else { | ||
type_error_struct!(self.tcx().sess, expr.span, expr_t, E0613, | ||
"attempted tuple index `{}` on type `{}`, but the type was not a \ |
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.
I suggest instead: "attempted to access tuple index {}
on type {}
, but the type is not a tuple or tuple struct"
9c9d0a0
to
8063e12
Compare
@Susurrus: Thanks a lot for this review! Updated. :) |
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.
Travis found some errors
println!("({}, {}, {}, {})", x.0, x.1, x.2, x.3); | ||
``` | ||
|
||
If you want to index into an array, use `[]` instead: |
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.
index into a slice
would this be more accurate?
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.
I wanted to include both Vec and slices.
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.
In the context of Rust, when I see the term "array" I often think of fixed-length arrays [T; n]
. But I don't have a better term on hand that covers the cases here, so this is fine with me.
println!("[{}, {}, {}, {}]", x[0], x[1], x[2], x[3]); | ||
``` | ||
|
||
If you want to access a field of a struct, check the field's name wasn't |
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.
If you want to access a field of a struct, ensure the field's name is spelled correctly
this sounds better to me, but i don't feel strongly
8063e12
to
0a2d5dc
Compare
☔ The latest upstream changes (presumably #42644) made this pull request unmergeable. Please resolve the merge conflicts. |
0a2d5dc
to
ee60064
Compare
Rebased. |
Would it be worth combining E0611 (private field access, tuple struct) and E0616 (private field access, traditional struct)? From the user's perspective, it's the same error, just in different situations. (EDIT: For any infra team members who see this in a week, I believe imperio just left for a 10-day vacation, so updates on this will likely wait until he's come back from that.) |
ping @pnkfelix, I think this is ready for a re-review |
@bors r+ |
📌 Commit ee60064 has been approved by |
New error codes Part of #42229. cc @Susurrus @frewsxcv @QuietMisdreavus
☀️ Test successful - status-appveyor, status-travis |
Part of #42229.
cc @Susurrus @frewsxcv @QuietMisdreavus