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 when specifying wrong return type for closure in static item #130858

Closed
rgwood-dd opened this issue Sep 25, 2024 · 1 comment · Fixed by #130879
Closed

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

rgwood-dd opened this issue Sep 25, 2024 · 1 comment · Fixed by #130879
Assignees
Labels
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

@rgwood-dd
Copy link

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")

@rgwood-dd rgwood-dd added C-bug Category: This is a bug. 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. labels Sep 25, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 25, 2024
@cyrgani
Copy link
Contributor

cyrgani commented Sep 26, 2024

Reduced:

static FOO: fn() = || -> bool { 1 };

@fmease fmease added S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Sep 26, 2024
@fmease fmease self-assigned this Sep 26, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Sep 26, 2024
…rors

Pass correct HirId to late_bound_vars in diagnostic code

Fixes rust-lang#130858.
Fixes rust-lang#125655.
Fixes rust-lang#130391.
Fixes rust-lang#130663.

r? compiler-errors
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Sep 26, 2024
…rors

Pass correct HirId to late_bound_vars in diagnostic code

Fixes rust-lang#130858.
Fixes rust-lang#125655.
Fixes rust-lang#130391.
Fixes rust-lang#130663.

r? compiler-errors
@bors bors closed this as completed in ed902a8 Sep 27, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Sep 27, 2024
Rollup merge of rust-lang#130879 - fmease:fix-diag-ice, r=compiler-errors

Pass correct HirId to late_bound_vars in diagnostic code

Fixes rust-lang#130858.
Fixes rust-lang#125655.
Fixes rust-lang#130391.
Fixes rust-lang#130663.

r? compiler-errors
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-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