Skip to content

ICE: Unexpected coroutine/closure type in variance computation #123899

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
matthiaskrgr opened this issue Apr 13, 2024 · 3 comments · Fixed by #123931
Closed

ICE: Unexpected coroutine/closure type in variance computation #123899

matthiaskrgr opened this issue Apr 13, 2024 · 3 comments · Fixed by #123931
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-HIR Area: The high-level intermediate representation (HIR) A-inference Area: Type inference A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Apr 13, 2024

auto-reduced (treereduce-rust):

pub struct T<'g>(&'a str);

pub fn f<statica>(val ) -> _ {
    g
}

pub fn g(val: T<'a>) -> _ {}


original:

pub struct T<'g>(&'a str);

pub fn f<statica>(val val: T<'static>) -> _ {
    g
}

pub fn g(val: T<'a>) -> _ {}

fn main() {}

Version information

rustc 1.79.0-nightly (7106800e1 2024-04-13)
binary: rustc
commit-hash: 7106800e16085bf1805cc8e75866ed0f0efd85d9
commit-date: 2024-04-13
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: expected one of `:`, `@`, or `|`, found `)`
 --> /tmp/icemaker_global_tempdir.BJ7DBx2Izast/rustc_testrunner_tmpdir_reporting.Au3pifxmyi2a/mvce.rs:3:23
  |
3 | pub fn f<statica>(val ) -> _ {
  |                       ^ expected one of `:`, `@`, or `|`
  |
  = note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
help: if this is a `self` type, give it a parameter name
  |
3 | pub fn f<statica>(self: val ) -> _ {
  |                   +++++
help: if this is a parameter name, give it a type
  |
3 | pub fn f<statica>(val: TypeName ) -> _ {
  |                      ++++++++++
help: if this is a type, explicitly ignore the parameter name
  |
3 | pub fn f<statica>(_: val ) -> _ {
  |                   ++

error[E0261]: use of undeclared lifetime name `'a`
 --> /tmp/icemaker_global_tempdir.BJ7DBx2Izast/rustc_testrunner_tmpdir_reporting.Au3pifxmyi2a/mvce.rs:1:19
  |
1 | pub struct T<'g>(&'a str);
  |              -    ^^ undeclared lifetime
  |              |
  |              help: consider introducing lifetime `'a` here: `'a,`

error[E0261]: use of undeclared lifetime name `'a`
 --> /tmp/icemaker_global_tempdir.BJ7DBx2Izast/rustc_testrunner_tmpdir_reporting.Au3pifxmyi2a/mvce.rs:7:17
  |
7 | pub fn g(val: T<'a>) -> _ {}
  |         -       ^^ undeclared lifetime
  |         |
  |         help: consider introducing lifetime `'a` here: `<'a>`

warning: type parameter `statica` should have an upper camel case name
 --> /tmp/icemaker_global_tempdir.BJ7DBx2Izast/rustc_testrunner_tmpdir_reporting.Au3pifxmyi2a/mvce.rs:3:10
  |
3 | pub fn f<statica>(val ) -> _ {
  |          ^^^^^^^ help: convert the identifier to upper camel case (notice the capitalization): `Statica`
  |
  = note: `#[warn(non_camel_case_types)]` on by default

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.BJ7DBx2Izast/rustc_testrunner_tmpdir_reporting.Au3pifxmyi2a/mvce.rs:7:29
  |
7 | pub fn g(val: T<'a>) -> _ {}
  |                             ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.BJ7DBx2Izast/rustc_testrunner_tmpdir_reporting.Au3pifxmyi2a/mvce.rs`

error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
 --> /tmp/icemaker_global_tempdir.BJ7DBx2Izast/rustc_testrunner_tmpdir_reporting.Au3pifxmyi2a/mvce.rs:7:25
  |
7 | pub fn g(val: T<'a>) -> _ {}
  |                         ^
  |                         |
  |                         not allowed in type signatures
  |                         help: replace with the correct return type: `()`

error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
 --> /tmp/icemaker_global_tempdir.BJ7DBx2Izast/rustc_testrunner_tmpdir_reporting.Au3pifxmyi2a/mvce.rs:3:28
  |
3 | pub fn f<statica>(val ) -> _ {
  |                            ^
  |                            |
  |                            not allowed in type signatures
  |                            help: replace with the correct return type: `fn(T<'static>)`

warning: unused variable: `val`
 --> /tmp/icemaker_global_tempdir.BJ7DBx2Izast/rustc_testrunner_tmpdir_reporting.Au3pifxmyi2a/mvce.rs:7:10
  |
7 | pub fn g(val: T<'a>) -> _ {}
  |          ^^^ help: if this is intentional, prefix it with an underscore: `_val`
  |
  = note: `#[warn(unused_variables)]` on by default

error: internal compiler error: compiler/rustc_hir_analysis/src/variance/constraints.rs:239:17: Unexpected coroutine/closure type in variance computation

thread 'rustc' panicked at compiler/rustc_hir_analysis/src/variance/constraints.rs:239:17:
Box<dyn Any>
stack backtrace:
   0:     0x7cd3c96eac05 - std::backtrace_rs::backtrace::libunwind::trace::hd44abde4e56b93ae
                               at /rustc/7106800e16085bf1805cc8e75866ed0f0efd85d9/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x7cd3c96eac05 - std::backtrace_rs::backtrace::trace_unsynchronized::h93e9d4ba285990da
                               at /rustc/7106800e16085bf1805cc8e75866ed0f0efd85d9/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7cd3c96eac05 - std::sys_common::backtrace::_print_fmt::h30429ee4bc1e53aa
                               at /rustc/7106800e16085bf1805cc8e75866ed0f0efd85d9/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7cd3c96eac05 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::ha6d9228469b6762a
                               at /rustc/7106800e16085bf1805cc8e75866ed0f0efd85d9/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7cd3c9739f3b - core::fmt::rt::Argument::fmt::hac031b225e253311
                               at /rustc/7106800e16085bf1805cc8e75866ed0f0efd85d9/library/core/src/fmt/rt.rs:142:9
   5:     0x7cd3c9739f3b - core::fmt::write::h9f5a2ae1018cbd96
                               at /rustc/7106800e16085bf1805cc8e75866ed0f0efd85d9/library/core/src/fmt/mod.rs:1153:17
   6:     0x7cd3c96df80f - std::io::Write::write_fmt::hd9edfa39a7ec5c2b
                               at /rustc/7106800e16085bf1805cc8e75866ed0f0efd85d9/library/std/src/io/mod.rs:1832:15
   7:     0x7cd3c96ea9de - std::sys_common::backtrace::_print::h7e0af64dc7464b7b
                               at /rustc/7106800e16085bf1805cc8e75866ed0f0efd85d9/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7cd3c96ea9de - std::sys_common::backtrace::print::h618452dde664c7b6
                               at /rustc/7106800e16085bf1805cc8e75866ed0f0efd85d9/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7cd3c96ed359 - std::panicking::default_hook::{{closure}}::h6f65dad3451d890e
  10:     0x7cd3c96ed09d - std::panicking::default_hook::h3c23a4188d7d1311
                               at /rustc/7106800e16085bf1805cc8e75866ed0f0efd85d9/library/std/src/panicking.rs:291:9
  11:     0x7cd3c6079d7b - std[835e4498f0b3bd88]::panicking::update_hook::<alloc[903e10720135b018]::boxed::Box<rustc_driver_impl[9c9c8c71a9367b3e]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7cd3c96eda5c - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hd43968aff557412b
                               at /rustc/7106800e16085bf1805cc8e75866ed0f0efd85d9/library/alloc/src/boxed.rs:2032:9
  13:     0x7cd3c96eda5c - std::panicking::rust_panic_with_hook::heeb0f225e0d228a3
                               at /rustc/7106800e16085bf1805cc8e75866ed0f0efd85d9/library/std/src/panicking.rs:792:13
  14:     0x7cd3c60a9d94 - std[835e4498f0b3bd88]::panicking::begin_panic::<rustc_errors[d1965a4535c85053]::ExplicitBug>::{closure#0}
  15:     0x7cd3c60a6836 - std[835e4498f0b3bd88]::sys_common::backtrace::__rust_end_short_backtrace::<std[835e4498f0b3bd88]::panicking::begin_panic<rustc_errors[d1965a4535c85053]::ExplicitBug>::{closure#0}, !>
  16:     0x7cd3c60a1e56 - std[835e4498f0b3bd88]::panicking::begin_panic::<rustc_errors[d1965a4535c85053]::ExplicitBug>
  17:     0x7cd3c60b2dc1 - <rustc_errors[d1965a4535c85053]::diagnostic::BugAbort as rustc_errors[d1965a4535c85053]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7cd3c655835c - rustc_middle[46ef5772c9c0ed48]::util::bug::opt_span_bug_fmt::<rustc_span[4530179975c83374]::span_encoding::Span>::{closure#0}
  19:     0x7cd3c653f8aa - rustc_middle[46ef5772c9c0ed48]::ty::context::tls::with_opt::<rustc_middle[46ef5772c9c0ed48]::util::bug::opt_span_bug_fmt<rustc_span[4530179975c83374]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  20:     0x7cd3c653f74b - rustc_middle[46ef5772c9c0ed48]::ty::context::tls::with_context_opt::<rustc_middle[46ef5772c9c0ed48]::ty::context::tls::with_opt<rustc_middle[46ef5772c9c0ed48]::util::bug::opt_span_bug_fmt<rustc_span[4530179975c83374]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  21:     0x7cd3c415a5a0 - rustc_middle[46ef5772c9c0ed48]::util::bug::bug_fmt
  22:     0x7cd3c7bcb9a4 - <rustc_hir_analysis[f2637e2f8363b2e2]::variance::constraints::ConstraintContext>::add_constraints_from_ty
  23:     0x7cd3c7bca7a6 - <rustc_hir_analysis[f2637e2f8363b2e2]::variance::constraints::ConstraintContext>::build_constraints_for_item
  24:     0x7cd3c541defe - rustc_hir_analysis[f2637e2f8363b2e2]::variance::crate_variances
  25:     0x7cd3c8246f62 - rustc_query_impl[daa0d67e937acf40]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[daa0d67e937acf40]::query_impl::crate_variances::dynamic_query::{closure#2}::{closure#0}, rustc_middle[46ef5772c9c0ed48]::query::erase::Erased<[u8; 8usize]>>
  26:     0x7cd3c82462f4 - rustc_query_system[711a3dc69f9a36dd]::query::plumbing::try_execute_query::<rustc_query_impl[daa0d67e937acf40]::DynamicConfig<rustc_query_system[711a3dc69f9a36dd]::query::caches::SingleCache<rustc_middle[46ef5772c9c0ed48]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[daa0d67e937acf40]::plumbing::QueryCtxt, false>
  27:     0x7cd3c82458a0 - rustc_query_impl[daa0d67e937acf40]::query_impl::crate_variances::get_query_non_incr::__rust_end_short_backtrace
  28:     0x7cd3c7bc8712 - rustc_hir_analysis[f2637e2f8363b2e2]::variance::variances_of
  29:     0x7cd3c7bc8356 - rustc_query_impl[daa0d67e937acf40]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[daa0d67e937acf40]::query_impl::variances_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[46ef5772c9c0ed48]::query::erase::Erased<[u8; 16usize]>>
  30:     0x7cd3c7bc831d - <rustc_query_impl[daa0d67e937acf40]::query_impl::variances_of::dynamic_query::{closure#2} as core[97a31a37f33d2453]::ops::function::FnOnce<(rustc_middle[46ef5772c9c0ed48]::ty::context::TyCtxt, rustc_span[4530179975c83374]::def_id::DefId)>>::call_once
  31:     0x7cd3c7bc668d - rustc_query_system[711a3dc69f9a36dd]::query::plumbing::try_execute_query::<rustc_query_impl[daa0d67e937acf40]::DynamicConfig<rustc_query_system[711a3dc69f9a36dd]::query::caches::DefIdCache<rustc_middle[46ef5772c9c0ed48]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[daa0d67e937acf40]::plumbing::QueryCtxt, false>
  32:     0x7cd3c7bc6221 - rustc_query_impl[daa0d67e937acf40]::query_impl::variances_of::get_query_non_incr::__rust_end_short_backtrace
  33:     0x7cd3c79261e6 - <rustc_borrowck[6a7541c46d4dde04]::type_check::relate_tys::NllTypeRelating as rustc_middle[46ef5772c9c0ed48]::ty::relate::TypeRelation>::relate_item_args
  34:     0x7cd3c792cf56 - <rustc_borrowck[6a7541c46d4dde04]::type_check::relate_tys::NllTypeRelating as rustc_middle[46ef5772c9c0ed48]::ty::relate::TypeRelation>::tys
  35:     0x7cd3c50f6051 - rustc_borrowck[6a7541c46d4dde04]::type_check::type_check
  36:     0x7cd3c4a57b9b - rustc_borrowck[6a7541c46d4dde04]::nll::compute_regions
  37:     0x7cd3c82e948d - rustc_borrowck[6a7541c46d4dde04]::do_mir_borrowck
  38:     0x7cd3c82db708 - rustc_borrowck[6a7541c46d4dde04]::mir_borrowck
  39:     0x7cd3c82db129 - rustc_query_impl[daa0d67e937acf40]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[daa0d67e937acf40]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[46ef5772c9c0ed48]::query::erase::Erased<[u8; 8usize]>>
  40:     0x7cd3c761e3f1 - rustc_query_system[711a3dc69f9a36dd]::query::plumbing::try_execute_query::<rustc_query_impl[daa0d67e937acf40]::DynamicConfig<rustc_query_system[711a3dc69f9a36dd]::query::caches::VecCache<rustc_span[4530179975c83374]::def_id::LocalDefId, rustc_middle[46ef5772c9c0ed48]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[daa0d67e937acf40]::plumbing::QueryCtxt, false>
  41:     0x7cd3c761de4c - rustc_query_impl[daa0d67e937acf40]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
  42:     0x7cd3c7cf186e - rustc_interface[a0b07be1395d4d27]::passes::analysis
  43:     0x7cd3c7cf0a15 - rustc_query_impl[daa0d67e937acf40]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[daa0d67e937acf40]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[46ef5772c9c0ed48]::query::erase::Erased<[u8; 1usize]>>
  44:     0x7cd3c82443a5 - rustc_query_system[711a3dc69f9a36dd]::query::plumbing::try_execute_query::<rustc_query_impl[daa0d67e937acf40]::DynamicConfig<rustc_query_system[711a3dc69f9a36dd]::query::caches::SingleCache<rustc_middle[46ef5772c9c0ed48]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[daa0d67e937acf40]::plumbing::QueryCtxt, false>
  45:     0x7cd3c8244109 - rustc_query_impl[daa0d67e937acf40]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  46:     0x7cd3c80d64d3 - rustc_interface[a0b07be1395d4d27]::interface::run_compiler::<core[97a31a37f33d2453]::result::Result<(), rustc_span[4530179975c83374]::ErrorGuaranteed>, rustc_driver_impl[9c9c8c71a9367b3e]::run_compiler::{closure#0}>::{closure#0}
  47:     0x7cd3c81b295d - std[835e4498f0b3bd88]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[a0b07be1395d4d27]::util::run_in_thread_with_globals<rustc_interface[a0b07be1395d4d27]::util::run_in_thread_pool_with_globals<rustc_interface[a0b07be1395d4d27]::interface::run_compiler<core[97a31a37f33d2453]::result::Result<(), rustc_span[4530179975c83374]::ErrorGuaranteed>, rustc_driver_impl[9c9c8c71a9367b3e]::run_compiler::{closure#0}>::{closure#0}, core[97a31a37f33d2453]::result::Result<(), rustc_span[4530179975c83374]::ErrorGuaranteed>>::{closure#0}, core[97a31a37f33d2453]::result::Result<(), rustc_span[4530179975c83374]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[97a31a37f33d2453]::result::Result<(), rustc_span[4530179975c83374]::ErrorGuaranteed>>
  48:     0x7cd3c81b276a - <<std[835e4498f0b3bd88]::thread::Builder>::spawn_unchecked_<rustc_interface[a0b07be1395d4d27]::util::run_in_thread_with_globals<rustc_interface[a0b07be1395d4d27]::util::run_in_thread_pool_with_globals<rustc_interface[a0b07be1395d4d27]::interface::run_compiler<core[97a31a37f33d2453]::result::Result<(), rustc_span[4530179975c83374]::ErrorGuaranteed>, rustc_driver_impl[9c9c8c71a9367b3e]::run_compiler::{closure#0}>::{closure#0}, core[97a31a37f33d2453]::result::Result<(), rustc_span[4530179975c83374]::ErrorGuaranteed>>::{closure#0}, core[97a31a37f33d2453]::result::Result<(), rustc_span[4530179975c83374]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[97a31a37f33d2453]::result::Result<(), rustc_span[4530179975c83374]::ErrorGuaranteed>>::{closure#2} as core[97a31a37f33d2453]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  49:     0x7cd3c96f795b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha1eb23a81eb586ce
                               at /rustc/7106800e16085bf1805cc8e75866ed0f0efd85d9/library/alloc/src/boxed.rs:2018:9
  50:     0x7cd3c96f795b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hdbc074edfd37bb32
                               at /rustc/7106800e16085bf1805cc8e75866ed0f0efd85d9/library/alloc/src/boxed.rs:2018:9
  51:     0x7cd3c96f795b - std::sys::pal::unix::thread::Thread::new::thread_start::hdd0799c5e968fab1
                               at /rustc/7106800e16085bf1805cc8e75866ed0f0efd85d9/library/std/src/sys/pal/unix/thread.rs:108:17
  52:     0x7cd3c2ea955a - <unknown>
  53:     0x7cd3c2f26a3c - <unknown>
  54:                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 (7106800e1 2024-04-13) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [crate_variances] computing the variances for items in this crate
#1 [variances_of] computing the variances of `T`
#2 [mir_borrowck] borrow-checking `g`
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 7 previous errors; 2 warnings emitted

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

@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 13, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 13, 2024
@matthiaskrgr
Copy link
Member Author

smaller

pub struct T<'g>();

pub fn g(val: T) {}

pub fn f<a>() -> _ {
   g
}

@matthiaskrgr
Copy link
Member Author

ice since #117449 it seems

@compiler-errors
Copy link
Member

i can look into this

@rustbot claim

@jieyouxu jieyouxu added A-diagnostics Area: Messages for errors, warnings, and lints A-inference Area: Type inference A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue A-HIR Area: The high-level intermediate representation (HIR) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 15, 2024
jieyouxu added a commit to jieyouxu/rust that referenced this issue Apr 15, 2024
…es, r=fmease

Don't leak unnameable types in `-> _` recover

Fixes rust-lang#123899
@bors bors closed this as completed in 313b02a Apr 15, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 15, 2024
Rollup merge of rust-lang#123931 - compiler-errors:variance-unnameables, r=fmease

Don't leak unnameable types in `-> _` recover

Fixes rust-lang#123899
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-HIR Area: The high-level intermediate representation (HIR) A-inference Area: Type inference A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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