Repository navigation
ICE upvar_tys called before capture types are inferred #162440
Copy link
Copy link
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-trait-system-refactorThe Rustc Trait System Refactor Initiative (-Znext-solver)The Rustc Trait System Refactor Initiative (-Znext-solver)regression-untriagedUntriaged performance or correctness regression.Untriaged performance or correctness regression.
Description
snippet:
fn main() {
Some([0]).map(|s| s[..]);
}Version information
rustc 1.100.0-nightly (752b9bf87 2026-09-07)
binary: rustc
commit-hash: 752b9bf8798c2ffc1d3fe2b804c04454366fc6d6
commit-date: 2026-09-07
host: x86_64-unknown-linux-gnu
release: 1.100.0-nightly
LLVM version: 23.1.1
Possibly related line of code:
rust/compiler/rustc_middle/src/ty/sty.rs
Lines 194 to 206 in 752b9bf
| UpvarArgs::CoroutineClosure(args) => args.as_coroutine_closure().tupled_upvars_ty(), | |
| }; | |
| match tupled_tys.kind() { | |
| TyKind::Error(_) => ty::List::empty(), | |
| TyKind::Tuple(..) => self.tupled_upvars_ty().tuple_fields(), | |
| TyKind::Infer(_) => bug!("upvar_tys called before capture types are inferred"), | |
| ty => bug!("Unexpected representation of upvar types tuple {:?}", ty), | |
| } | |
| } | |
| #[inline] | |
| pub fn tupled_upvars_ty(self) -> Ty<'tcx> { |
Command:
/home/matthias/.rustup/toolchains/master/bin/rustc
Program output
error[E0277]: the size for values of type `[{integer}]` cannot be known at compilation time
--> /tmp/icemaker_global_tempdir.y4oxhmSBkaRU/rustc_testrunner_tmpdir_reporting.4aRXUhCYUxEe/mvce.rs:2:15
|
2 | Some([0]).map(|s| s[..]);
| ^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `[{integer}]`
note: required by an implicit `Sized` bound in `Option::<T>::map`
--> /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/core/src/option.rs:1160:22
|
1160 | pub const fn map<U, F>(self, f: F) -> Option<U>
| ^ required by the implicit `Sized` requirement on this type parameter in `Option::<T>::map`
error[E0277]: the size for values of type `[{integer}]` cannot be known at compilation time
--> /tmp/icemaker_global_tempdir.y4oxhmSBkaRU/rustc_testrunner_tmpdir_reporting.4aRXUhCYUxEe/mvce.rs:2:23
|
2 | Some([0]).map(|s| s[..]);
| ^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `[{integer}]`
= note: the return type of a function must have a statically known size
error: internal compiler error: /rustc-dev/752b9bf8798c2ffc1d3fe2b804c04454366fc6d6/compiler/rustc_middle/src/ty/sty.rs:200:33: upvar_tys called before capture types are inferred
thread 'rustc' (2995014) panicked at /rustc-dev/752b9bf8798c2ffc1d3fe2b804c04454366fc6d6/compiler/rustc_middle/src/ty/sty.rs:200:33:
Box<dyn Any>
stack backtrace:
0: 0x7f6b7ead5b46 - <<std[7799338267317a1]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[feb819e0aab98535]::fmt::Display>::fmt
1: 0x7f6b7f2081cf - core[feb819e0aab98535]::fmt::write
2: 0x7f6b7eaeac0c - <std[7799338267317a1]::sys::stdio::unix::Stderr as core[feb819e0aab98535]::io::write::Write>::write_fmt
3: 0x7f6b7eaa83ea - std[7799338267317a1]::panicking::default_hook::{closure#0}
4: 0x7f6b7eac9e43 - std[7799338267317a1]::panicking::default_hook
5: 0x7f6b7da1338f - std[7799338267317a1]::panicking::update_hook::<alloc[eddc929262330b86]::boxed::Box<rustc_driver_impl[93e22c4ae85d6128]::install_ice_hook::{closure#1}>>::{closure#0}
6: 0x7f6b7eaca2e2 - std[7799338267317a1]::panicking::panic_with_hook
7: 0x7f6b7da41c44 - std[7799338267317a1]::panicking::begin_panic::<rustc_errors[ccb98f0a5bff281a]::ExplicitBug>::{closure#0}
8: 0x7f6b7da3a71e - std[7799338267317a1]::sys::backtrace::__rust_end_short_backtrace::<std[7799338267317a1]::panicking::begin_panic<rustc_errors[ccb98f0a5bff281a]::ExplicitBug>::{closure#0}, !>
9: 0x7f6b7da387be - std[7799338267317a1]::panicking::begin_panic::<rustc_errors[ccb98f0a5bff281a]::ExplicitBug>
10: 0x7f6b7da4d511 - <rustc_errors[ccb98f0a5bff281a]::diagnostic::BugAbort as rustc_errors[ccb98f0a5bff281a]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
11: 0x7f6b7dff4cb9 - rustc_middle[95f7c36db503aa5c]::util::bug::opt_span_bug_fmt::<rustc_span[aab65db9cf037f3]::span_encoding::Span>::{closure#0}
12: 0x7f6b7dff50f2 - rustc_middle[95f7c36db503aa5c]::ty::context::tls::with_opt::<rustc_middle[95f7c36db503aa5c]::util::bug::opt_span_bug_fmt<rustc_span[aab65db9cf037f3]::span_encoding::Span>::{closure#0}, !>::{closure#0}
13: 0x7f6b7dfdfeb0 - rustc_middle[95f7c36db503aa5c]::ty::context::tls::with_context_opt::<rustc_middle[95f7c36db503aa5c]::ty::context::tls::with_opt<rustc_middle[95f7c36db503aa5c]::util::bug::opt_span_bug_fmt<rustc_span[aab65db9cf037f3]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
14: 0x7f6b7aca83d4 - rustc_middle[95f7c36db503aa5c]::util::bug::bug_fmt
15: 0x7f6b7e7e4b70 - <rustc_trait_selection[b2c49a93e168dccb]::error_reporting::TypeErrCtxt>::note_closure_capture::<rustc_span[aab65db9cf037f3]::ErrorGuaranteed>
16: 0x7f6b7e7f9e1f - <rustc_trait_selection[b2c49a93e168dccb]::error_reporting::TypeErrCtxt>::note_obligation_cause_code_inner::<rustc_span[aab65db9cf037f3]::ErrorGuaranteed, rustc_middle[95f7c36db503aa5c]::ty::predicate::Predicate>
17: 0x7f6b7e7e4c36 - <rustc_trait_selection[b2c49a93e168dccb]::error_reporting::TypeErrCtxt>::note_obligation_cause_code::<rustc_span[aab65db9cf037f3]::ErrorGuaranteed, rustc_middle[95f7c36db503aa5c]::ty::predicate::Predicate>
18: 0x7f6b7e8f1d1c - <rustc_trait_selection[b2c49a93e168dccb]::error_reporting::TypeErrCtxt>::note_obligation_cause
19: 0x7f6b7e8de797 - <rustc_trait_selection[b2c49a93e168dccb]::error_reporting::TypeErrCtxt>::report_selection_error
20: 0x7f6b7e905fc9 - <rustc_trait_selection[b2c49a93e168dccb]::error_reporting::TypeErrCtxt>::report_fulfillment_error
21: 0x7f6b7d298d3c - <rustc_trait_selection[b2c49a93e168dccb]::error_reporting::TypeErrCtxt>::report_fulfillment_errors
22: 0x7f6b7f2f3426 - <rustc_hir_typeck[74465e21f53f1374]::fn_ctxt::FnCtxt>::resolve_vars_with_obligations::<rustc_middle[95f7c36db503aa5c]::ty::Ty>
23: 0x7f6b7fd33cde - <rustc_hir_typeck[74465e21f53f1374]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
24: 0x7f6b7fd28105 - <rustc_hir_typeck[74465e21f53f1374]::fn_ctxt::FnCtxt>::check_expr_block
25: 0x7f6b7fd2f155 - <rustc_hir_typeck[74465e21f53f1374]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
26: 0x7f6b7fd13258 - rustc_hir_typeck[74465e21f53f1374]::check::check_fn
27: 0x7f6b8067a55b - rustc_hir_typeck[74465e21f53f1374]::typeck_with_inspect::{closure#0}
28: 0x7f6b80678b7a - rustc_query_impl[bdd1a1285068393]::query_vtables::typeck_root::invoke_provider_fn::__rust_begin_short_backtrace
29: 0x7f6b7f879535 - rustc_query_impl[bdd1a1285068393]::execution::try_execute_query::<rustc_data_structures[b3e0016b95cb4620]::vec_cache::VecCache<rustc_span[aab65db9cf037f3]::def_id::LocalDefId, rustc_middle[95f7c36db503aa5c]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[95f7c36db503aa5c]::dep_graph::graph::DepNodeIndex>, false>
30: 0x7f6b7f879167 - rustc_query_impl[bdd1a1285068393]::query_vtables::typeck_root::execute_query_non_incr::__rust_end_short_backtrace
31: 0x7f6b7f93566f - <rustc_middle[95f7c36db503aa5c]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis[3f6e10ab2280337c]::check_crate::{closure#1}>::{closure#0}
32: 0x7f6b7f93492e - rustc_hir_analysis[3f6e10ab2280337c]::check_crate
33: 0x7f6b7f87aaf3 - rustc_interface[1845d939591a8dca]::passes::analysis
34: 0x7f6b8049d7ca - rustc_query_impl[bdd1a1285068393]::execution::try_execute_query::<rustc_middle[95f7c36db503aa5c]::query::caches::SingleCache<rustc_middle[95f7c36db503aa5c]::query::erase::ErasedData<[u8; 0usize]>>, false>
35: 0x7f6b8049d56b - rustc_query_impl[bdd1a1285068393]::query_vtables::analysis::execute_query_non_incr::__rust_end_short_backtrace
36: 0x7f6b8054bb4c - rustc_interface[1845d939591a8dca]::interface::run_compiler::<(), rustc_driver_impl[93e22c4ae85d6128]::run_compiler::{closure#0}>::{closure#2}
37: 0x7f6b80628f42 - std[7799338267317a1]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[1845d939591a8dca]::util::run_in_thread_with_globals<rustc_interface[1845d939591a8dca]::util::run_in_thread_pool_with_globals<rustc_interface[1845d939591a8dca]::interface::run_compiler<(), rustc_driver_impl[93e22c4ae85d6128]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
38: 0x7f6b80628ced - <std[7799338267317a1]::thread::lifecycle::spawn_unchecked<rustc_interface[1845d939591a8dca]::util::run_in_thread_with_globals<rustc_interface[1845d939591a8dca]::util::run_in_thread_pool_with_globals<rustc_interface[1845d939591a8dca]::interface::run_compiler<(), rustc_driver_impl[93e22c4ae85d6128]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[feb819e0aab98535]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
39: 0x7f6b80631607 - <std[7799338267317a1]::sys::thread::unix::Thread>::new::thread_start
40: 0x7f6b796980a2 - <unknown>
41: 0x7f6b7972080c - <unknown>
42: 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.100.0-nightly (752b9bf87 2026-09-07) running on x86_64-unknown-linux-gnu
query stack during panic:
#0 [typeck_root] type-checking `main`
#1 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0277`.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-trait-system-refactorThe Rustc Trait System Refactor Initiative (-Znext-solver)The Rustc Trait System Refactor Initiative (-Znext-solver)regression-untriagedUntriaged performance or correctness regression.Untriaged performance or correctness regression.
Activity
matthiaskrgr commentedon Sep 7, 2026
yesterday:
today:
my guess would be its related to #161624
lcnr commentedon Sep 8, 2026
https://rust-lang.zulipchat.com/#narrow/channel/618216-t-types.2Fcall-for-participation/topic/incorrectly.20accessing.20upvars.20in.20diagnostics.20code/with/622511748
matthiaskrgr commentedon Sep 8, 2026
Ooh its a next-solver thing! >.<
I was wondering how this could have passed in our testsuite without ICEing but we use coherence there :/
Rollup merge of rust-lang#162489 - chenyukang:yukang-refactor-upvar_t…
Rollup merge of rust-lang#162489 - chenyukang:yukang-refactor-upvar_t…
Unrolled build for #162489 in rollup 162503
BuilderEd commentedon Sep 19, 2026
Another reproducer for this ICE, found by an automated compiler-testing
campaign; sharing in case it is a useful extra test case for #162595.
Expected: the two pattern errors (
rest @is not allowed in a tuple,..patterns are not allowed here) and a clean rejection. Actual: additionallywith the same backtrace path as the original report
(
note_closure_capture->note_obligation_cause_code_inner->report_selection_error->report_fulfillment_errors).Versions tested:
CoerceUnsized errors on the closures, no ICE). I did not test the
issue-body snippet on this toolchain; it is reported against a master
build of the same date (752b9bf)
The reproducer combines two ingredients: a closure coerced to
&dyn Fninside a macro-generated trait method, and the invalid tuple pattern
elsewhere in the crate. I did not isolate which ingredient drives error
reporting into
note_closure_capturebefore capture types are inferred(the issue-body snippet ICEs without any pattern error, so the closure
error path may be the driver here too). Happy to file this as a separate
issue if the trigger turns out to be distinct.
rustc_middle/src/ty/sty.rs:194:33#163072 as a duplicate of this issueRashingPro commentedon Sep 21, 2026
#163072 contains another code snippet triggering this, just in case
Rollup merge of rust-lang#162595 - amirHdev:uninferred-upvars, r=lcnr
Unrolled build for #162595 in rollup 163265
Rollup merge of #162595 - amirHdev:uninferred-upvars, r=lcnr
Rollup merge of #162595 - amirHdev:uninferred-upvars, r=lcnr