Skip to content

consider changing this to be mutable suggested for a binding in a ref pattern #114896

Closed
@Alexendoo

Description

@Alexendoo

Code

fn x(a: &char) {
    let &b = a;
    b.make_ascii_uppercase();
}

Current output

error[E0596]: cannot borrow `b` as mutable, as it is not declared as mutable
 --> src/lib.rs:3:5
  |
3 |     b.make_ascii_uppercase();
  |     ^ cannot borrow as mutable
  |
help: consider changing this to be mutable
  |
2 |     let &mut b = a;
  |          +++

Desired output

No response

Rationale and extra context

Applying the suggestion gives

error[[E0308]](https://doc.rust-lang.org/nightly/error_codes/E0308.html): mismatched types
 --> src/lib.rs:2:9
  |
2 |     let &mut b = a;
  |         ^^^^^^   - this expression has type `&char`
  |         |
  |         types differ in mutability
  |         help: to declare a mutable variable use: `mut b`
  |
  = note:      expected reference `&char`
          found mutable reference `&mut _`

Other cases

No response

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-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