Skip to content

Fix suggestion on DerefMut #71389

Open
Open
@pickfire

Description

@pickfire

I tried this code:

fn t(n: &mut i32) {
    n = "42".parse().unwrap();
}

I expected to see this happen: Suggestion of *n = ..., the correct code would be

fn t(n: &mut i32) {
    *n = "42".parse().unwrap();
}

Instead, this happened: It did not look at mutable deref value and directly show the suggestion

error[E0277]: the trait bound `&mut i32: std::str::FromStr` is not satisfied
 --> src/lib.rs:2:14
  |
2 |     n = "42".parse().unwrap();
  |              ^^^^^ the trait `std::str::FromStr` is not implemented for `&mut i32`
  |
  = help: the following implementations were found:
            <i32 as std::str::FromStr>

Not sure why but I miss * quite often. Link to playground https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=011e594936166764d011c581d7db107e

Meta

rustc --version --verbose:

1.42.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions