Skip to content

Compiler should hint to user to deref when doing reference assignment #33570

@frewsxcv

Description

@frewsxcv

https://is.gd/wm0S9G

fn change_opt(opt: &mut Option<String>){ opt = None }
<anon>:2:11: 2:15 error: mismatched types: expected `&mut core::option::Option<collections::string::String>`, found `core::option::Option<_>` (expected &-ptr, found enum `core::option::Option`) [E0308] <anon>:2 opt = None ^~~~ <anon>:2:11: 2:15 help: see the detailed explanation for E0308 error: aborting due to previous error 

It'd be great if this had a hint:

 Did you mean `*opt = None` 

Someone on IRC just ran into this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions