Skip to content

ICE: trying to compare incompatible constructors Ref and Str(Ty("foo")) #124083

Closed

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

enum En1<T> {
    Outest(&'a T),
}

fn wrap_en1_1<T>(x: T) -> En1<T> {}

fn main() {
    if let En1::Outest("foo") = wrap_en1_1::<_>("foo") {}
}

original:

trait Tr1 {}

enum En1<T> {
    Outest(&'a T),
}

fn wrap_en1_1<T>(x: T) -> En1<T> {}

fn main() {
    if let En1::Outest("foo") = wrap_en1_1::<_>("foo") {}
}

Version information

rustc 1.79.0-nightly (803e33a44 2024-04-17)
binary: rustc
commit-hash: 803e33a4460c82581bd01d4008d0f44aef1ddfe8
commit-date: 2024-04-17
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.3

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

Program output

error[E0261]: use of undeclared lifetime name `'a`
 --> /tmp/icemaker_global_tempdir.GLAdtPI8j8km/rustc_testrunner_tmpdir_reporting.XLmLiOlBrrIu/mvce.rs:2:13
  |
1 | enum En1<T> {
  |          - help: consider introducing lifetime `'a` here: `'a,`
2 |     Outest(&'a T),
  |             ^^ undeclared lifetime

error[E0308]: mismatched types
 --> /tmp/icemaker_global_tempdir.GLAdtPI8j8km/rustc_testrunner_tmpdir_reporting.XLmLiOlBrrIu/mvce.rs:5:27
  |
5 | fn wrap_en1_1<T>(x: T) -> En1<T> {}
  |    ----------             ^^^^^^ expected `En1<T>`, found `()`
  |    |
  |    implicitly returns `()` as its body has no tail or `return` expression
  |
  = note:   expected enum `En1<T>`
          found unit type `()`

error: internal compiler error: compiler/rustc_pattern_analysis/src/rustc.rs:897:9: trying to compare incompatible constructors Ref and Str(Ty("foo"))
 --> /tmp/icemaker_global_tempdir.GLAdtPI8j8km/rustc_testrunner_tmpdir_reporting.XLmLiOlBrrIu/mvce.rs:8:12
  |
8 |     if let En1::Outest("foo") = wrap_en1_1::<_>("foo") {}
  |            ^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at compiler/rustc_pattern_analysis/src/rustc.rs:897:9:
Box<dyn Any>
stack backtrace:
   0:     0x7a8d45dd8cd5 - std::backtrace_rs::backtrace::libunwind::trace::hd9cb198098d2c61d
                               at /rustc/803e33a4460c82581bd01d4008d0f44aef1ddfe8/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x7a8d45dd8cd5 - std::backtrace_rs::backtrace::trace_unsynchronized::hddf1040e7fdba935
                               at /rustc/803e33a4460c82581bd01d4008d0f44aef1ddfe8/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7a8d45dd8cd5 - std::sys_common::backtrace::_print_fmt::h804fa0989ad810bd
                               at /rustc/803e33a4460c82581bd01d4008d0f44aef1ddfe8/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7a8d45dd8cd5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h22cafdf1748a9616
                               at /rustc/803e33a4460c82581bd01d4008d0f44aef1ddfe8/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7a8d45e27f9b - core::fmt::rt::Argument::fmt::h6949bd6acf715f08
                               at /rustc/803e33a4460c82581bd01d4008d0f44aef1ddfe8/library/core/src/fmt/rt.rs:165:63
   5:     0x7a8d45e27f9b - core::fmt::write::h477d5c38da630f26
                               at /rustc/803e33a4460c82581bd01d4008d0f44aef1ddfe8/library/core/src/fmt/mod.rs:1157:21
   6:     0x7a8d45dcd85f - std::io::Write::write_fmt::h702d781f9312caab
                               at /rustc/803e33a4460c82581bd01d4008d0f44aef1ddfe8/library/std/src/io/mod.rs:1832:15
   7:     0x7a8d45dd8aae - std::sys_common::backtrace::_print::ha98bb3f47b7f108d
                               at /rustc/803e33a4460c82581bd01d4008d0f44aef1ddfe8/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7a8d45dd8aae - std::sys_common::backtrace::print::h0fda5e4e3b41e77c
                               at /rustc/803e33a4460c82581bd01d4008d0f44aef1ddfe8/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7a8d45ddb429 - std::panicking::default_hook::{{closure}}::h2f2bd0e1ae5292c4
  10:     0x7a8d45ddb16d - std::panicking::default_hook::hae01f2639bb30551
                               at /rustc/803e33a4460c82581bd01d4008d0f44aef1ddfe8/library/std/src/panicking.rs:291:9
  11:     0x7a8d4266c82b - std[579020d2760f34a5]::panicking::update_hook::<alloc[dd6d785e9c2bdfe3]::boxed::Box<rustc_driver_impl[f3f4779df6407916]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7a8d45ddbb2c - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h8cd1b2746579a7c1
                               at /rustc/803e33a4460c82581bd01d4008d0f44aef1ddfe8/library/alloc/src/boxed.rs:2036:9
  13:     0x7a8d45ddbb2c - std::panicking::rust_panic_with_hook::hbf6eda42ac6530ee
                               at /rustc/803e33a4460c82581bd01d4008d0f44aef1ddfe8/library/std/src/panicking.rs:792:13
  14:     0x7a8d4269cc24 - std[579020d2760f34a5]::panicking::begin_panic::<rustc_errors[38e7372a7ffc3815]::ExplicitBug>::{closure#0}
  15:     0x7a8d426995d6 - std[579020d2760f34a5]::sys_common::backtrace::__rust_end_short_backtrace::<std[579020d2760f34a5]::panicking::begin_panic<rustc_errors[38e7372a7ffc3815]::ExplicitBug>::{closure#0}, !>
  16:     0x7a8d42694b66 - std[579020d2760f34a5]::panicking::begin_panic::<rustc_errors[38e7372a7ffc3815]::ExplicitBug>
  17:     0x7a8d426a5c51 - <rustc_errors[38e7372a7ffc3815]::diagnostic::BugAbort as rustc_errors[38e7372a7ffc3815]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7a8d42db1658 - <rustc_errors[38e7372a7ffc3815]::DiagCtxt>::span_bug::<rustc_span[6007e8e04ffa0b28]::span_encoding::Span, alloc[dd6d785e9c2bdfe3]::string::String>
  19:     0x7a8d42db97ed - rustc_middle[e034bcf58dc9044a]::util::bug::opt_span_bug_fmt::<rustc_span[6007e8e04ffa0b28]::span_encoding::Span>::{closure#0}
  20:     0x7a8d42db981a - rustc_middle[e034bcf58dc9044a]::ty::context::tls::with_opt::<rustc_middle[e034bcf58dc9044a]::util::bug::opt_span_bug_fmt<rustc_span[6007e8e04ffa0b28]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7a8d42db503b - rustc_middle[e034bcf58dc9044a]::ty::context::tls::with_context_opt::<rustc_middle[e034bcf58dc9044a]::ty::context::tls::with_opt<rustc_middle[e034bcf58dc9044a]::util::bug::opt_span_bug_fmt<rustc_span[6007e8e04ffa0b28]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7a8d42db4d47 - rustc_middle[e034bcf58dc9044a]::util::bug::span_bug_fmt::<rustc_span[6007e8e04ffa0b28]::span_encoding::Span>
  23:     0x7a8d447bd498 - rustc_pattern_analysis[b816e39839f8fe6e]::usefulness::compute_exhaustiveness_and_usefulness::<rustc_pattern_analysis[b816e39839f8fe6e]::rustc::RustcPatCtxt>::{closure#0}
  24:     0x7a8d447b9606 - rustc_pattern_analysis[b816e39839f8fe6e]::usefulness::compute_exhaustiveness_and_usefulness::<rustc_pattern_analysis[b816e39839f8fe6e]::rustc::RustcPatCtxt>::{closure#0}
  25:     0x7a8d447b9606 - rustc_pattern_analysis[b816e39839f8fe6e]::usefulness::compute_exhaustiveness_and_usefulness::<rustc_pattern_analysis[b816e39839f8fe6e]::rustc::RustcPatCtxt>::{closure#0}
  26:     0x7a8d4417a480 - rustc_pattern_analysis[b816e39839f8fe6e]::analyze_match
  27:     0x7a8d40fc8b35 - <rustc_mir_build[639bcfbd6b56c353]::thir::pattern::check_match::MatchVisitor>::is_let_irrefutable
  28:     0x7a8d40fc3350 - <rustc_mir_build[639bcfbd6b56c353]::thir::pattern::check_match::MatchVisitor as rustc_middle[e034bcf58dc9044a]::thir::visit::Visitor>::visit_expr
  29:     0x7a8d40fc296d - <rustc_mir_build[639bcfbd6b56c353]::thir::pattern::check_match::MatchVisitor as rustc_middle[e034bcf58dc9044a]::thir::visit::Visitor>::visit_expr
  30:     0x7a8d40fc2eaf - <rustc_mir_build[639bcfbd6b56c353]::thir::pattern::check_match::MatchVisitor as rustc_middle[e034bcf58dc9044a]::thir::visit::Visitor>::visit_expr
  31:     0x7a8d40fc296d - <rustc_mir_build[639bcfbd6b56c353]::thir::pattern::check_match::MatchVisitor as rustc_middle[e034bcf58dc9044a]::thir::visit::Visitor>::visit_expr
  32:     0x7a8d40fc3827 - <rustc_mir_build[639bcfbd6b56c353]::thir::pattern::check_match::MatchVisitor as rustc_middle[e034bcf58dc9044a]::thir::visit::Visitor>::visit_expr
  33:     0x7a8d40fc296d - <rustc_mir_build[639bcfbd6b56c353]::thir::pattern::check_match::MatchVisitor as rustc_middle[e034bcf58dc9044a]::thir::visit::Visitor>::visit_expr
  34:     0x7a8d43d1b2ad - rustc_mir_build[639bcfbd6b56c353]::thir::pattern::check_match::check_match
  35:     0x7a8d43d1ae9f - rustc_query_impl[49829c95e283b62a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[49829c95e283b62a]::query_impl::check_match::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e034bcf58dc9044a]::query::erase::Erased<[u8; 1usize]>>
  36:     0x7a8d43d11b87 - rustc_query_system[43632b3ed5a17eb7]::query::plumbing::try_execute_query::<rustc_query_impl[49829c95e283b62a]::DynamicConfig<rustc_query_system[43632b3ed5a17eb7]::query::caches::VecCache<rustc_span[6007e8e04ffa0b28]::def_id::LocalDefId, rustc_middle[e034bcf58dc9044a]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[49829c95e283b62a]::plumbing::QueryCtxt, false>
  37:     0x7a8d43d11815 - rustc_query_impl[49829c95e283b62a]::query_impl::check_match::get_query_non_incr::__rust_end_short_backtrace
  38:     0x7a8d43d24093 - rustc_mir_build[639bcfbd6b56c353]::build::mir_build
  39:     0x7a8d43d23751 - rustc_query_impl[49829c95e283b62a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[49829c95e283b62a]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e034bcf58dc9044a]::query::erase::Erased<[u8; 8usize]>>
  40:     0x7a8d43c38d31 - rustc_query_system[43632b3ed5a17eb7]::query::plumbing::try_execute_query::<rustc_query_impl[49829c95e283b62a]::DynamicConfig<rustc_query_system[43632b3ed5a17eb7]::query::caches::VecCache<rustc_span[6007e8e04ffa0b28]::def_id::LocalDefId, rustc_middle[e034bcf58dc9044a]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[49829c95e283b62a]::plumbing::QueryCtxt, false>
  41:     0x7a8d43c3884c - rustc_query_impl[49829c95e283b62a]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  42:     0x7a8d44225b9a - rustc_mir_build[639bcfbd6b56c353]::check_unsafety::check_unsafety
  43:     0x7a8d44225937 - rustc_query_impl[49829c95e283b62a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[49829c95e283b62a]::query_impl::check_unsafety::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e034bcf58dc9044a]::query::erase::Erased<[u8; 0usize]>>
  44:     0x7a8d44230067 - rustc_query_system[43632b3ed5a17eb7]::query::plumbing::try_execute_query::<rustc_query_impl[49829c95e283b62a]::DynamicConfig<rustc_query_system[43632b3ed5a17eb7]::query::caches::VecCache<rustc_span[6007e8e04ffa0b28]::def_id::LocalDefId, rustc_middle[e034bcf58dc9044a]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[49829c95e283b62a]::plumbing::QueryCtxt, false>
  45:     0x7a8d4422fc93 - rustc_query_impl[49829c95e283b62a]::query_impl::check_unsafety::get_query_non_incr::__rust_end_short_backtrace
  46:     0x7a8d4422c085 - rustc_interface[83f8b168dbc5b1b5]::passes::analysis
  47:     0x7a8d4422b195 - rustc_query_impl[49829c95e283b62a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[49829c95e283b62a]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e034bcf58dc9044a]::query::erase::Erased<[u8; 1usize]>>
  48:     0x7a8d447a5f25 - rustc_query_system[43632b3ed5a17eb7]::query::plumbing::try_execute_query::<rustc_query_impl[49829c95e283b62a]::DynamicConfig<rustc_query_system[43632b3ed5a17eb7]::query::caches::SingleCache<rustc_middle[e034bcf58dc9044a]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[49829c95e283b62a]::plumbing::QueryCtxt, false>
  49:     0x7a8d447a5c89 - rustc_query_impl[49829c95e283b62a]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  50:     0x7a8d4467b919 - rustc_interface[83f8b168dbc5b1b5]::interface::run_compiler::<core[83e4cb43580d14f1]::result::Result<(), rustc_span[6007e8e04ffa0b28]::ErrorGuaranteed>, rustc_driver_impl[f3f4779df6407916]::run_compiler::{closure#0}>::{closure#1}
  51:     0x7a8d4463e067 - std[579020d2760f34a5]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[83f8b168dbc5b1b5]::util::run_in_thread_with_globals<rustc_interface[83f8b168dbc5b1b5]::util::run_in_thread_pool_with_globals<rustc_interface[83f8b168dbc5b1b5]::interface::run_compiler<core[83e4cb43580d14f1]::result::Result<(), rustc_span[6007e8e04ffa0b28]::ErrorGuaranteed>, rustc_driver_impl[f3f4779df6407916]::run_compiler::{closure#0}>::{closure#1}, core[83e4cb43580d14f1]::result::Result<(), rustc_span[6007e8e04ffa0b28]::ErrorGuaranteed>>::{closure#0}, core[83e4cb43580d14f1]::result::Result<(), rustc_span[6007e8e04ffa0b28]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[83e4cb43580d14f1]::result::Result<(), rustc_span[6007e8e04ffa0b28]::ErrorGuaranteed>>
  52:     0x7a8d4463de2a - <<std[579020d2760f34a5]::thread::Builder>::spawn_unchecked_<rustc_interface[83f8b168dbc5b1b5]::util::run_in_thread_with_globals<rustc_interface[83f8b168dbc5b1b5]::util::run_in_thread_pool_with_globals<rustc_interface[83f8b168dbc5b1b5]::interface::run_compiler<core[83e4cb43580d14f1]::result::Result<(), rustc_span[6007e8e04ffa0b28]::ErrorGuaranteed>, rustc_driver_impl[f3f4779df6407916]::run_compiler::{closure#0}>::{closure#1}, core[83e4cb43580d14f1]::result::Result<(), rustc_span[6007e8e04ffa0b28]::ErrorGuaranteed>>::{closure#0}, core[83e4cb43580d14f1]::result::Result<(), rustc_span[6007e8e04ffa0b28]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[83e4cb43580d14f1]::result::Result<(), rustc_span[6007e8e04ffa0b28]::ErrorGuaranteed>>::{closure#2} as core[83e4cb43580d14f1]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  53:     0x7a8d45de5a1b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h4e4c94566de61594
                               at /rustc/803e33a4460c82581bd01d4008d0f44aef1ddfe8/library/alloc/src/boxed.rs:2022:9
  54:     0x7a8d45de5a1b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3a5b2acb8225662e
                               at /rustc/803e33a4460c82581bd01d4008d0f44aef1ddfe8/library/alloc/src/boxed.rs:2022:9
  55:     0x7a8d45de5a1b - std::sys::pal::unix::thread::Thread::new::thread_start::h1b84f76802dc5e80
                               at /rustc/803e33a4460c82581bd01d4008d0f44aef1ddfe8/library/std/src/sys/pal/unix/thread.rs:108:17
  56:     0x7a8d45b8355a - <unknown>
  57:     0x7a8d45c00a3c - <unknown>
  58:                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: please make sure that you have updated to the latest nightly

note: rustc 1.79.0-nightly (803e33a44 2024-04-17) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [check_match] match-checking `main`
#1 [mir_built] building MIR for `main`
#2 [check_unsafety] unsafety-checking `main`
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors

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

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 Apr 17, 2024
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Apr 17, 2024
  3. matthiaskrgr commented on Apr 17, 2024

    @matthiaskrgr
    MemberAuthor
  4. compiler-errors commented on Apr 17, 2024

    @compiler-errors
    Contributor
  5. Nadrieril commented on Apr 17, 2024

    @Nadrieril
    Member

    Minimized:

    struct Outest(&'a ());
    
    fn make() -> Outest {}
    
    fn main() {
        if let Outest("foo") = make() {}
    }

    This is a type error that should never have reached match checking. The ICE goes away if we replace 'a with 'static. How come we don't bail when 'a is unbound?

  6. Nadrieril commented on Apr 17, 2024

    @Nadrieril
    Member

    If #122749 is indeed the culprit, I'm guessing there's a Ty::Error in there that used to be caught but isn't anymore

  7. compiler-errors commented on Apr 17, 2024

    @compiler-errors
    Contributor

    Well it's not Ty::Error, it's probably RegionKind::ReError

  8. added
    S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.
    on Apr 20, 2024
  9. added
    A-patternsRelating to patterns and pattern matching
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Apr 28, 2024
  10. added 3 commits that reference this issue on Jul 4, 2024
    7b804d2
    567809d
    c92a8e4
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-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-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