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 when matching with an opaque constant pattern #78071

Closed
Nadrieril opened this issue Oct 18, 2020 · 4 comments · Fixed by #78072
Closed

ICE when matching with an opaque constant pattern #78071

Nadrieril opened this issue Oct 18, 2020 · 4 comments · Fixed by #78072
Assignees
Labels
A-exhaustiveness-checking Relating to exhaustiveness / usefulness checking of patterns C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Nadrieril
Copy link
Member

Nadrieril commented Oct 18, 2020

Code

playground

#[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.

@Nadrieril Nadrieril added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 18, 2020
@Nadrieril
Copy link
Member Author

@rustbot modify labels: +A-exhaustiveness-checking

@rustbot rustbot added the A-exhaustiveness-checking Relating to exhaustiveness / usefulness checking of patterns label Oct 18, 2020
@Nadrieril
Copy link
Member Author

I'll self-assign while I investigate but I don't know if I can fix it alone yet.
@rustbot claim

@scottmcm
Copy link
Member

This was an error back in 1.25,

error[E0658]: non-reference pattern used to match a reference (see issue #42640)
  --> <source>:11:9
   |
11 |         Opaque(_) => {}
   |         ^^^^^^^^^ help: consider using a reference: `&Opaque(_)`

But has been an ICE since as fast back as 1.26.

@Nadrieril
Copy link
Member Author

Thanks for the investigation!

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Oct 22, 2020
…, r=varkor

Cleanup constant matching in exhaustiveness checking

This supercedes rust-lang#77390. I made the `Opaque` constructor work.
I have opened two issues rust-lang#78071 and rust-lang#78057 from the discussion we had on the previous PR. They are not regressions nor directly related to the current PR so I thought we'd deal with them separately.

I left a FIXME somewhere because I didn't know how to compare string constants for equality. There might even be some unicode things that need to happen there. In the meantime I preserved previous behavior.

EDIT: I accidentally fixed rust-lang#78071
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Oct 22, 2020
…, r=varkor

Cleanup constant matching in exhaustiveness checking

This supercedes rust-lang#77390. I made the `Opaque` constructor work.
I have opened two issues rust-lang#78071 and rust-lang#78057 from the discussion we had on the previous PR. They are not regressions nor directly related to the current PR so I thought we'd deal with them separately.

I left a FIXME somewhere because I didn't know how to compare string constants for equality. There might even be some unicode things that need to happen there. In the meantime I preserved previous behavior.

EDIT: I accidentally fixed rust-lang#78071
@bors bors closed this as completed in 5bfd3e7 Oct 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-exhaustiveness-checking Relating to exhaustiveness / usefulness checking of patterns C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants