Skip to content
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

Merged
merged 7 commits into from
Jun 27, 2017
Merged

Conversation

GuillaumeGomez
Copy link
Member

Fixes #31174.
Part of #42229.

cc @Susurrus

@rust-highfive
Copy link
Collaborator

r? @pnkfelix

(rust_highfive has picked a reviewer for you, use r? to override)

@aidanhs
Copy link
Member

aidanhs commented Jun 8, 2017

[00:46:17] 	error[E0600]: cannot apply unary operator `!` to type `char`
[00:46:17]  --> <anon>:3:1
[00:46:17]   |
[00:46:17] 3 | assert!(c, 'V');
[00:46:17]   | ^^^^^^^^^^^^^^^^
[00:46:17]   |
[00:46:17]   = note: this error originates in a macro outside of the current crate

Presumably meant to be assert_eq?

@aidanhs aidanhs added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 8, 2017
@GuillaumeGomez
Copy link
Member Author

Absolutely!

@GuillaumeGomez
Copy link
Member Author

GuillaumeGomez commented Jun 9, 2017

Fixed btw.

v as &u8; // error: non-scalar cast: `*const u8` as `&u8`
```

Only primitive types cast be casted into each others. Examples:
Copy link
Contributor

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"

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
Copy link
Contributor

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.

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
Copy link
Contributor

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.

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
Copy link
Contributor

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`
Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Contributor

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).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me!

@GuillaumeGomez
Copy link
Member Author

Updated.

@@ -4095,6 +4095,91 @@ assert_eq!(!Question::No, true);
```
"##,

E0604: r##"
A cast to `char` was attempted on another type than `u8`.
Copy link
Contributor

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 u8s castable to chars? I thought a char in rust was 4 bytes?

Copy link
Member Author

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.

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
Copy link
Contributor

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"


First: what are thin and fat pointers?

Thin pointers are "simple" pointers that simply reference a memory address.
Copy link
Contributor

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"


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
Copy link
Contributor

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).

Copy link
Member Author

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. :)

@GuillaumeGomez
Copy link
Member Author

Updated.

@GuillaumeGomez GuillaumeGomez force-pushed the create-more-error-codes branch 3 times, most recently from e18afb3 to c70c37a Compare June 10, 2017 19:23
v as &u8; // error: non-primitive cast: `*const u8` as `&u8`
```

Only primitive types cast be casted into each other. Examples:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"can be casted"

@GuillaumeGomez
Copy link
Member Author

Updated.

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
Copy link
Contributor

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".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn irregular verbs! :p

@GuillaumeGomez
Copy link
Member Author

Fixed the verbing error.

@bors
Copy link
Contributor

bors commented Jun 12, 2017

☔ The latest upstream changes (presumably #42585) made this pull request unmergeable. Please resolve the merge conflicts.

@GuillaumeGomez
Copy link
Member Author

And re-updated. cc @Susurrus

@Susurrus
Copy link
Contributor

LGTM

@GuillaumeGomez
Copy link
Member Author

@bors: r+

@bors
Copy link
Contributor

bors commented Jun 12, 2017

📌 Commit 851fbbc has been approved by GuillaumeGomez

@frewsxcv
Copy link
Member

@bors r-

who is the reviewer?

@GuillaumeGomez
Copy link
Member Author

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).
Copy link
Member

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

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok removed.

"##,

E0606: r##"
A cast between non-primitive types was attempted.
Copy link
Member

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

@GuillaumeGomez
Copy link
Member Author

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?

@QuietMisdreavus
Copy link
Member

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.

@bors
Copy link
Contributor

bors commented Jun 16, 2017

☔ The latest upstream changes (presumably #42568) made this pull request unmergeable. Please resolve the merge conflicts.

@arielb1 arielb1 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 20, 2017
@GuillaumeGomez
Copy link
Member Author

I slightly updated the long error explanation. Does it seem good like this?

@QuietMisdreavus
Copy link
Member

It looks like the links to the reference got taken out in the last update? I'd rather leave those in.

@GuillaumeGomez
Copy link
Member Author

Updated.

@QuietMisdreavus
Copy link
Member

Travis looks stuck on one builder, but the ALLOW_PR build passed, so that's good enough for me.

@bors r+

Thanks so much!

@bors
Copy link
Contributor

bors commented Jun 26, 2017

📌 Commit bcf0d60 has been approved by QuietMisdreavus

@frewsxcv
Copy link
Member

@bors rollup

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Jun 27, 2017
…des, r=QuietMisdreavus

Create more error codes

Fixes rust-lang#31174.
Part of rust-lang#42229.

cc @Susurrus
bors added a commit that referenced this pull request Jun 27, 2017
Rollup of 5 pull requests

- Successful merges: #42519, #42871, #42874, #42905, #42917
- Failed merges:
@bors bors merged commit bcf0d60 into rust-lang:master Jun 27, 2017
@GuillaumeGomez GuillaumeGomez deleted the create-more-error-codes branch June 27, 2017 07:42
bors added a commit that referenced this pull request Jun 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants