Skip to content

large_assignments: Unactionable diagnostics with -Zinline-mir #121672

Description

@Enselic

Tracking issue #83518.

Doing cargo build --release will activate -Zinline-mir under the hood (through -Copt-level=3). But it makes large_assignments diagnostics unhelpful, because it can make diagnostics point to library code that the user can't change.

How to reproduce

src/main.rs

#![feature(large_assignments)]
#![deny(large_assignments)]
#![move_size_limit = "1000"]

pub fn main() {
    let data = [10u8; 9999];
    let cell = std::cell::UnsafeCell::new(data);
    std::hint::black_box(cell);
}
# One of:
cargo +nightly build --release
cargo +nightly rustc -- -Zmir-opt-level=1 -Zinline-mir

Actual

   Compiling minimal v0.1.0 (/home/martin/src/bin)
error: moving 9999 bytes
    --> /home/martin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/cell.rs:2054:9
     |
2054 |         UnsafeCell { value }
     |         ^^^^^^^^^^^^^^^^^^^^ value moved from here
     |

Expected

   Compiling minimal v0.1.0 (/home/martin/src/bin)
error: moving 9999 bytes
 --> src/main.rs:7:43
  |
7 |     let cell = std::cell::UnsafeCell::new(data);
  |                                           ^^^^ value moved from here
  |

Remarks

The expected diagnostics is given with these commands. Note how -Zinline-mir is deactivated in both cases:

# One of:
cargo +nightly build
cargo +nightly rustc -- -Zmir-opt-level=1

The above test case is ui-testified here.

CC E-mentor @oli-obk who maybe have an idea on how to fix this? (I currently don't.)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-mir-opt-inliningArea: MIR inliningC-bugCategory: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.L-large_assignmentsLint: large_assignmentsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions