-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Create more error codes #42519
Create more error codes #42519
Conversation
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
Presumably meant to be |
9bedfa8
to
341f827
Compare
Absolutely! |
Fixed btw. |
src/librustc_typeck/diagnostics.rs
Outdated
v as &u8; // error: non-scalar cast: `*const u8` as `&u8` | ||
``` | ||
|
||
Only primitive types cast be casted into each others. Examples: |
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 read: "Only primitive types can be cast into each other"
src/librustc_typeck/diagnostics.rs
Outdated
let y: u32 = x as u32; // error: casting `&u8` as `u32` is invalid | ||
``` | ||
|
||
When casting, keep in mind that only primitive types cast be casted into each |
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.
Same as above.
I'm thinking the first line should read more like "Casting between non-primitive types" or something instead of just saying "invalid cast" and then having to explain every time that a valid cast is just between primitives.
src/librustc_typeck/diagnostics.rs
Outdated
Thin pointers are "simple" pointers that simply reference a memory address. | ||
|
||
Fat pointers are pointers referencing Dynamically Sized Types (also called DST). | ||
They don't have a statically known size, therefore they can only exist behind |
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.
"DST" instead of "They" at the start to be more clear.
src/librustc_typeck/diagnostics.rs
Outdated
some kind of pointers that contain additional information. Slices and trait | ||
objects are DSTs. | ||
|
||
So in order to fix this error, don't try to cast directly between thin and fat |
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.
Get rid of "So in order"
@@ -20,57 +20,67 @@ error: no field `f` on type `fn() {main}` | |||
75 | let _ = main.f as *const u32; | |||
| ^ | |||
|
|||
error: non-scalar cast: `*const u8` as `&u8` | |||
error[E0605]: non-scalar cast: `*const u8` as `&u8` |
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.
Any way to remove "non-scalar" from this? Your expanded error descriptions you added above use the term "primitive types", can that be used everywhere for all these errors instead of "non-scalar"? I never see "non-scalar" in any docs anywhere.
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.
Hum, do you have a better formulation?
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.
"non-primitive cast"? Primitive is a word people will/should be exposed to when using rust. I don't think "non-scalar" appears much in the docs (though I haven't searched, but I've never seen it).
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.
Fine by me!
341f827
to
c1791ba
Compare
Updated. |
src/librustc_typeck/diagnostics.rs
Outdated
@@ -4095,6 +4095,91 @@ assert_eq!(!Question::No, true); | |||
``` | |||
"##, | |||
|
|||
E0604: r##" | |||
A cast to `char` was attempted on another type than `u8`. |
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 reads awkwardly. I suggest "was attempted on a type other than u8
".
This error does bring up the question of why are only u8
s castable to char
s? I thought a char
in rust was 4 bytes?
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 think it comes straight from the C language. In C, char are 8 bits and supposed to represent ascii characters.
src/librustc_typeck/diagnostics.rs
Outdated
let y: u32 = x as u32; // error: casting `&u8` as `u32` is invalid | ||
``` | ||
|
||
When casting, keep in mind that only primitive types cast be casted into each |
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 "can be casted"
src/librustc_typeck/diagnostics.rs
Outdated
|
||
First: what are thin and fat pointers? | ||
|
||
Thin pointers are "simple" pointers that simply reference a memory address. |
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.
Maybe instead be more clear what simple means: "Thin pointers are purely a reference to a memory address"
src/librustc_typeck/diagnostics.rs
Outdated
|
||
Fat pointers are pointers referencing Dynamically Sized Types (also called DST). | ||
DST don't have a statically known size, therefore they can only exist behind | ||
some kind of pointers that contain additional information. Slices and trait |
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 brings up the question of why? What extra information is required to be stored that makes a fat pointer a necessity. Adding a sentence or clarifying why just a pure memory address would be useful here (I'm not even actually sure of why fat pointers are necessary).
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.
So, the explanation for you too (so nice of me haha 😉 ). Let's take a slice: you need in addition of the memory address, the size of the slice.
That's actually a good explanation, I'll add it. :)
c1791ba
to
69cdf76
Compare
Updated. |
e18afb3
to
c70c37a
Compare
src/librustc_typeck/diagnostics.rs
Outdated
v as &u8; // error: non-primitive cast: `*const u8` as `&u8` | ||
``` | ||
|
||
Only primitive types cast be casted into each other. Examples: |
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.
"can be casted"
c70c37a
to
b0016ca
Compare
Updated. |
src/librustc_typeck/diagnostics.rs
Outdated
let y: u32 = x as u32; // error: casting `&u8` as `u32` is invalid | ||
``` | ||
|
||
When casting, keep in mind that only primitive types can be casted into each |
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.
There are a few instances of "casted" used here when I think the past tense of "cast" is actually just "cast".
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.
Damn irregular verbs! :p
b0016ca
to
b9804ad
Compare
Fixed the verbing error. |
☔ The latest upstream changes (presumably #42585) made this pull request unmergeable. Please resolve the merge conflicts. |
b9804ad
to
851fbbc
Compare
And re-updated. cc @Susurrus |
LGTM |
@bors: r+ |
📌 Commit 851fbbc has been approved by |
@bors r- who is the reviewer? |
r? @frewsxcv |
Thin pointers are "simple" pointers: they are purely a reference to a memory | ||
address. | ||
|
||
Fat pointers are pointers referencing Dynamically Sized Types (also called DST). |
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 don't know if "dynamically sized types" needs to be capitalized here, but not a big deal
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 agree, it shouldn't be capitalized.
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.
It was to make easier the understanding of DST.
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.
Ok removed.
src/librustc_typeck/diagnostics.rs
Outdated
"##, | ||
|
||
E0606: r##" | ||
A cast between non-primitive types was attempted. |
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.
As long as this is the catch-all error message for invalid casting, I'm slightly leaning towards listing all the different casting rules. Maybe we could just link to the book? Other error messages seem to link to the book/reference
So, I added an url to the rust reference to every cast rules in all long error explanation. Do you think I need to update something else? |
I still think it would be better to rephrase the explain text for E0606 to state something like "incompatible cast" instead of talking about "non-primitive types". Especially now that it's linking to the list of "valid casts", we can just call it "invalid" or "incompatible" or something like that. |
☔ The latest upstream changes (presumably #42568) made this pull request unmergeable. Please resolve the merge conflicts. |
7c12bbb
to
9137153
Compare
I slightly updated the long error explanation. Does it seem good like this? |
It looks like the links to the reference got taken out in the last update? I'd rather leave those in. |
Updated. |
Travis looks stuck on one builder, but the ALLOW_PR build passed, so that's good enough for me. @bors r+ Thanks so much! |
📌 Commit bcf0d60 has been approved by |
@bors rollup |
…des, r=QuietMisdreavus Create more error codes Fixes rust-lang#31174. Part of rust-lang#42229. cc @Susurrus
Remove err methods To be merged after #42519. cc @Susurrus @QuietMisdreavus
Fixes #31174.
Part of #42229.
cc @Susurrus