Skip to content

Incorrect suggestion for referencing a cast #46756

@varkor

Description

@varkor
Member
#![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

Activity

added a commit that references this issue on Dec 16, 2017
73a9019
added
A-diagnosticsArea: Messages for errors, warnings, and lints
C-bugCategory: This is a bug.
on Dec 16, 2017
added a commit that references this issue on Dec 17, 2017
3537658
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.WG-diagnosticsWorking group: Diagnostics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @estebank@varkor

      Issue actions

        Incorrect suggestion for referencing a cast · Issue #46756 · rust-lang/rust