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

Anonymous f64 generic parameters causes compiler panic #98813

Closed
peku33 opened this issue Jul 2, 2022 · 1 comment · Fixed by #98907
Closed

Anonymous f64 generic parameters causes compiler panic #98813

peku33 opened this issue Jul 2, 2022 · 1 comment · Fixed by #98907
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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.

Comments

@peku33
Copy link

peku33 commented Jul 2, 2022

When anonymous value is used as generic parameter, the compiler panics with thread 'rustc' panicked at 'Box<dyn Any>', compiler\rustc_errors\src\lib.rs:1425:13.

However if a value is bound to a const variable, it works.

Code

#![feature(adt_const_params)]

const ZERO: f64 = 0.0;

pub struct Foo<const X: f64> {}

fn main() {
    let _ = Foo::<0.0> {}; // fails
    let _ = Foo::<ZERO> {}; // passes
}

Meta

rustc --version --verbose:

rustc 1.64.0-nightly (46b8c23f3 2022-07-01)
binary: rustc
commit-hash: 46b8c23f3eb5e4d0e0aa27eb3f20d5b8fc3ed51f
commit-date: 2022-07-01
host: x86_64-pc-windows-msvc
release: 1.64.0-nightly
LLVM version: 14.0.6

Error output

warning: Error finalizing incremental compilation session directory (...)

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: Const::from_anon_const: couldn't lit_to_const TypeError
 --> src\main.rs:6:19
  |
6 |     let _ = Foo::<0.0> {};
  |                   ^^^
  |
  = note: delayed at compiler\rustc_middle\src\ty\consts.rs:128:30

thread 'rustc' panicked at 'Box<dyn Any>', compiler\rustc_errors\src\lib.rs:1425:13
stack backtrace:
   0:     0x7fffcceea08f - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::haf1ad183bbfbc238
   1:     0x7fffccf2454a - core::fmt::write::ha9a2f4b5fc2cd03e
   2:     0x7fffccedc589 - <std::io::IoSliceMut as core::fmt::Debug>::fmt::h934bac5f9f732b9e
   3:     0x7fffcceed97b - std::panicking::default_hook::hf57e8e79b218be44
   4:     0x7fffcceed5fb - std::panicking::default_hook::hf57e8e79b218be44
   5:     0x7fffcd517186 - rustc_driver[5cf3877d393213b7]::pretty::print_after_hir_lowering
   6:     0x7fffcceee122 - std::panicking::rust_panic_with_hook::hd2f9d78204050d72
   7:     0x7fffd1d13905 - <rustc_errors[768570d7a0d53115]::snippet::Style as core[179685c4f861d119]::fmt::Debug>::fmt
   8:     0x7fffd1d0f889 - <rustc_errors[768570d7a0d53115]::snippet::Style as core[179685c4f861d119]::fmt::Debug>::fmt
   9:     0x7fffd2057b69 - rustc_query_system[598cd9cddcda72da]::query::job::report_cycle
  10:     0x7fffd1cbee69 - <rustc_feature[4dbba36b93aa7032]::builtin_attrs::AttributeType as core[179685c4f861d119]::fmt::Debug>::fmt
  11:     0x7fffd1cc2bac - <rustc_errors[768570d7a0d53115]::HandlerInner as core[179685c4f861d119]::ops::drop::Drop>::drop
  12:     0x7fffcd4919d4 - <chalk_engine[44566aa7495cc23f]::TableIndex>::increment
  13:     0x7fffcd49ca9a - <chalk_engine[44566aa7495cc23f]::TableIndex>::increment
  14:     0x7fffcd52812d - <rustc_driver[5cf3877d393213b7]::Compilation as core[179685c4f861d119]::fmt::Debug>::fmt
  15:     0x7fffcd525b39 - <rustc_driver[5cf3877d393213b7]::Compilation as core[179685c4f861d119]::fmt::Debug>::fmt
  16:     0x7fffcd4a63ed - <chalk_engine[44566aa7495cc23f]::TableIndex>::increment
  17:     0x7fffcd4d0186 - <rustc_driver[5cf3877d393213b7]::args::Error as core[179685c4f861d119]::fmt::Debug>::fmt
  18:     0x7fffcd4d0a08 - <rustc_driver[5cf3877d393213b7]::args::Error as core[179685c4f861d119]::fmt::Debug>::fmt
  19:     0x7fffccefe8fc - std::sys::windows::thread::Thread::new::h9a2ca89e45b8574f
  20:     0x7ff84b087034 - BaseThreadInitThunk
  21:     0x7ff84cf82651 - RtlUserThreadStart

note: the compiler unexpectedly panicked. this is a bug.
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.64.0-nightly (46b8c23f3 2022-07-01) running on x86_64-pc-windows-msvc

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
warning: `rustc-bug-const-generic` (bin "rustc-bug-const-generic") generated 2 warnings
error: could not compile `rustc-bug-const-generic`; 2 warnings emitted
@peku33 peku33 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 Jul 2, 2022
matthiaskrgr added a commit to matthiaskrgr/glacier that referenced this issue Jul 3, 2022
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jul 3, 2022
@RalfJung
Copy link
Member

RalfJung commented Jul 5, 2022

See #98825 (comment) some relevant discussion. In particular

ideally we shouldn't be able to use floats in a const generic to begin with...

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jul 11, 2022
…-obk

Deny float const params even when `adt_const_params` is enabled

Supersedes rust-lang#98825
Fixes rust-lang#98813

r? `@oli-obk`
@bors bors closed this as completed in 92b8adf Jul 11, 2022
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. glacier ICE tracked in rust-lang/glacier. 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.
Projects
None yet
3 participants