Skip to content

Fix suggestion on DerefMut #71388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pickfire opened this issue Apr 21, 2020 · 2 comments
Closed

Fix suggestion on DerefMut #71388

pickfire opened this issue Apr 21, 2020 · 2 comments
Labels
C-bug Category: This is a bug.

Comments

@pickfire
Copy link
Contributor

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.

Meta

rustc --version --verbose:

1.42.0
@pickfire pickfire added the C-bug Category: This is a bug. label Apr 21, 2020
@cuviper
Copy link
Member

cuviper commented Apr 21, 2020

Closing as a duplicate -- #71389 has an updated edit and more labels applied.

@cuviper cuviper closed this as completed Apr 21, 2020
@pickfire
Copy link
Contributor Author

Oh weird, I didn't know github created the issue twice after I see the unicorn.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants