Skip to content

nll: strange suggestion to "consider removing the * #54985

Closed
@pnkfelix

Description

@pnkfelix

Spawned off of #54825 (comment)

For this code:

unsafe fn foo(x: *const Box<isize>) -> Box<isize> {
let y = *x; //~ ERROR cannot move out of dereference of raw pointer
return y;
}

which produces this diagnostic output:

LL | let y = *x; //~ ERROR cannot move out of dereference of raw pointer
| ^^
| |
| cannot move out of dereference of raw pointer
| help: consider removing the `*`: `x`

@nikomatsakis made this comment about the HELP on line 8:

Pre-existing but: it is...strange that we make this suggestion. It seems almost certainly wrong. It doesn't preserve the type or "intent" of the code in any particular way...? It's also distinct from what the AST checker says, which is to suggest &*x (though I would argue that is also wrong, for similar reasons). It feels like the best suggestion might be ptr::read but I'm sort of inclined to just not suggest anything at all.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-NLLArea: Non-lexical lifetimes (NLL)A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.NLL-diagnosticsWorking towards the "diagnostic parity" goalP-mediumMedium priority

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions