Skip to content

Compiler panics when comparing functions #91636

Closed
@CeleritasCelery

Description

@CeleritasCelery

Edit: see example in the first comment below for a reproduction without Miri.

I have created a minimal reproduction based on some more verbose code that was causing Miri to panic. Note this code does not panic when compiled to native code with rustc (though that doesn't mean there is no undefined behavior here).

Code

type BuiltIn = for<'a> fn(&str);

struct Function {
    inner: BuiltIn,
}

impl Function {
    fn new(subr: BuiltIn) -> Self {
        Self { inner: subr }
    }
}

fn dummy(_: &str) {}

fn main() {
    let func1 = Function::new(dummy);
    let func2 = Function::new(dummy);
    let inner: fn(&'static _) -> _ = func1.inner;
    if inner == func2.inner {
        println!("equal");
    } else {
        println!("not equal");
    }
}

Meta

rustc --version --verbose:

rustc 1.59.0-nightly (acbe4443c 2021-12-02)
binary: rustc
commit-hash: acbe4443cc4c9695c0b74a7b64b60333c990a400
commit-date: 2021-12-02
host: x86_64-unknown-linux-gnu
release: 1.59.0-nightly
LLVM version: 13.0.0

Error output

thread 'rustc' panicked at 'Unexpected types for BinOp: fn(&str) Eq for<'r> fn(&'r str)', /rustc/acbe4443cc4c9695c0b74a7b64b60333c990a400/compiler/rustc_const_eval/src/interpret/operator.rs:332:17

error: internal compiler error: unexpected panic

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

stack backtrace:
   0: rust_begin_unwind
             at /rustc/acbe4443cc4c9695c0b74a7b64b60333c990a400/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/acbe4443cc4c9695c0b74a7b64b60333c990a400/library/core/src/panicking.rs:107:14
   2: <rustc_const_eval::interpret::eval_context::InterpCx<miri::machine::Evaluator>>::overflowing_binary_op
   3: <rustc_const_eval::interpret::eval_context::InterpCx<miri::machine::Evaluator>>::binop_ignore_overflow
   4: <rustc_const_eval::interpret::eval_context::InterpCx<miri::machine::Evaluator>>::statement
   5: miri::eval::eval_entry
   6: <rustc_interface::passes::QueryContext>::enter::<<miri::MiriCompilerCalls as rustc_driver::Callbacks>::after_analysis::{closure#0}, ()>
   7: <miri::MiriCompilerCalls as rustc_driver::Callbacks>::after_analysis
   8: <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::ErrorReported>>
   9: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
  10: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions