Skip to content

Wrong code example for the "ref on an entire let pattern is discouraged" lint #1882

Closed
@stanislav-tkach

Description

@stanislav-tkach

Clippy gives confusing help-message for the following code:

let mut v = vec![1i8, 2, 3];
for ref mut val in &mut v {
    ...
}
warning: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead
 --> src/main.rs:3:9
  |
3 |     for ref mut _val in &mut v {
  |         ^^^^^^^^^^^^
  |
  = note: #[warn(toplevel_ref_arg)] on by default
  = help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#toplevel_ref_arg
help: try
  |     let _val = &mut for ref mut _val in &mut v {
  |     };

ref mut can simply be removed, let isn't needed here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions