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: trying to compare incompatible constructors Ref and Str(Ty("foo")) #124083

Closed
matthiaskrgr opened this issue Apr 17, 2024 · 5 comments · Fixed by #127311
Closed

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

matthiaskrgr opened this issue Apr 17, 2024 · 5 comments · Fixed by #127311
Labels
A-patterns Relating to patterns and pattern matching C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

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`.

@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. labels Apr 17, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 17, 2024
@matthiaskrgr
Copy link
Member Author

#122749

@compiler-errors
Copy link
Member

cc @Nadrieril

@Nadrieril
Copy link
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?

@Nadrieril
Copy link
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

@compiler-errors
Copy link
Member

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

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Apr 20, 2024
@saethlin saethlin added A-patterns Relating to patterns and pattern matching and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 28, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Jul 4, 2024
Avoid follow-up errors and ICEs after missing lifetime errors on data structures

Tuple struct constructors are functions, so when we call them typeck will use the signature tuple struct constructor function to provide type hints. Since typeck mostly ignores and erases lifetimes, we end up never seeing the error lifetime in writeback, thus not tainting the typeck result.

Now, we eagerly taint typeck results by tainting from `resolve_vars_if_possible`, which is called all over the place.

I did not carry over all the `crashes` test suite tests, as they are really all the same cause (missing or unknown lifetime names in tuple struct definitions or generic arg lists).

fixes rust-lang#124262
fixes rust-lang#124083
fixes rust-lang#125155
fixes rust-lang#125888
fixes rust-lang#125992
fixes rust-lang#126666
fixes rust-lang#126648
fixes rust-lang#127268
bors added a commit to rust-lang-ci/rust that referenced this issue Jul 9, 2024
…ler-errors

Avoid follow-up errors and ICEs after missing lifetime errors on data structures

Tuple struct constructors are functions, so when we call them typeck will use the signature tuple struct constructor function to provide type hints. Since typeck mostly ignores and erases lifetimes, we end up never seeing the error lifetime in writeback, thus not tainting the typeck result.

Now, we eagerly taint typeck results by tainting from `resolve_vars_if_possible`, which is called all over the place.

I did not carry over all the `crashes` test suite tests, as they are really all the same cause (missing or unknown lifetime names in tuple struct definitions or generic arg lists).

fixes rust-lang#124262
fixes rust-lang#124083
fixes rust-lang#125155
fixes rust-lang#125888
fixes rust-lang#125992
fixes rust-lang#126666
fixes rust-lang#126648
fixes rust-lang#127268
@bors bors closed this as completed in c92a8e4 Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-patterns Relating to patterns and pattern matching C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. 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.

5 participants