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

Incorrect suggestion for referencing a cast #46756

Closed
varkor opened this issue Dec 15, 2017 · 0 comments · Fixed by #46761
Closed

Incorrect suggestion for referencing a cast #46756

varkor opened this issue Dec 15, 2017 · 0 comments · Fixed by #46761
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. WG-diagnostics Working group: Diagnostics

Comments

@varkor
Copy link
Member

varkor commented Dec 15, 2017

#![crate_type = "lib"]

use std::collections::HashSet;

pub struct T {}

fn f(map: HashSet<usize>, v: *const T) {
    map.contains(v as usize);
}

The current error message is:

  |
8 |     map.contains(v as usize);
  |                  ^^^^^^^^^^ expected &usize, found usize
  |
  = note: expected type `&usize`
             found type `usize`
  = help: try with `&v as usize`

It should suggest trying &(v as usize): at the moment, if the user tries the current suggestion, they'll be told to try &&v as usize, and so on.
Playground link

zackmdavis added a commit to zackmdavis/rust that referenced this issue Dec 16, 2017
This simple patch resolves rust-lang#46756 (which was specifically about the case of
casts, but it would be poor form indeed to fix a reported issue without at
least a cursory attempt at answering the immortal question, "How does this bug
generalize?").
@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. WG-diagnostics Working group: Diagnostics labels Dec 16, 2017
bors added a commit that referenced this issue Dec 17, 2017
…r_referencing_a_cast, r=estebank

in which suggestions to borrow casts or binary expressions are rectified

 resolves #46756

r? @estebank
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. WG-diagnostics Working group: Diagnostics
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants