rust-lang / rust-lang/rust-clippy

Linting shouldn't be run on optimized MIR

Open
#6,080 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug E-hard T-MIR
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

For example, const-checking needs to run before optimizations, otherwise it might miss some invalid operations that get optimized away. Specifically, it should run on the result of the mir_const query, but currently it uses optimized_mir. This is because the result of the mir_const query is "stolen" instead of cloned, so it no longer exists when clippy runs. clippy tries to work around this by setting mir-opt-level=0, but this doesn't disable every optimization pass.

Until this is fixed, missing_const_for_fn will have false positives and/or ICE (due to some assertions about the state of the MIR at the point const-checking is run).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how clippy obtains MIR for the missing_const_for_fn lint, comparing the mir_const and optimized_mir queries. Investigate why mir_const is stolen before clippy runs and how mir-opt-level=0 affects the optimization passes. Done means linting uses the pre-optimization MIR without false positives or ICEs from const-checking assertions.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.