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

ICE on let else #9578

Closed
Emilgardis opened this issue Oct 2, 2022 · 6 comments
Closed

ICE on let else #9578

Emilgardis opened this issue Oct 2, 2022 · 6 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@Emilgardis
Copy link

Summary

❯ cargo clippy    
    Checking clippy_bug v0.1.0 (/Users/emil/workspace/dev_space/clippy_bug)
error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: broken MIR in Item(WithOptConstParam { did: DefId(0:15 ~ clippy_bug[8b5c]::{impl#1}::wait::{closure#0}), const_param_did: None }) (after pass PhaseChange-Runtime(Optimized)) at bb60[0]:
                                use of local _22, which has no storage here
  --> src/lib.rs:89:14
   |
89 |             };
   |              ^
   |
   = note: delayed at compiler/rustc_const_eval/src/transform/validate.rs:128:36

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1536:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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.65 (57f097ea 2022-10-01)

query stack during panic:
end of query stack
error: could not compile `clippy_bug`
# Cargo.toml
[package]
name = "clippy_bug"
version = "0.1.0"
edition = "2021"

[dependencies]
thiserror = "1.0.37"
tokio = { version = "1.21.2", features = ["sync"] }
#![allow(unreachable_code, dead_code)]
#![allow(clippy::diverging_sub_expression)]
#[derive(Debug, Clone, PartialEq, Eq)]
struct TimerIdentifier(String);

type DirectSendMessage = Box<dyn std::any::Any + Send + Sync>;

type DirectRecv = tokio::sync::oneshot::Receiver<DirectSendMessage>;
type DirectRecvMulti = tokio::sync::mpsc::UnboundedReceiver<DirectSendMessage>;

#[derive(Debug)]
enum DirectReceiver {
    All(DirectRecvMulti, Option<DirectSendMessage>),
    Module(Option<DirectRecv>, Option<DirectSendMessage>),
    Done,
}

impl DirectReceiver {
    // Receives a value from the channel, returns `None` if the downcast failed.
    async fn receive(&mut self) -> Result<&mut Self, DirectReceiverError> {
        match self {
            DirectReceiver::All(channel, ref mut received) => match channel.recv().await {
                Some(recv) => {
                    *received = Some(recv);
                }
                None => {
                    *self = DirectReceiver::Done;
                    return todo!();
                }
            },
            DirectReceiver::Module(ref mut chan @ Some(_), ref mut received) => {
                let chan = chan.take().expect("this should never hit");
                *received = Some(chan.await?);
            }
            _ => return todo!(),
        };
        Ok(self)
    }

    fn downcast<T: Send + Sync + 'static>(&mut self) -> Result<Option<T>, DirectReceiverError> {
        match self {
            DirectReceiver::All(_, ref mut received) => {
                let Some(recv) = received.take() else {
                    return Ok(None)
                };
                match recv.downcast() {
                    Ok(recv) => Ok(Some(*recv)),
                    Err(recv) => {
                        *received = Some(recv);
                        Ok(None)
                    }
                }
            }
            DirectReceiver::Module(_, ref mut received) => {
                let Some(recv) = received.take() else {
                    return Ok(None)
                };
                match recv.downcast() {
                    Ok(recv) => Ok(Some(*recv)),
                    Err(recv) => {
                        *received = Some(recv);
                        Ok(None)
                    }
                }
            }
            DirectReceiver::Done => todo!(),
        }
    }
}

#[derive(Debug, thiserror::Error)]
enum DirectReceiverError {
    #[error("oneshot failed")]
    Oneshot(#[from] tokio::sync::oneshot::error::RecvError),
}

#[derive(Debug)]
struct TimerTracker {
    resp: Option<TimerAction>,
    recv: Option<DirectReceiver>,
    token: TimerIdentifier,
}

impl TimerTracker {
    async fn wait(&mut self) -> Result<(), DirectReceiverError> {
        if let Some(mut recv) = self.recv.take() {
            let Some(resp) = recv.receive().await?.downcast()? else {
                panic!("Unexpected response type");
            };
            self.resp = Some(resp);
        }
        Ok(())
    }
}

impl PartialEq<TimerIdentifier> for TimerTracker {
    fn eq(&self, other: &TimerIdentifier) -> bool {
        &self.token == other
    }
}

impl PartialEq<TimerTracker> for TimerIdentifier {
    fn eq(&self, other: &TimerTracker) -> bool {
        self == &other.token
    }
}

/// Timer action done.
#[derive(Clone)]
enum TimerAction {
    Inserted(TimerIdentifier, Vec<u8>),
}

impl std::fmt::Debug for TimerAction {
    fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        todo!()
    }
}

Version

rustc 1.66.0-nightly (57f097ea2 2022-10-01)
binary: rustc
commit-hash: 57f097ea25f2c05f424fc9b9dc50dbd6d399845c
commit-date: 2022-10-01
host: aarch64-apple-darwin
release: 1.66.0-nightly
LLVM version: 15.0.2

Error output

Backtrace

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1536:13
stack backtrace:
 0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
 1: std::panic::panic_any::<rustc_errors::ExplicitBug>
 2: <rustc_errors::HandlerInner>::flush_delayed::<alloc::vec::Vec<rustc_errors::diagnostic::Diagnostic>, &str>
 3: <rustc_errors::Handler>::flush_delayed
 4: <rustc_interface::passes::QueryContext>::enter::<<rustc_interface::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core::result::Result<alloc::boxed::Box<dyn core::any::Any>, rustc_errors::ErrorGuaranteed>>
 5: <rustc_interface::queries::Queries>::ongoing_codegen
 6: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorGuaranteed>>
 7: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
 8: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>
 9: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>

@Emilgardis Emilgardis added C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️ labels Oct 2, 2022
@Emilgardis
Copy link
Author

this could definitely do with more minimization

@Jarcho
Copy link
Contributor

Jarcho commented Oct 2, 2022

Likely a rustc bug. There have been a few MIR validation issues with let else.

@Emilgardis
Copy link
Author

how could we confirm this, are there passes done in clippy not enabled in a normal build/check?

@matthiaskrgr
Copy link
Member

This could be rust-lang/rust#102317

@Emilgardis
Copy link
Author

that one is clippy only as well, this should probably be closed in favor of that one, same backtrace for this repro and rust-lang/rust#102317

@Emilgardis Emilgardis closed this as not planned Won't fix, can't repro, duplicate, stale Oct 2, 2022
@Emilgardis
Copy link
Author

rust-lang/rust@c97d02c has solved this, and that change is available on nightly-2022-10-05

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

3 participants