Skip to content

ICE when specifying wrong return type for closure in static item #130858

@rgwood-dd

Description

@rgwood-dd

This is a pretty minor ICE that I can only reproduce in code that shouldn't compile anyway. If I specify the wrong return type for a closure used in a static item, I get an ICE instead of a normal build error.

Possibly related to #125655

Code

Add this to any main.rs:

use std::sync::LazyLock; static FOO: LazyLock<i64> = LazyLock::new(|| -> String { 3 });

Meta

rustc --version --verbose:

rustc 1.81.0 (eeb90cda1 2024-09-04) binary: rustc commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c commit-date: 2024-09-04 host: aarch64-apple-darwin release: 1.81.0 LLVM version: 18.1.7 

I can also reproduce this on latest nightly (rustc 1.83.0-nightly (363ae4188 2024-09-24) I believe, ran it with cargo +nightly run).

Error output

error: internal compiler error: compiler/rustc_middle/src/ty/context.rs:3016:21: No bound vars found for HirId(DefId(0:4 ~ ice_repro[b95c]::FOO).0) (static FOO) thread 'rustc' panicked at compiler/rustc_middle/src/ty/context.rs:3016:21: Box<dyn Any> 
Backtrace

stack backtrace: 0: std::panicking::begin_panic::<rustc_errors::ExplicitBug> 1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee 2: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0} 3: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0} 4: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !> 5: rustc_middle::util::bug::bug_fmt 6: <rustc_middle::ty::context::TyCtxt>::late_bound_vars 7: <rustc_hir_typeck::fn_ctxt::FnCtxt>::suggest_missing_return_type 8: <rustc_hir_typeck::coercion::CoerceMany<rustc_hir::hir::Arm>>::report_return_mismatched_types 9: <rustc_hir_typeck::coercion::CoerceMany<&rustc_hir::hir::Expr>>::coerce_inner::<<rustc_hir_typeck::fn_ctxt::FnCtxt>::check_block_with_expected::{closure#0}::{closure#1}> 10: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_block_with_expected 11: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args 12: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_return_expr 13: rustc_hir_typeck::check::check_fn 14: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_kind 15: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args 16: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_argument_types 17: <rustc_hir_typeck::fn_ctxt::FnCtxt>::confirm_builtin_call 18: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_kind 19: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args 20: rustc_hir_typeck::typeck [... omitted 2 frames ...] 21: rustc_hir_analysis::check::check::check_item_type 22: rustc_hir_analysis::check::wfcheck::check_well_formed [... omitted 2 frames ...] 23: <rustc_data_structures::sync::parallel::ParallelGuard>::run::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_data_structures::sync::parallel::disabled::try_par_for_each_in<&[rustc_hir::hir::ImplItemId], rustc_span::ErrorGuaranteed, <rustc_middle::hir::ModuleItems>::par_impl_items<rustc_hir_analysis::check::wfcheck::check_mod_type_wf::{closure#1}>::{closure#0}>::{closure#0}::{closure#0}::{closure#0}> 24: rustc_hir_analysis::check::wfcheck::check_mod_type_wf [... omitted 2 frames ...] 25: <rustc_data_structures::sync::parallel::ParallelGuard>::run::<(), rustc_data_structures::sync::parallel::disabled::par_for_each_in<&[rustc_hir::hir_id::OwnerId], <rustc_middle::hir::map::Map>::par_for_each_module<rustc_hir_analysis::check_crate::{closure#0}::{closure#0}>::{closure#0}>::{closure#0}::{closure#0}::{closure#0}> 26: <rustc_session::session::Session>::time::<(), rustc_hir_analysis::check_crate::{closure#0}> 27: rustc_hir_analysis::check_crate 28: rustc_interface::passes::analysis [... omitted 2 frames ...] 29: <rustc_interface::queries::QueryResult<&rustc_middle::ty::context::GlobalCtxt>>::enter::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}::{closure#5}> 30: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#0}::{closure#1}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>> 31: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>> 32: rustc_span::create_session_globals_then::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_interface::util::run_in_thread_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}> note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. 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: rustc 1.81.0 (eeb90cda1 2024-09-04) running on aarch64-apple-darwin note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked -C incremental=[REDACTED] note: some of the compiler flags provided by cargo are hidden query stack during panic: #0 [typeck] type-checking `FOO` #1 [check_well_formed] checking that `FOO` is well-formed #2 [check_mod_type_wf] checking that types are well-formed in top-level module #3 [analysis] running analysis passes on this crate end of query stack error: could not compile `ice-repro` (bin "ice-repro") 

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-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