-
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
Improve reference cast help message #37375
Conversation
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
7ddd19f
to
329e1f5
Compare
You completely changed the meaning though, now it's bad if the user wanted to do the pointer thing. |
But at least it's not incorrect anymore. |
@GuillaumeGomez: I'm not sure, but wouldn't your patch suggest dereferencing the pointer also in the following case: let _ = &String::new() as usize; Here, the original message is more accurate, I think. |
In @TimNN's example, the original message clearly makes more sense. In the example from #37338, there is genuine ambiguity about which one the user wanted to do, but I would argue that the new suggestion is probably better because I suspect that the deref case is the more common one. Would it makes sense to check the |
I'd argue that only |
@TimNN: Well saw and not well saw at the same time. In this case, you should have to explicitly cast into a pointer before casting to usize. However, it just puts under the light a big issue: the compiler cannot guess what the user intends to do in some cases and only provide the simplest solution. In this case, more people will certainly think that you just want to get the length and you put @fhartwig: Still difficult. But we could provide both helps. What do you think about this @eddyb? |
@GuillaumeGomez IMO having both is more confusing. |
Ok, I'll update it this way then. |
@GuillaumeGomez, I hadn't seen that this PR was already out, so I took a stab at it as well. I still feel there's some value in PR #37442, as it handles the case @TimNN pushed forward as it is now, and specializes the cases of For a given file: fn main() {
vec![0.0].iter().map(|s| s as i16).collect::<Vec<i16>>();
let _ = &String::new() as usize;
} PR #37442 outputs:
|
@estebank: I still need to update it anyway. I intend to do it this week-end. |
329e1f5
to
ddd00f7
Compare
Updated. |
Travis failure looks unrelated.
|
I restart it. |
cc @eddyb |
You seem to have removed too many messages. |
Agree with @eddyb - why remove the help messages? |
@jonathandturner: It comes after a discussion between @eddyb and me. Since a lot of messages were incorrect in some cases, it should be better to just remove them. However, after the last messages, I think I misunderstood him. Any further explanation would be appreciated. :) |
What I mean is only providing the "pointer to integer" help if |
d4c7a85
to
5c341b1
Compare
Updated. |
@@ -54,7 +54,7 @@ fn main() | |||
//~^^ HELP through a usize first | |||
let _ = &v as usize; | |||
//~^ ERROR casting | |||
//~^^ HELP through a raw pointer first | |||
//~| HELP cast through a raw pointer first |
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 think you need to change anything in this file.
b as usize; //~ ERROR non-scalar cast | ||
p as usize; | ||
//~^ ERROR casting | ||
//~^^ HELP cast through a thin pointer |
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.
These should still emit the help. It's only when that usize
is replaced with another type that it's wrong.
@@ -13,5 +13,4 @@ struct Inches(i32); | |||
fn main() { | |||
Inches as f32; | |||
//~^ ERROR casting | |||
//~^^ cast through a usize first |
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.
How could this have disappeared?
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.
Inches
is a function pointer.
5c341b1
to
157acc8
Compare
@eddyb: Didn't pay attention to the tests I updated. Fixed now. |
@GuillaumeGomez Can you add non- |
That's another debate I think haha. If you can imagine something weird, someone will do something weirder. |
9bda5fb
to
3f0c2d2
Compare
cc @eddyb |
|
3f0c2d2
to
37903bf
Compare
@bors r+ |
📌 Commit 37903bf has been approved by |
⌛ Testing commit 37903bf with merge f22fdb0... |
Improve reference cast help message Fixes #37338.
Fixes #37338.