Skip to content

Incorrect suggestion for referencing a cast #46756

Closed
@varkor

Description

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

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

    Development

    No branches or pull requests

    Issue actions