Skip to content

ICE: Got a scalar pair where a scalar was expected when using the Self on fn, a wrong place. #140365

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

Open
TsiyukiRitsuki opened this issue Apr 27, 2025 · 1 comment
Labels
-Zvalidate-mir Unstable option: MIR validation C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@TsiyukiRitsuki
Copy link

TsiyukiRitsuki commented Apr 27, 2025

A really similar case I found is: #135128
But I think they are different, as when trying the code in that issue, it didn't panic in the latest rustc: 1.88.0-nightly, but mine does.

Code

fn f() -> &'static str
where
    Self: Sized,
{
    ""
}

Command: rustc -C opt-level=1 -Zvalidate-mir

Meta

rustc --version --verbose:

rustc 1.88.0-nightly (10fa3c449 2025-04-26)
binary: rustc
commit-hash: 10fa3c449f6b1613b352a6cbf78d3d91fd9a1d81
commit-date: 2025-04-26
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2

Error output

error[E0411]: cannot find type `Self` in this scope
 --> test/tmp.rs:3:5
  |
1 | fn f() -> &'static str
  |    - `Self` not allowed in a function
2 | where
3 |     Self: Sized,
  |     ^^^^ `Self` is only available in impls, traits, and type definitions

error: internal compiler error: /rustc/10fa3c449f6b1613b352a6cbf78d3d91fd9a1d81/compiler/rustc_const_eval/src/interpret/operand.rs:84:42: Got a scalar pair where a scalar was expected


thread 'rustc' panicked at /rustc/10fa3c449f6b1613b352a6cbf78d3d91fd9a1d81/compiler/rustc_const_eval/src/interpret/operand.rs:84:42:
Box<dyn Any>
Backtrace

error[E0411]: cannot find type `Self` in this scope
 --> test/tmp.rs:3:5
  |
1 | fn f() -> &'static str
  |    - `Self` not allowed in a function
2 | where
3 |     Self: Sized,
  |     ^^^^ `Self` is only available in impls, traits, and type definitions

error: internal compiler error: /rustc/10fa3c449f6b1613b352a6cbf78d3d91fd9a1d81/compiler/rustc_const_eval/src/interpret/operand.rs:84:42: Got a scalar pair where a scalar was expected


thread 'rustc' panicked at /rustc/10fa3c449f6b1613b352a6cbf78d3d91fd9a1d81/compiler/rustc_const_eval/src/interpret/operand.rs:84:42:
Box<dyn Any>
stack backtrace:
   0:     0x7837b4ce90f3 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::he1cc6de51b8e3e46
   1:     0x7837b5405ac7 - core::fmt::write::h546351ef89cac2c3
   2:     0x7837b683e6d1 - std::io::Write::write_fmt::hdd0a9df47aae8e9f
   3:     0x7837b4ce8f52 - std::sys::backtrace::BacktraceLock::print::h575bf1241b79e77a
   4:     0x7837b4cecd9a - std::panicking::default_hook::{{closure}}::h9889804a123e7c5b
   5:     0x7837b4cec91f - std::panicking::default_hook::h0459a96a46f07fba
   6:     0x7837b3d710d3 - std[799ab5ff8c92313d]::panicking::update_hook::<alloc[8b075dae1d9a4a4]::boxed::Box<rustc_driver_impl[8ffa39a1f100e9bb]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7837b4ced613 - std::panicking::rust_panic_with_hook::hb01102643345a267
   8:     0x7837b3dacac1 - std[799ab5ff8c92313d]::panicking::begin_panic::<rustc_errors[3ee20515ee49c7f0]::ExplicitBug>::{closure#0}
   9:     0x7837b3da0af6 - std[799ab5ff8c92313d]::sys::backtrace::__rust_end_short_backtrace::<std[799ab5ff8c92313d]::panicking::begin_panic<rustc_errors[3ee20515ee49c7f0]::ExplicitBug>::{closure#0}, !>
  10:     0x7837b3da097b - std[799ab5ff8c92313d]::panicking::begin_panic::<rustc_errors[3ee20515ee49c7f0]::ExplicitBug>
  11:     0x7837b3db6fb1 - <rustc_errors[3ee20515ee49c7f0]::diagnostic::BugAbort as rustc_errors[3ee20515ee49c7f0]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x7837b43f1f9a - rustc_middle[d1b324fb2b9fb44f]::util::bug::opt_span_bug_fmt::<rustc_span[9169b51a7177056a]::span_encoding::Span>::{closure#0}
  13:     0x7837b43ccdfa - rustc_middle[d1b324fb2b9fb44f]::ty::context::tls::with_opt::<rustc_middle[d1b324fb2b9fb44f]::util::bug::opt_span_bug_fmt<rustc_span[9169b51a7177056a]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x7837b43ccc6b - rustc_middle[d1b324fb2b9fb44f]::ty::context::tls::with_context_opt::<rustc_middle[d1b324fb2b9fb44f]::ty::context::tls::with_opt<rustc_middle[d1b324fb2b9fb44f]::util::bug::opt_span_bug_fmt<rustc_span[9169b51a7177056a]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7837b168a6c0 - rustc_middle[d1b324fb2b9fb44f]::util::bug::bug_fmt
  16:     0x7837b2ad897c - <rustc_mir_transform[b9389225760552bd]::gvn::VnState as rustc_middle[d1b324fb2b9fb44f]::mir::visit::MutVisitor>::visit_statement
  17:     0x7837b2acea5b - <rustc_mir_transform[b9389225760552bd]::gvn::GVN as rustc_mir_transform[b9389225760552bd]::pass_manager::MirPass>::run_pass
  18:     0x7837b54039fb - rustc_mir_transform[b9389225760552bd]::pass_manager::run_passes_inner
  19:     0x7837b5d87c1f - rustc_mir_transform[b9389225760552bd]::optimized_mir
  20:     0x7837b5d8720d - rustc_query_impl[5054593ac04cc94b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[5054593ac04cc94b]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d1b324fb2b9fb44f]::query::erase::Erased<[u8; 8usize]>>
  21:     0x7837b57b646f - rustc_query_system[868e915c35b94eeb]::query::plumbing::try_execute_query::<rustc_query_impl[5054593ac04cc94b]::DynamicConfig<rustc_query_system[868e915c35b94eeb]::query::caches::DefIdCache<rustc_middle[d1b324fb2b9fb44f]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[5054593ac04cc94b]::plumbing::QueryCtxt, false>
  22:     0x7837b57b589d - rustc_query_impl[5054593ac04cc94b]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  23:     0x7837b58d782f - <rustc_middle[d1b324fb2b9fb44f]::ty::context::TyCtxt>::instance_mir
  24:     0x7837b5ef588c - rustc_interface[4f0825a59a6ff88a]::passes::run_required_analyses
  25:     0x7837b62d7c5e - rustc_interface[4f0825a59a6ff88a]::passes::analysis
  26:     0x7837b62d7c2d - rustc_query_impl[5054593ac04cc94b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[5054593ac04cc94b]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d1b324fb2b9fb44f]::query::erase::Erased<[u8; 0usize]>>
  27:     0x7837b62dd73d - rustc_query_system[868e915c35b94eeb]::query::plumbing::try_execute_query::<rustc_query_impl[5054593ac04cc94b]::DynamicConfig<rustc_query_system[868e915c35b94eeb]::query::caches::SingleCache<rustc_middle[d1b324fb2b9fb44f]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[5054593ac04cc94b]::plumbing::QueryCtxt, false>
  28:     0x7837b62dd438 - rustc_query_impl[5054593ac04cc94b]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  29:     0x7837b66341c0 - rustc_interface[4f0825a59a6ff88a]::passes::create_and_enter_global_ctxt::<core[30c64d6a260d8eb8]::option::Option<rustc_interface[4f0825a59a6ff88a]::queries::Linker>, rustc_driver_impl[8ffa39a1f100e9bb]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  30:     0x7837b64aeb84 - rustc_interface[4f0825a59a6ff88a]::interface::run_compiler::<(), rustc_driver_impl[8ffa39a1f100e9bb]::run_compiler::{closure#0}>::{closure#1}
  31:     0x7837b6353b28 - std[799ab5ff8c92313d]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[4f0825a59a6ff88a]::util::run_in_thread_with_globals<rustc_interface[4f0825a59a6ff88a]::util::run_in_thread_pool_with_globals<rustc_interface[4f0825a59a6ff88a]::interface::run_compiler<(), rustc_driver_impl[8ffa39a1f100e9bb]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  32:     0x7837b6353f74 - <<std[799ab5ff8c92313d]::thread::Builder>::spawn_unchecked_<rustc_interface[4f0825a59a6ff88a]::util::run_in_thread_with_globals<rustc_interface[4f0825a59a6ff88a]::util::run_in_thread_pool_with_globals<rustc_interface[4f0825a59a6ff88a]::interface::run_compiler<(), rustc_driver_impl[8ffa39a1f100e9bb]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[30c64d6a260d8eb8]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  33:     0x7837b6355377 - std::sys::pal::unix::thread::Thread::new::thread_start::h6104b903ae36f332
  34:     0x7837b02a3708 - <unknown>
  35:     0x7837b0327aac - <unknown>
  36:                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.88.0-nightly (10fa3c449 2025-04-26) running on x86_64-unknown-linux-gnu

note: compiler flags: -C opt-level=3 -Z no-codegen -Z validate-mir --crate-type lib

query stack during panic:
#0 [optimized_mir] optimizing MIR for `f`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0411`.

@TsiyukiRitsuki TsiyukiRitsuki 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 Apr 27, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 27, 2025
@theemathas
Copy link
Contributor

@rustbot labels +-Zvalidate-mir

@rustbot rustbot added the -Zvalidate-mir Unstable option: MIR validation label Apr 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-Zvalidate-mir Unstable option: MIR validation C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants