Skip to content

Clippy panic: do not use 'optimized_mir' for constants: Static(Not) #11120

Closed
@tomBoddaert

Description

@tomBoddaert

Summary

Clippy panics when I try to lint the 'reproducer' code.

This also happens on the rust playground (the code).

Tools > Clippy

Reproducer

I tried this code:

#![allow(dead_code)]

use std::marker::PhantomData;

struct Journey<L, T: AsRef<L>> {
    start: T,
    phantom: PhantomData<L>,
}

impl<L, T: AsRef<L>> Journey<L, T> {
    const fn new(start: T) -> Self {
        Self {
            start,
            phantom: PhantomData,
        }
    }
}

struct Node {}

impl AsRef<Node> for &'static Node {
    fn as_ref(&self) -> &Node {
        self
    }
}

static NODE_A: Node = Node {};

static JOURNEY: Journey<Node, &'static Node> = Journey::new(&NODE_A);

fn main() {}

I expected to see this happen:

Clippy to lint my code.

Instead, this happened:

Clippy panics with the message below.

thread 'rustc' panicked at 'do not use `optimized_mir` for constants: Static(Not)', compiler/rustc_mir_transform/src/lib.rs:617:24
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy/issues/new

note: Clippy version: clippy 0.1.70 (90c5418 2023-05-31)

query stack during panic:
#0 [optimized_mir] optimizing MIR for `JOURNEY`
#1 [analysis] running analysis passes on this crate
end of query stack

Version

rustc 1.70.0 (90c541806 2023-05-31)
binary: rustc
commit-hash: 90c541806f23a127002de5b4038be731ba1458ca
commit-date: 2023-05-31
host: x86_64-unknown-linux-gnu
release: 1.70.0
LLVM version: 16.0.2

Additional Labels

No response

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