Skip to content
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

The NOOP_METHOD_CALL lint fails to run if a MIR error occurs #91536

Open
Tracked by #83099
Aaron1011 opened this issue Dec 4, 2021 · 0 comments
Open
Tracked by #83099

The NOOP_METHOD_CALL lint fails to run if a MIR error occurs #91536

Aaron1011 opened this issue Dec 4, 2021 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Aaron1011
Copy link
Member

The following code:

#![warn(noop_method_call)]

struct Board;

fn do_part1(boards: &Vec<Board>) {
    let boards = boards.clone();
    boards[0] = Board;
}

produces the following error:

error[E0596]: cannot borrow `*boards` as mutable, as it is behind a `&` reference
 --> src/lib.rs:7:5
  |
6 |     let boards = boards.clone();
  |         ------ help: consider changing this to be a mutable reference: `&mut Vec<Board>`
7 |     boards[0] = Board;
  |     ^^^^^^ `boards` is a `&` reference, so the data it refers to cannot be borrowed as mutable

For more information about this error, try `rustc --explain E0596`.

If we comment out boards[0] = Board;, then the noop_method_call lint will fire as expected. However, when that line is present, the lint never gets a chance to run, since the mutable borrow error occurs during MIR borrowchecking. Displaying the lint would help the user to resolve the problem, since the root cause is the fact that the .clone() call produces a &Vec<Board>, not a Vec<Board>.

Originally identified in #91532

@Aaron1011 Aaron1011 added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. labels Dec 4, 2021
@Noratrieb Noratrieb added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants