Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
tomBoddaert opened this issue Jul 7, 2023 · 3 comments
Closed
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@tomBoddaert
Copy link

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

@tomBoddaert tomBoddaert added the C-bug Category: Clippy is not doing the correct thing label Jul 7, 2023
@tomBoddaert tomBoddaert changed the title Clippy panic: do not use \optimized_mir\ for constants: Static(Not) Clippy panic: do not use 'optimized_mir' for constants: Static(Not) Jul 7, 2023
@y21
Copy link
Member

y21 commented Jul 7, 2023

This might be a duplicate of #10535 ? Same ICE, both reproducers seem to follow the same pattern

@tomBoddaert
Copy link
Author

This might be a duplicate of #10535 ? Same ICE, both reproducers seem to follow the same pattern

Yep, sorry, it looks like it is! Thanks for the quick reply.

@y21
Copy link
Member

y21 commented Jul 25, 2023

Reproducer doesn't seem to ICE anymore. #11130 probably fixed this one as well

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

No branches or pull requests

2 participants