Skip to content

"consider removing the borrow" suggests to only remove & and not mut #85933

Closed
@m-ou-se

Description

@m-ou-se

In the following snippet, rustc suggests to remove just the & instead of removing the &mut, resulting in an invalid suggestion: mut format!("").

fn main() {
    let _: String = &mut format!("");
}
error[E0308]: mismatched types
 --> src/main.rs:2:21
  |
2 |     let _: String = &mut format!("");
  |            ------   ^^^^^^^^^^^^^^^^
  |            |        |
  |            |        expected struct `String`, found `&mut String`
  |            |        help: consider removing the borrow: `mut format!("")`
  |            expected due to this

Metadata

Metadata

Assignees

Labels

A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.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