Skip to content

ICE when trying to match on non-PartialEq slice. #61188

Closed
@matthewjasper

Description

@matthewjasper
Contributor

The following code will result in an ICE in codegen MIR construction:

struct B(i32);

const A: &[B] = &[];

fn main() {
    match &[][..] {
        A => (),
        _ => (),
    }
}

playground

Error and Backtrace
error: internal compiler error: src/librustc/traits/codegen/mod.rs:156: Encountered errors `[FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<B as std::cmp::PartialEq>)),depth=2),Unimplemented)]` resolving bounds after type-checking

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:570:9
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:

 0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:59
             at src/libstd/panicking.rs:197
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:211
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:478
   6: std::panicking::begin_panic
   7: rustc_errors::Handler::span_bug
   8: rustc::util::bug::opt_span_bug_fmt::{{closure}}
   9: rustc::ty::context::tls::with_opt::{{closure}}
  10: rustc::ty::context::tls::with_context_opt
  11: rustc::ty::context::tls::with_opt
  12: rustc::util::bug::opt_span_bug_fmt
  13: rustc::util::bug::span_bug_fmt
  14: rustc::traits::codegen::<impl rustc::infer::InferCtxt>::drain_fulfillment_cx_or_panic
  15: rustc::ty::context::GlobalCtxt::enter_local
  16: rustc::traits::codegen::codegen_fulfill_obligation
  17: rustc::ty::query::__query_compute::codegen_fulfill_obligation
  18: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::codegen_fulfill_obligation>::compute
  19: rustc::dep_graph::graph::DepGraph::with_task_impl
  20: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  21: rustc::ty::instance::Instance::resolve
  22: rustc_mir::lints::check
  23: rustc::ty::context::GlobalCtxt::enter_local
  24: rustc_mir::build::mir_build
  25: rustc_mir::transform::mir_built
  26: rustc::ty::query::__query_compute::mir_built
  27: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::mir_built>::compute
  28: rustc::dep_graph::graph::DepGraph::with_task_impl
  29: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  30: rustc_mir::transform::check_unsafety::unsafety_check_result
  31: rustc::ty::query::__query_compute::unsafety_check_result
  32: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::unsafety_check_result>::compute
  33: rustc::dep_graph::graph::DepGraph::with_task_impl
  34: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  35: rustc_mir::transform::mir_const
  36: rustc::ty::query::__query_compute::mir_const
  37: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::mir_const>::compute
  38: rustc::dep_graph::graph::DepGraph::with_task_impl
  39: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  40: rustc_mir::transform::mir_validated
  41: rustc::ty::query::__query_compute::mir_validated
  42: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::mir_validated>::compute
  43: rustc::dep_graph::graph::DepGraph::with_task_impl
  44: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  45: rustc_mir::borrow_check::mir_borrowck
  46: rustc::ty::query::__query_compute::mir_borrowck
  47: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::mir_borrowck>::compute
  48: rustc::dep_graph::graph::DepGraph::with_task_impl
  49: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  50: rustc::ty::<impl rustc::ty::context::TyCtxt>::par_body_owners
  51: rustc::util::common::time
  52: rustc_interface::passes::analysis
  53: rustc::ty::query::__query_compute::analysis
  54: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::analysis>::compute
  55: rustc::dep_graph::graph::DepGraph::with_task_impl
  56: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  57: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  58: rustc_interface::passes::create_global_ctxt::{{closure}}
  59: rustc_interface::interface::run_compiler_in_existing_thread_pool
  60: std::thread::local::LocalKey<T>::with
  61: scoped_tls::ScopedKey<T>::set
  62: syntax::with_globals
query stack during panic:
#0 [codegen_fulfill_obligation] checking if `std::cmp::PartialEq` fulfills its obligations
#1 [mir_built] processing `main`
#2 [unsafety_check_result] processing `main`
#3 [mir_const] processing `main`
#4 [mir_validated] processing `main`
#5 [mir_borrowck] processing `main`
#6 [analysis] running analysis passes on this crate
end of query stack

Activity

added
I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
on May 25, 2019
added
C-bugCategory: This is a bug.
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on May 25, 2019
estebank

estebank commented on May 25, 2019

@estebank
Contributor
added
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html
on Jun 6, 2019
pnkfelix

pnkfelix commented on Jun 6, 2019

@pnkfelix
Member

As implied by @estebank above, this seems very likely to be a duplicate (or at least strongly related to) #53708 ...

Update: Not duplicate. Further investigation of #53708 shows that it is no longer an ICE, but "merely" an exhaustiveness checker bug. This bug, #61188, remains an ICE today.

pnkfelix

pnkfelix commented on Jun 6, 2019

@pnkfelix
Member

Ah ha!

If you add #[derive(PartialEq, Eq)] to the struct B(i32) in the example above, then the code compiles successfully.

Which may be something a user might infer from the message ...

Encountered errors [FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<B as std::cmp::PartialEq>)),depth=2),Unimplemented)]

... but probably not 🤣

pnkfelix

pnkfelix commented on Jun 6, 2019

@pnkfelix
Member

triage: P-high; removing nomination. I want to know why we are not catching the failure to fulfill B: PartialEq earlier in the compilation. Is this perhaps a const-eval issue, based on the stack trace? (or a mir-borrowck one? I suppose the query-system is just making that appear on the stack, though it is not necessarily the root cause?)

eddyb

eddyb commented on Jun 6, 2019

@eddyb
Member

I suspect rustc_typeck is not enforcing it, and MIR borrowck, as I found recently, doesn't produce user errors from trait matching, but rather expects it to succeed, and only uses it to get lifetime obligations.

EDIT: I should've read more carefully, looks like Instance::resolve is being used by rustc_mir::build without rustc_typeck having checked that Eq is implemented for that type.

pnkfelix

pnkfelix commented on Jun 6, 2019

@pnkfelix
Member

assigning to self with intent to try to mentor.

self-assigned this
on Jun 6, 2019
added
E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
on Jun 6, 2019

29 remaining items

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

Metadata

Metadata

Assignees

Labels

A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-highHigh priorityT-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

    Participants

    @eddyb@pnkfelix@estebank@jonas-schievink@matthewjasper

    Issue actions

      ICE when trying to match on non-PartialEq slice. · Issue #61188 · rust-lang/rust