Closed
Description
Code
#[derive(PartialEq)]
struct Opaque(i32);
impl Eq for Opaque {}
const FOO: &&Opaque = &&Opaque(42);
fn main() {
match FOO {
FOO => {},
Opaque(_) => {}
}
}
This ICEs on stable and nightly. Interestingly, if the type derives Eq
this doesn't fail on nightly anymore, but still on stable. The change surely has something to do with the recent change in expansion of constant patterns (#70743).
Note also that this doesn't ICE with 0 or 1 references.
From the error, this is due to an invariant being broken in thir/pattern/_match.rs
. This is likely to be due do specialize_one_pattern
returning the wrong number of fields after specialization. So it's the interaction of const_to_pat.rs
constant expansion and _match.rs
pattern specialization that does something weird. I'm currently baffled as to why this happens.
Error output
thread 'rustc' panicked at 'assertion failed: rows.iter().all(|r| r.len() == v.len())', compiler/rustc_mir_build/src/thir/pattern/_match.rs:2009:5
Backtrace
thread 'rustc' panicked at 'assertion failed: rows.iter().all(|r| r.len() == v.len())', compiler/rustc_mir_build/src/thir/pattern/_match.rs:2009:5
stack backtrace:
0: std::panicking::begin_panic
1: rustc_mir_build::thir::pattern::_match::is_useful
2: rustc_mir_build::thir::pattern::_match::is_useful_specialized
3: <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::try_fold
4: rustc_mir_build::thir::pattern::_match::is_useful
5: rustc_mir_build::thir::pattern::_match::is_useful_specialized
6: <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::try_fold
7: rustc_mir_build::thir::pattern::_match::is_useful
8: rustc_mir_build::thir::pattern::_match::is_useful_specialized
9: <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::try_fold
10: rustc_mir_build::thir::pattern::_match::is_useful
11: <rustc_mir_build::thir::pattern::check_match::MatchVisitor as rustc_hir::intravisit::Visitor>::visit_expr
12: <rustc_mir_build::thir::pattern::check_match::MatchVisitor as rustc_hir::intravisit::Visitor>::visit_expr
13: rustc_mir_build::thir::pattern::check_match::check_match
14: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::check_match>::compute
15: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
16: rustc_data_structures::stack::ensure_sufficient_stack
17: rustc_query_system::query::plumbing::get_query_impl
18: rustc_query_system::query::plumbing::ensure_query_impl
19: rustc_session::utils::<impl rustc_session::session::Session>::time
20: rustc_session::utils::<impl rustc_session::session::Session>::time
21: rustc_interface::passes::analysis
22: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
23: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
24: rustc_data_structures::stack::ensure_sufficient_stack
25: rustc_query_system::query::plumbing::get_query_impl
26: rustc_interface::passes::QueryContext::enter
27: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
28: rustc_span::with_source_map
29: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.