Skip to content

ICE: rustdoc on issue-70453-generics-in-discr-ice-2.rs: enum discriminant depends on generics #79495

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
matthiaskrgr opened this issue Nov 28, 2020 · 7 comments
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) ❄️ P-low Low priority T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Nov 28, 2020

Code

code from ./src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice-2.rs

#![feature(arbitrary_enum_discriminant, generic_const_exprs, core_intrinsics)]

extern crate core;
use core::intrinsics::discriminant_value;

#[repr(usize)]
enum MyWeirdOption<T> {
    None = 0,
    Some(T) = std::mem::size_of::<T>(),
    //~^ ERROR constant expression depends on a generic parameter
}

fn main() {
    assert_eq!(discriminant_value(&MyWeirdOption::<u8>::None), 0);
    assert_eq!(discriminant_value(&MyWeirdOption::Some(0u8)), 1);
}

Meta

rustc --version --verbose:

rustdoc 1.50.0-nightly (1c389ffef 2020-11-24)
binary: rustdoc
commit-hash: 1c389ffeff814726dec325f0f2b0c99107df2673
commit-date: 2020-11-24
host: x86_64-unknown-linux-gnu
release: 1.50.0-nightly

Error output

error: internal compiler error: enum discriminant depends on generics
 --> ./src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice-2.rs:9:15
  |
9 |     Some(T) = std::mem::size_of::<T>(),
  |               ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: delayed at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/compiler/rustc_middle/src/ty/mod.rs:2611:26

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:974:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

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.50.0-nightly (1c389ffef 2020-11-24) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack
Backtrace

error: internal compiler error: enum discriminant depends on generics
 --> ./src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice-2.rs:9:15
  |
9 |     Some(T) = std::mem::size_of::<T>(),
  |               ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: delayed at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/compiler/rustc_middle/src/ty/mod.rs:2611:26

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:974:13
stack backtrace:
   0:     0x7f628ecbde30 - std::backtrace_rs::backtrace::libunwind::trace::h746c3e9529d524bc
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
   1:     0x7f628ecbde30 - std::backtrace_rs::backtrace::trace_unsynchronized::h86340908ff889faa
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f628ecbde30 - std::sys_common::backtrace::_print_fmt::h43f85f9b18230404
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7f628ecbde30 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hc132ae1a5b5aa7cd
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/sys_common/backtrace.rs:46:22
   4:     0x7f628ed30c4c - core::fmt::write::hdf023a0036d2a25f
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/core/src/fmt/mod.rs:1078:17
   5:     0x7f628ecaf9a2 - std::io::Write::write_fmt::h8580846154bcb66a
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/io/mod.rs:1519:15
   6:     0x7f628ecc1a95 - std::sys_common::backtrace::_print::h7ee55fed88d107a3
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/sys_common/backtrace.rs:49:5
   7:     0x7f628ecc1a95 - std::sys_common::backtrace::print::h54a7d3e52a524177
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/sys_common/backtrace.rs:36:9
   8:     0x7f628ecc1a95 - std::panicking::default_hook::{{closure}}::h60921e857bf55a40
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/panicking.rs:208:50
   9:     0x7f628ecc15ea - std::panicking::default_hook::hf0f9afb1017317fc
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/panicking.rs:225:9
  10:     0x7f628f54ebb8 - rustc_driver::report_ice::ha25ae86a5858acc3
  11:     0x7f628ecc2396 - std::panicking::rust_panic_with_hook::h8d66bf42b407aaea
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/panicking.rs:595:17
  12:     0x7f628ecc1eb7 - std::panicking::begin_panic_handler::{{closure}}::hde71edcd925d0c5e
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/panicking.rs:497:13
  13:     0x7f628ecbe2ec - std::sys_common::backtrace::__rust_end_short_backtrace::h8a3c7d6cea578919
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/sys_common/backtrace.rs:141:18
  14:     0x7f628ecc1e19 - rust_begin_unwind
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/panicking.rs:493:5
  15:     0x7f628ecc1dcb - std::panicking::begin_panic_fmt::hee67ce14b77d0396
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/panicking.rs:435:5
  16:     0x7f62926b1f11 - rustc_errors::HandlerInner::flush_delayed::h336555a5d5079cda
  17:     0x7f62926ae3d1 - <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop::he52694f8b8fafc7c
  18:     0x55638902a226 - core::ptr::drop_in_place::he12f0fc8a3bb0500
  19:     0x55638902e2b6 - <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop::hc65b7dbe435be8b6
  20:     0x556388fafe0c - rustdoc::main_options::h8a5cda9c1c8c625b
  21:     0x5563890f6a68 - rustc_span::with_session_globals::h7a83fbbd64fb6823
  22:     0x556388fdd30e - std::sys_common::backtrace::__rust_begin_short_backtrace::h50722f4a01515f7b
  23:     0x55638910f03a - core::ops::function::FnOnce::call_once{{vtable.shim}}::h22276985fb540191
  24:     0x7f628ecd165a - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hea1090dbdcecbf5a
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/alloc/src/boxed.rs:1318:9
  25:     0x7f628ecd165a - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h8d5723d3912bd325
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/alloc/src/boxed.rs:1318:9
  26:     0x7f628ecd165a - std::sys::unix::thread::Thread::new::thread_start::hc17a425ca2995724
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/sys/unix/thread.rs:71:17
  27:     0x7f628ebad3e9 - start_thread
  28:     0x7f628e993293 - __GI___clone
  29:                0x0 - <unknown>

error: internal compiler error: unexpected panic

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.50.0-nightly (1c389ffef 2020-11-24) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack

@matthiaskrgr matthiaskrgr 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 Nov 28, 2020
@matthiaskrgr
Copy link
Member Author

@rustbot label -T-compiler +T-rustdoc

@rustbot rustbot added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 28, 2020
@fanninpm
Copy link

@jyn514
Copy link
Member

jyn514 commented Dec 20, 2020

MCVE:

#[repr(usize)]
enum MyWeirdOption<T> {
    None,
    Some = std::mem::size_of::<T>(),
    //~^ ERROR constant expression depends on a generic parameter
}

Rustc gives the correct error:

error: constant expression depends on a generic parameter
 --> enum.rs:4:12
  |
4 |     Some = std::mem::size_of::<T>(),
  |            ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this may fail depending on what value the parameter takes

I expect this is the same sort of issue as #73566 (comment) where rustdoc ignores errors that the compiler requires to be emitted.

@jyn514
Copy link
Member

jyn514 commented Dec 20, 2020

Adding P-low by the same rationale as #79496 (comment).

@matthiaskrgr
Copy link
Member Author

matthiaskrgr commented Feb 18, 2022

Appears to be fixed 🎉

error: generic parameters may not be used in const operations
 --> out.rs:9:35
  |
9 |     Some(T) = std::mem::size_of::<T>(),
  |                                   ^ cannot perform const operation using `T`
  |
  = note: type parameters may not be used in const expressions
  = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions

@matthiaskrgr matthiaskrgr added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Feb 18, 2022
TaKO8Ki added a commit to TaKO8Ki/rust that referenced this issue Jun 28, 2022
TaKO8Ki added a commit to TaKO8Ki/rust that referenced this issue Jun 28, 2022
@TaKO8Ki
Copy link
Member

TaKO8Ki commented Jun 29, 2022

Adding #![feature(generic_const_exprs)] still causes the same ICE.

warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/main.rs:1:58
  |
1 | #![feature(arbitrary_enum_discriminant, core_intrinsics, generic_const_exprs)]
  |                                                          ^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information

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

error: internal compiler error: enum discriminant depends on generics
 --> src/main.rs:9:15
  |
9 |     Some(T) = std::mem::size_of::<T>(),
  |               ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: delayed at /rust/compiler/rustc_middle/src/ty/adt.rs:459:26

@JohnTitor JohnTitor removed the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Jul 19, 2022
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Mar 3, 2023
@Alexendoo
Copy link
Member

Fixed by #111215

# for free to join this conversation on GitHub. Already have an account? # 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) ❄️ P-low Low priority T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants