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: Unexpected type for 'Ref' constructor: *const &'{erased} () #126648

Closed
matthiaskrgr opened this issue Jun 18, 2024 · 2 comments · Fixed by #127311
Closed

ICE: Unexpected type for 'Ref' constructor: *const &'{erased} () #126648

matthiaskrgr opened this issue Jun 18, 2024 · 2 comments · Fixed by #127311
Labels
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

snippet:

struct Outest(*const &'a ());

fn make() -> Outest {}

fn main() {
    if let Outest("foo") = make() {}
}

Version information

rustc 1.81.0-nightly (dd104ef16 2024-06-18)
binary: rustc
commit-hash: dd104ef16315e2387fe94e8c43eb5a66e3dbd660
commit-date: 2024-06-18
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7

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

Program output

error[E0261]: use of undeclared lifetime name `'a`
 --> /tmp/icemaker_global_tempdir.TgpW6JrktGaA/rustc_testrunner_tmpdir_reporting.7eRm4vVFAtEm/mvce.rs:1:23
  |
1 | struct Outest(*const &'a ());
  |              -        ^^ undeclared lifetime
  |              |
  |              help: consider introducing lifetime `'a` here: `<'a>`

error[E0308]: mismatched types
 --> /tmp/icemaker_global_tempdir.TgpW6JrktGaA/rustc_testrunner_tmpdir_reporting.7eRm4vVFAtEm/mvce.rs:3:14
  |
3 | fn make() -> Outest {}
  |    ----      ^^^^^^ expected `Outest`, found `()`
  |    |
  |    implicitly returns `()` as its body has no tail or `return` expression

error: internal compiler error: compiler/rustc_pattern_analysis/src/rustc.rs:241:22: Unexpected type for `Ref` constructor: *const &'{erased} ()

thread 'rustc' panicked at compiler/rustc_pattern_analysis/src/rustc.rs:241:22:
Box<dyn Any>
stack backtrace:
   0:     0x731938db2935 - std::backtrace_rs::backtrace::libunwind::trace::h24001de405a19c29
                               at /rustc/dd104ef16315e2387fe94e8c43eb5a66e3dbd660/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x731938db2935 - std::backtrace_rs::backtrace::trace_unsynchronized::h52cb31f58d87e795
                               at /rustc/dd104ef16315e2387fe94e8c43eb5a66e3dbd660/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x731938db2935 - std::sys::backtrace::_print_fmt::ha0a4a385e6305dc9
                               at /rustc/dd104ef16315e2387fe94e8c43eb5a66e3dbd660/library/std/src/sys/backtrace.rs:68:5
   3:     0x731938db2935 - <std::sys::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd2ac9d261fff2c5c
                               at /rustc/dd104ef16315e2387fe94e8c43eb5a66e3dbd660/library/std/src/sys/backtrace.rs:44:22
   4:     0x731938e034db - core::fmt::rt::Argument::fmt::h5dd96858711c38a5
                               at /rustc/dd104ef16315e2387fe94e8c43eb5a66e3dbd660/library/core/src/fmt/rt.rs:165:63
   5:     0x731938e034db - core::fmt::write::h9137aaeb0715e137
                               at /rustc/dd104ef16315e2387fe94e8c43eb5a66e3dbd660/library/core/src/fmt/mod.rs:1168:21
   6:     0x731938da751f - std::io::Write::write_fmt::h3d543f59fe71748a
                               at /rustc/dd104ef16315e2387fe94e8c43eb5a66e3dbd660/library/std/src/io/mod.rs:1835:15
   7:     0x731938db270e - std::sys::backtrace::_print::h4a7caef85c10fa0d
                               at /rustc/dd104ef16315e2387fe94e8c43eb5a66e3dbd660/library/std/src/sys/backtrace.rs:47:5
   8:     0x731938db270e - std::sys::backtrace::print::hf1ff8c4b50b84478
                               at /rustc/dd104ef16315e2387fe94e8c43eb5a66e3dbd660/library/std/src/sys/backtrace.rs:34:9
   9:     0x731938db5149 - std::panicking::default_hook::{{closure}}::h76d1d90acd3a4473
  10:     0x731938db4eec - std::panicking::default_hook::h2a49ac4243aa5140
                               at /rustc/dd104ef16315e2387fe94e8c43eb5a66e3dbd660/library/std/src/panicking.rs:292:9
  11:     0x7319354acd2f - std[49f1045a74567fa7]::panicking::update_hook::<alloc[5df14249ca9505f2]::boxed::Box<rustc_driver_impl[db4e8f03b5696bb3]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x731938db5a6f - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h25f6191eb839a16b
                               at /rustc/dd104ef16315e2387fe94e8c43eb5a66e3dbd660/library/alloc/src/boxed.rs:2076:9
  13:     0x731938db5a6f - std::panicking::rust_panic_with_hook::hc9c5e69e405d5d6c
                               at /rustc/dd104ef16315e2387fe94e8c43eb5a66e3dbd660/library/std/src/panicking.rs:804:13
  14:     0x7319354dd7e1 - std[49f1045a74567fa7]::panicking::begin_panic::<rustc_errors[f1c452f0768a3196]::ExplicitBug>::{closure#0}
  15:     0x7319354da596 - std[49f1045a74567fa7]::sys::backtrace::__rust_end_short_backtrace::<std[49f1045a74567fa7]::panicking::begin_panic<rustc_errors[f1c452f0768a3196]::ExplicitBug>::{closure#0}, !>
  16:     0x7319354da276 - std[49f1045a74567fa7]::panicking::begin_panic::<rustc_errors[f1c452f0768a3196]::ExplicitBug>
  17:     0x7319354e6d31 - <rustc_errors[f1c452f0768a3196]::diagnostic::BugAbort as rustc_errors[f1c452f0768a3196]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7319359bf58c - rustc_middle[1b5811ec6d2edbd2]::util::bug::opt_span_bug_fmt::<rustc_span[b2dab8d5db9c06d4]::span_encoding::Span>::{closure#0}
  19:     0x7319359a8ada - rustc_middle[1b5811ec6d2edbd2]::ty::context::tls::with_opt::<rustc_middle[1b5811ec6d2edbd2]::util::bug::opt_span_bug_fmt<rustc_span[b2dab8d5db9c06d4]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  20:     0x7319359a895b - rustc_middle[1b5811ec6d2edbd2]::ty::context::tls::with_context_opt::<rustc_middle[1b5811ec6d2edbd2]::ty::context::tls::with_opt<rustc_middle[1b5811ec6d2edbd2]::util::bug::opt_span_bug_fmt<rustc_span[b2dab8d5db9c06d4]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  21:     0x73193346c250 - rustc_middle[1b5811ec6d2edbd2]::util::bug::bug_fmt
  22:     0x731937004d48 - rustc_pattern_analysis[9ec12d2f5d12a80]::usefulness::compute_exhaustiveness_and_usefulness::<rustc_pattern_analysis[9ec12d2f5d12a80]::rustc::RustcPatCtxt>::{closure#0}
  23:     0x731936ffee69 - rustc_pattern_analysis[9ec12d2f5d12a80]::usefulness::compute_exhaustiveness_and_usefulness::<rustc_pattern_analysis[9ec12d2f5d12a80]::rustc::RustcPatCtxt>::{closure#0}
  24:     0x731936ff92bc - rustc_pattern_analysis[9ec12d2f5d12a80]::analyze_match
  25:     0x731933de2804 - <rustc_mir_build[10942160e2184657]::thir::pattern::check_match::MatchVisitor>::is_let_irrefutable
  26:     0x731933ddd05d - <rustc_mir_build[10942160e2184657]::thir::pattern::check_match::MatchVisitor as rustc_middle[1b5811ec6d2edbd2]::thir::visit::Visitor>::visit_expr
  27:     0x731933ddc69d - <rustc_mir_build[10942160e2184657]::thir::pattern::check_match::MatchVisitor as rustc_middle[1b5811ec6d2edbd2]::thir::visit::Visitor>::visit_expr
  28:     0x731933ddcbc9 - <rustc_mir_build[10942160e2184657]::thir::pattern::check_match::MatchVisitor as rustc_middle[1b5811ec6d2edbd2]::thir::visit::Visitor>::visit_expr
  29:     0x731933ddc69d - <rustc_mir_build[10942160e2184657]::thir::pattern::check_match::MatchVisitor as rustc_middle[1b5811ec6d2edbd2]::thir::visit::Visitor>::visit_expr
  30:     0x731933ddd504 - <rustc_mir_build[10942160e2184657]::thir::pattern::check_match::MatchVisitor as rustc_middle[1b5811ec6d2edbd2]::thir::visit::Visitor>::visit_expr
  31:     0x731933ddc69d - <rustc_mir_build[10942160e2184657]::thir::pattern::check_match::MatchVisitor as rustc_middle[1b5811ec6d2edbd2]::thir::visit::Visitor>::visit_expr
  32:     0x731936bf41be - rustc_mir_build[10942160e2184657]::thir::pattern::check_match::check_match
  33:     0x731936bf3dd5 - rustc_query_impl[ed5fbfae2043678b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ed5fbfae2043678b]::query_impl::check_match::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1b5811ec6d2edbd2]::query::erase::Erased<[u8; 1usize]>>
  34:     0x731936bf347f - rustc_query_system[f4d6069fb68f5c49]::query::plumbing::try_execute_query::<rustc_query_impl[ed5fbfae2043678b]::DynamicConfig<rustc_query_system[f4d6069fb68f5c49]::query::caches::VecCache<rustc_span[b2dab8d5db9c06d4]::def_id::LocalDefId, rustc_middle[1b5811ec6d2edbd2]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[ed5fbfae2043678b]::plumbing::QueryCtxt, false>
  35:     0x731936bf31dd - rustc_query_impl[ed5fbfae2043678b]::query_impl::check_match::get_query_non_incr::__rust_end_short_backtrace
  36:     0x731936c0bcc8 - rustc_mir_build[10942160e2184657]::build::mir_build
  37:     0x731936c0b38e - rustc_query_impl[ed5fbfae2043678b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ed5fbfae2043678b]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1b5811ec6d2edbd2]::query::erase::Erased<[u8; 8usize]>>
  38:     0x731936bbe0ae - rustc_query_system[f4d6069fb68f5c49]::query::plumbing::try_execute_query::<rustc_query_impl[ed5fbfae2043678b]::DynamicConfig<rustc_query_system[f4d6069fb68f5c49]::query::caches::VecCache<rustc_span[b2dab8d5db9c06d4]::def_id::LocalDefId, rustc_middle[1b5811ec6d2edbd2]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[ed5fbfae2043678b]::plumbing::QueryCtxt, false>
  39:     0x731936bbdbcd - rustc_query_impl[ed5fbfae2043678b]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  40:     0x731936bff048 - rustc_mir_build[10942160e2184657]::check_unsafety::check_unsafety
  41:     0x731936bfedf1 - rustc_query_impl[ed5fbfae2043678b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ed5fbfae2043678b]::query_impl::check_unsafety::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1b5811ec6d2edbd2]::query::erase::Erased<[u8; 0usize]>>
  42:     0x731936bfdeea - rustc_query_system[f4d6069fb68f5c49]::query::plumbing::try_execute_query::<rustc_query_impl[ed5fbfae2043678b]::DynamicConfig<rustc_query_system[f4d6069fb68f5c49]::query::caches::VecCache<rustc_span[b2dab8d5db9c06d4]::def_id::LocalDefId, rustc_middle[1b5811ec6d2edbd2]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[ed5fbfae2043678b]::plumbing::QueryCtxt, false>
  43:     0x731936bfdb0b - rustc_query_impl[ed5fbfae2043678b]::query_impl::check_unsafety::get_query_non_incr::__rust_end_short_backtrace
  44:     0x731937203d2a - rustc_interface[c6ece38a3a908c28]::passes::analysis
  45:     0x731937202e07 - rustc_query_impl[ed5fbfae2043678b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ed5fbfae2043678b]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1b5811ec6d2edbd2]::query::erase::Erased<[u8; 1usize]>>
  46:     0x7319376360a5 - rustc_query_system[f4d6069fb68f5c49]::query::plumbing::try_execute_query::<rustc_query_impl[ed5fbfae2043678b]::DynamicConfig<rustc_query_system[f4d6069fb68f5c49]::query::caches::SingleCache<rustc_middle[1b5811ec6d2edbd2]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[ed5fbfae2043678b]::plumbing::QueryCtxt, false>
  47:     0x731937635e0f - rustc_query_impl[ed5fbfae2043678b]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  48:     0x7319374dd3d2 - rustc_interface[c6ece38a3a908c28]::interface::run_compiler::<core[3c5d2e85893f84f8]::result::Result<(), rustc_span[b2dab8d5db9c06d4]::ErrorGuaranteed>, rustc_driver_impl[db4e8f03b5696bb3]::run_compiler::{closure#0}>::{closure#1}
  49:     0x7319374b54c9 - std[49f1045a74567fa7]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[c6ece38a3a908c28]::util::run_in_thread_with_globals<rustc_interface[c6ece38a3a908c28]::util::run_in_thread_pool_with_globals<rustc_interface[c6ece38a3a908c28]::interface::run_compiler<core[3c5d2e85893f84f8]::result::Result<(), rustc_span[b2dab8d5db9c06d4]::ErrorGuaranteed>, rustc_driver_impl[db4e8f03b5696bb3]::run_compiler::{closure#0}>::{closure#1}, core[3c5d2e85893f84f8]::result::Result<(), rustc_span[b2dab8d5db9c06d4]::ErrorGuaranteed>>::{closure#0}, core[3c5d2e85893f84f8]::result::Result<(), rustc_span[b2dab8d5db9c06d4]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[3c5d2e85893f84f8]::result::Result<(), rustc_span[b2dab8d5db9c06d4]::ErrorGuaranteed>>
  50:     0x7319374b527a - <<std[49f1045a74567fa7]::thread::Builder>::spawn_unchecked_<rustc_interface[c6ece38a3a908c28]::util::run_in_thread_with_globals<rustc_interface[c6ece38a3a908c28]::util::run_in_thread_pool_with_globals<rustc_interface[c6ece38a3a908c28]::interface::run_compiler<core[3c5d2e85893f84f8]::result::Result<(), rustc_span[b2dab8d5db9c06d4]::ErrorGuaranteed>, rustc_driver_impl[db4e8f03b5696bb3]::run_compiler::{closure#0}>::{closure#1}, core[3c5d2e85893f84f8]::result::Result<(), rustc_span[b2dab8d5db9c06d4]::ErrorGuaranteed>>::{closure#0}, core[3c5d2e85893f84f8]::result::Result<(), rustc_span[b2dab8d5db9c06d4]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[3c5d2e85893f84f8]::result::Result<(), rustc_span[b2dab8d5db9c06d4]::ErrorGuaranteed>>::{closure#2} as core[3c5d2e85893f84f8]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  51:     0x731938dbf8eb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::haf6c6ed15ef7c4b2
                               at /rustc/dd104ef16315e2387fe94e8c43eb5a66e3dbd660/library/alloc/src/boxed.rs:2062:9
  52:     0x731938dbf8eb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3648257e1237816c
                               at /rustc/dd104ef16315e2387fe94e8c43eb5a66e3dbd660/library/alloc/src/boxed.rs:2062:9
  53:     0x731938dbf8eb - std::sys::pal::unix::thread::Thread::new::thread_start::h379e689399d87cbf
                               at /rustc/dd104ef16315e2387fe94e8c43eb5a66e3dbd660/library/std/src/sys/pal/unix/thread.rs:108:17
  54:     0x731938b58ded - <unknown>
  55:     0x731938bdc0dc - <unknown>
  56:                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.81.0-nightly (dd104ef16 2024-06-18) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [check_match] match-checking `main`
#1 [mir_built] building MIR for `main`
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 Jun 18, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 18, 2024
@matthiaskrgr matthiaskrgr changed the title ICE: Unexpected type for Ref constructor: *const &'{erased} () ICE: Unexpected type for 'Ref' constructor: *const &'{erased} () Jun 18, 2024
@GrigorenkoPV
Copy link
Contributor

searched nightlies: from nightly-2022-02-19 to nightly-2024-06-19
regressed nightly: nightly-2024-03-22
searched commit range: 1388d7a...0ad927c
regressed commit: 6a6cd65 (#122803, which is a rollup)
Same as regressed PR as in #126666

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 23, 2024
@matthiaskrgr
Copy link
Member Author

probably #122749

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Jun 30, 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
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.

4 participants