Skip to content

ICE: pattern has unexpected type #122809

Closed

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

struct S(E::V, ())

impl S {
    fn check() {
        let a;
        (Self, a) = (S, ());
    }
}

original:

// check-pass

struct S(E::V, ())

enum E {
    V,
}

type A = E;

fn main() {
    let mut a;

    (S, a) = (, ());

    {
        let _val;
        let x;
        (S, a) = (S, ());
        ((a, .., b), .., (..)) = (DropRecorder(3), DropRecorder(4));
        (x, _) = (DropRecorder(3), DropRecorder(4));
        drop(DropRecorder(5));
    }

    (<E>::V, a) = (E::V, ());
    (Self, a) = (S, ());
}

impl S {
    fn check() {
        let a;
        (Self, a) = (S, ());
    }
}

impl E {
    fn check() {
        let a;
        (Self::V, a) = (E::V, ());
    }
}

Version information

rustc 1.79.0-nightly (e3df96cfd 2024-03-20)
binary: rustc
commit-hash: e3df96cfda905301fc8514e000f942222c1ab6ad
commit-date: 2024-03-20
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.2

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error: expected `;`, found keyword `impl`
  --> /tmp/icemaker_global_tempdir.wExQMUHWhTmO/rustc_testrunner_tmpdir_reporting.85MgQDvvjOZT/mvce.rs:3:19
   |
3  | struct S(E::V, ())
   |                   ^ help: add `;` here
...
11 | impl S {
   | ---- unexpected token

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.wExQMUHWhTmO/rustc_testrunner_tmpdir_reporting.85MgQDvvjOZT/mvce.rs:16:2
   |
16 | }
   |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.wExQMUHWhTmO/rustc_testrunner_tmpdir_reporting.85MgQDvvjOZT/mvce.rs`

error: internal compiler error: compiler/rustc_pattern_analysis/src/rustc.rs:512:26: pattern has unexpected type: pat: Pat { ty: FnDef(DefId(0:4 ~ mvce[320f]::S::{constructor#0}), []), span: /tmp/icemaker_global_tempdir.wExQMUHWhTmO/rustc_testrunner_tmpdir_reporting.85MgQDvvjOZT/mvce.rs:14:10: 14:14 (#0), kind: Leaf { subpatterns: [] } }, ty: FnDef(DefId(0:4 ~ mvce[320f]::S::{constructor#0}), [])

thread 'rustc' panicked at compiler/rustc_pattern_analysis/src/rustc.rs:512:26:
Box<dyn Any>
stack backtrace:
   0:     0x75bc6b51efa5 - std::backtrace_rs::backtrace::libunwind::trace::h54c486c232076428
                               at /rustc/e3df96cfda905301fc8514e000f942222c1ab6ad/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x75bc6b51efa5 - std::backtrace_rs::backtrace::trace_unsynchronized::h2fd5afdd0a8da31d
                               at /rustc/e3df96cfda905301fc8514e000f942222c1ab6ad/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x75bc6b51efa5 - std::sys_common::backtrace::_print_fmt::hadc110e46c54459f
                               at /rustc/e3df96cfda905301fc8514e000f942222c1ab6ad/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x75bc6b51efa5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h0b47cfd0f065e379
                               at /rustc/e3df96cfda905301fc8514e000f942222c1ab6ad/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x75bc6b56ffeb - core::fmt::rt::Argument::fmt::ha1ecc9131b49231f
                               at /rustc/e3df96cfda905301fc8514e000f942222c1ab6ad/library/core/src/fmt/rt.rs:142:9
   5:     0x75bc6b56ffeb - core::fmt::write::h63c1ef73f6590a52
                               at /rustc/e3df96cfda905301fc8514e000f942222c1ab6ad/library/core/src/fmt/mod.rs:1153:17
   6:     0x75bc6b513d3f - std::io::Write::write_fmt::hb36944f35ec2c84f
                               at /rustc/e3df96cfda905301fc8514e000f942222c1ab6ad/library/std/src/io/mod.rs:1843:15
   7:     0x75bc6b51ed7e - std::sys_common::backtrace::_print::hbb8a46438258797e
                               at /rustc/e3df96cfda905301fc8514e000f942222c1ab6ad/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x75bc6b51ed7e - std::sys_common::backtrace::print::ha1e05e25e8003bf0
                               at /rustc/e3df96cfda905301fc8514e000f942222c1ab6ad/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x75bc6b5219f9 - std::panicking::default_hook::{{closure}}::h697f539fd1011816
  10:     0x75bc6b521763 - std::panicking::default_hook::h4854131cd281e19c
                               at /rustc/e3df96cfda905301fc8514e000f942222c1ab6ad/library/std/src/panicking.rs:292:9
  11:     0x75bc67fc49bf - std[974069e135d83a45]::panicking::update_hook::<alloc[d715377074842bff]::boxed::Box<rustc_driver_impl[54c4e59e21ada34c]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x75bc6b522150 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::he54c797c7af387e7
                               at /rustc/e3df96cfda905301fc8514e000f942222c1ab6ad/library/alloc/src/boxed.rs:2029:9
  13:     0x75bc6b522150 - std::panicking::rust_panic_with_hook::ha23aac69efb218da
                               at /rustc/e3df96cfda905301fc8514e000f942222c1ab6ad/library/std/src/panicking.rs:783:13
  14:     0x75bc67ff1004 - std[974069e135d83a45]::panicking::begin_panic::<rustc_errors[b53ee156db0e18b6]::ExplicitBug>::{closure#0}
  15:     0x75bc67fedd76 - std[974069e135d83a45]::sys_common::backtrace::__rust_end_short_backtrace::<std[974069e135d83a45]::panicking::begin_panic<rustc_errors[b53ee156db0e18b6]::ExplicitBug>::{closure#0}, !>
  16:     0x75bc67feda56 - std[974069e135d83a45]::panicking::begin_panic::<rustc_errors[b53ee156db0e18b6]::ExplicitBug>
  17:     0x75bc67ffa2c1 - <rustc_errors[b53ee156db0e18b6]::diagnostic::BugAbort as rustc_errors[b53ee156db0e18b6]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x75bc6848ab3c - rustc_middle[aee9213921a7dfb8]::util::bug::opt_span_bug_fmt::<rustc_span[7201b210a46cafa6]::span_encoding::Span>::{closure#0}
  19:     0x75bc6846e54a - rustc_middle[aee9213921a7dfb8]::ty::context::tls::with_opt::<rustc_middle[aee9213921a7dfb8]::util::bug::opt_span_bug_fmt<rustc_span[7201b210a46cafa6]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  20:     0x75bc6846e3cb - rustc_middle[aee9213921a7dfb8]::ty::context::tls::with_context_opt::<rustc_middle[aee9213921a7dfb8]::ty::context::tls::with_opt<rustc_middle[aee9213921a7dfb8]::util::bug::opt_span_bug_fmt<rustc_span[7201b210a46cafa6]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  21:     0x75bc6627cb80 - rustc_middle[aee9213921a7dfb8]::util::bug::bug_fmt
  22:     0x75bc66a7f7c2 - <rustc_pattern_analysis[b36109219bcc4ec4]::rustc::RustcPatCtxt>::lower_pat
  23:     0x75bc66a7ec67 - <rustc_pattern_analysis[b36109219bcc4ec4]::rustc::RustcPatCtxt>::lower_pat
  24:     0x75bc66a73aa8 - <rustc_mir_build[79707f519d180325]::thir::pattern::check_match::MatchVisitor>::check_binding_is_irrefutable
  25:     0x75bc66a7b169 - <rustc_mir_build[79707f519d180325]::thir::pattern::check_match::MatchVisitor as rustc_middle[aee9213921a7dfb8]::thir::visit::Visitor>::visit_expr
  26:     0x75bc66a79eed - <rustc_mir_build[79707f519d180325]::thir::pattern::check_match::MatchVisitor as rustc_middle[aee9213921a7dfb8]::thir::visit::Visitor>::visit_expr
  27:     0x75bc66a7b036 - <rustc_mir_build[79707f519d180325]::thir::pattern::check_match::MatchVisitor as rustc_middle[aee9213921a7dfb8]::thir::visit::Visitor>::visit_expr
  28:     0x75bc66a79eed - <rustc_mir_build[79707f519d180325]::thir::pattern::check_match::MatchVisitor as rustc_middle[aee9213921a7dfb8]::thir::visit::Visitor>::visit_expr
  29:     0x75bc699eb5c7 - rustc_mir_build[79707f519d180325]::thir::pattern::check_match::check_match
  30:     0x75bc699eb1b3 - rustc_query_impl[fd1f40c470c08f9a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[fd1f40c470c08f9a]::query_impl::check_match::dynamic_query::{closure#2}::{closure#0}, rustc_middle[aee9213921a7dfb8]::query::erase::Erased<[u8; 1usize]>>
  31:     0x75bc698823be - rustc_query_system[1734afcd9a589e0d]::query::plumbing::try_execute_query::<rustc_query_impl[fd1f40c470c08f9a]::DynamicConfig<rustc_query_system[1734afcd9a589e0d]::query::caches::VecCache<rustc_span[7201b210a46cafa6]::def_id::LocalDefId, rustc_middle[aee9213921a7dfb8]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[fd1f40c470c08f9a]::plumbing::QueryCtxt, false>
  32:     0x75bc69882055 - rustc_query_impl[fd1f40c470c08f9a]::query_impl::check_match::get_query_non_incr::__rust_end_short_backtrace
  33:     0x75bc6964a3bf - rustc_mir_build[79707f519d180325]::build::mir_built
  34:     0x75bc6964a295 - rustc_query_impl[fd1f40c470c08f9a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[fd1f40c470c08f9a]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[aee9213921a7dfb8]::query::erase::Erased<[u8; 8usize]>>
  35:     0x75bc693ad32e - rustc_query_system[1734afcd9a589e0d]::query::plumbing::try_execute_query::<rustc_query_impl[fd1f40c470c08f9a]::DynamicConfig<rustc_query_system[1734afcd9a589e0d]::query::caches::VecCache<rustc_span[7201b210a46cafa6]::def_id::LocalDefId, rustc_middle[aee9213921a7dfb8]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[fd1f40c470c08f9a]::plumbing::QueryCtxt, false>
  36:     0x75bc693acf0c - rustc_query_impl[fd1f40c470c08f9a]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  37:     0x75bc698a498f - rustc_mir_build[79707f519d180325]::check_unsafety::check_unsafety
  38:     0x75bc698a46ed - rustc_query_impl[fd1f40c470c08f9a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[fd1f40c470c08f9a]::query_impl::check_unsafety::dynamic_query::{closure#2}::{closure#0}, rustc_middle[aee9213921a7dfb8]::query::erase::Erased<[u8; 0usize]>>
  39:     0x75bc696a73c3 - rustc_query_system[1734afcd9a589e0d]::query::plumbing::try_execute_query::<rustc_query_impl[fd1f40c470c08f9a]::DynamicConfig<rustc_query_system[1734afcd9a589e0d]::query::caches::VecCache<rustc_span[7201b210a46cafa6]::def_id::LocalDefId, rustc_middle[aee9213921a7dfb8]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[fd1f40c470c08f9a]::plumbing::QueryCtxt, false>
  40:     0x75bc696a6fff - rustc_query_impl[fd1f40c470c08f9a]::query_impl::check_unsafety::get_query_non_incr::__rust_end_short_backtrace
  41:     0x75bc696a337c - rustc_interface[1d5664f7c2fe05ea]::passes::analysis
  42:     0x75bc696a2499 - rustc_query_impl[fd1f40c470c08f9a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[fd1f40c470c08f9a]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[aee9213921a7dfb8]::query::erase::Erased<[u8; 1usize]>>
  43:     0x75bc6a00faa5 - rustc_query_system[1734afcd9a589e0d]::query::plumbing::try_execute_query::<rustc_query_impl[fd1f40c470c08f9a]::DynamicConfig<rustc_query_system[1734afcd9a589e0d]::query::caches::SingleCache<rustc_middle[aee9213921a7dfb8]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[fd1f40c470c08f9a]::plumbing::QueryCtxt, false>
  44:     0x75bc6a00f809 - rustc_query_impl[fd1f40c470c08f9a]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  45:     0x75bc69e88744 - rustc_interface[1d5664f7c2fe05ea]::interface::run_compiler::<core[6de4c49d8113e7da]::result::Result<(), rustc_span[7201b210a46cafa6]::ErrorGuaranteed>, rustc_driver_impl[54c4e59e21ada34c]::run_compiler::{closure#0}>::{closure#0}
  46:     0x75bc69f85b05 - std[974069e135d83a45]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[1d5664f7c2fe05ea]::util::run_in_thread_with_globals<rustc_interface[1d5664f7c2fe05ea]::util::run_in_thread_pool_with_globals<rustc_interface[1d5664f7c2fe05ea]::interface::run_compiler<core[6de4c49d8113e7da]::result::Result<(), rustc_span[7201b210a46cafa6]::ErrorGuaranteed>, rustc_driver_impl[54c4e59e21ada34c]::run_compiler::{closure#0}>::{closure#0}, core[6de4c49d8113e7da]::result::Result<(), rustc_span[7201b210a46cafa6]::ErrorGuaranteed>>::{closure#0}, core[6de4c49d8113e7da]::result::Result<(), rustc_span[7201b210a46cafa6]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[6de4c49d8113e7da]::result::Result<(), rustc_span[7201b210a46cafa6]::ErrorGuaranteed>>
  47:     0x75bc69f85932 - <<std[974069e135d83a45]::thread::Builder>::spawn_unchecked_<rustc_interface[1d5664f7c2fe05ea]::util::run_in_thread_with_globals<rustc_interface[1d5664f7c2fe05ea]::util::run_in_thread_pool_with_globals<rustc_interface[1d5664f7c2fe05ea]::interface::run_compiler<core[6de4c49d8113e7da]::result::Result<(), rustc_span[7201b210a46cafa6]::ErrorGuaranteed>, rustc_driver_impl[54c4e59e21ada34c]::run_compiler::{closure#0}>::{closure#0}, core[6de4c49d8113e7da]::result::Result<(), rustc_span[7201b210a46cafa6]::ErrorGuaranteed>>::{closure#0}, core[6de4c49d8113e7da]::result::Result<(), rustc_span[7201b210a46cafa6]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[6de4c49d8113e7da]::result::Result<(), rustc_span[7201b210a46cafa6]::ErrorGuaranteed>>::{closure#1} as core[6de4c49d8113e7da]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  48:     0x75bc6b52b919 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h692cb708ffa8bea9
                               at /rustc/e3df96cfda905301fc8514e000f942222c1ab6ad/library/alloc/src/boxed.rs:2015:9
  49:     0x75bc6b52b919 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha47fe4ab040f49b9
                               at /rustc/e3df96cfda905301fc8514e000f942222c1ab6ad/library/alloc/src/boxed.rs:2015:9
  50:     0x75bc6b52b919 - std::sys::pal::unix::thread::Thread::new::thread_start::haebdb8fbb64ea56b
                               at /rustc/e3df96cfda905301fc8514e000f942222c1ab6ad/library/std/src/sys/pal/unix/thread.rs:108:17
  51:     0x75bc64ea955a - <unknown>
  52:     0x75bc64f26a3c - <unknown>
  53:                0x0 - <unknown>

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.79.0-nightly (e3df96cfd 2024-03-20) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [check_match] match-checking `<impl at /tmp/icemaker_global_tempdir.wExQMUHWhTmO/rustc_testrunner_tmpdir_reporting.85MgQDvvjOZT/mvce.rs:11:1: 11:7>::check`
#1 [mir_built] building MIR for `<impl at /tmp/icemaker_global_tempdir.wExQMUHWhTmO/rustc_testrunner_tmpdir_reporting.85MgQDvvjOZT/mvce.rs:11:1: 11:7>::check`
#2 [check_unsafety] unsafety-checking `<impl at /tmp/icemaker_global_tempdir.wExQMUHWhTmO/rustc_testrunner_tmpdir_reporting.85MgQDvvjOZT/mvce.rs:11:1: 11:7>::check`
#3 [analysis] running analysis passes on this crate
end of query stack
error[E0433]: failed to resolve: use of undeclared type `E`
 --> /tmp/icemaker_global_tempdir.wExQMUHWhTmO/rustc_testrunner_tmpdir_reporting.85MgQDvvjOZT/mvce.rs:3:10
  |
3 | struct S(E::V, ())
  |          ^
  |          |
  |          use of undeclared type `E`
  |          help: a trait with a similar name exists: `Eq`

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0433, E0601.
For more information about an error, try `rustc --explain E0433`.

Activity

  1. added
    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.
    C-bugCategory: This is a bug.
    on Mar 21, 2024
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Mar 21, 2024
  3. matthiaskrgr commented on Mar 21, 2024

    @matthiaskrgr
    MemberAuthor
  4. added
    A-patternsRelating to patterns and pattern matching
    S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issue
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Mar 22, 2024
  5. compiler-errors commented on Mar 22, 2024

    @compiler-errors
    Contributor

    This has ICEd before #120550:

    struct S(());
    
    impl S {
        fn check() {
            let a;
            (Self, a) = (S, ());
        }
    }
    
    fn main() {}
  6. matthiaskrgr commented on Mar 22, 2024

    @matthiaskrgr
    MemberAuthor

    ^Regression in nightly-2022-05-05

    commit[0] 2022-05-03: Auto merge of #96558 - bjorn3:librarify_parse_format, r=davidtwco
    commit[1] 2022-05-03: Auto merge of #95380 - compiler-errors:unit-destructure-assign, r=nikomatsakis
    commit[2] 2022-05-04: Auto merge of #96353 - estebank:issue-95413, r=compiler-errors
    commit[3] 2022-05-04: Auto merge of #96447 - petrochenkov:docregr, r=GuillaumeGomez
    commit[4] 2022-05-04: Auto merge of #96693 - ehuss:update-cargo, r=ehuss
    commit[5] 2022-05-04: Auto merge of #96695 - JohnTitor:rollup-oo4fc1h, r=JohnTitor
    commit[6] 2022-05-04: Auto merge of #94775 - oli-obk:operand_order, r=davidtwco
    commit[7] 2022-05-04: Auto merge of #96683 - nnethercote:speed-up-Token-ident-lifetime, r=petrochenkov
    commit[8] 2022-05-04: Auto merge of #96546 - nnethercote:overhaul-MacArgs, r=petrochenkov

    would not be surprised if its #95380 actually 🙈

  7. compiler-errors commented on Mar 22, 2024

    @compiler-errors
    Contributor

    So only this specific case seems to be #95380. Matching Self tuple ctors in patterns and ICEing is older than that:

    struct S(());
    
    impl S {
        fn foo() {
            let Self = S;
        }
    }
    
    fn main() {}
  8. matthiaskrgr commented on Mar 22, 2024

    @matthiaskrgr
    MemberAuthor

    https://www.youtube.com/watch?v=OzLhXesNkCI

    Regression in nightly-2020-11-19

    fetching (via remote github) commits from max(c919f49, 2020-11-16) to 8256379
    ending github query because we found starting sha: c919f49
    get_commits_between returning commits, len: 6
    commit[0] 2020-11-17: Auto merge of #79138 - m-ou-se:rollup-owel5ld, r=m-ou-se
    commit[1] 2020-11-18: Auto merge of #79132 - pietroalbini:beta-next, r=Mark-Simulacrum
    commit[2] 2020-11-18: Auto merge of #77820 - jyn514:from-inner, r=petrochenkov
    commit[3] 2020-11-18: Auto merge of #79159 - pietroalbini:woops, r=pietroalbini
    commit[4] 2020-11-18: Auto merge of #79167 - m-ou-se:rollup-4g15apk, r=m-ou-se
    commit[5] 2020-11-18: Auto merge of #78995 - Nadrieril:clean-empty-match, r=varkor

  9. added a commit that references this issue on Mar 25, 2024
    e9ec442
  10. added a commit that references this issue on Mar 25, 2024
    b31c211
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-patternsRelating to patterns and pattern matchingC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions