-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)C-bugCategory: This is a bug.Category: This is a bug.F-const_generics`#![feature(const_generics)]``#![feature(const_generics)]`F-generic_const_exprs`#![feature(generic_const_exprs)]``#![feature(generic_const_exprs)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.ICE tracked in rust-lang/glacier.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
Description
One version crashes the compiler, the other version produces a normal error.
Note that commenting out the line in main()
makes it compile just fine.
Code
#![feature(const_generics)]
#![feature(const_evaluatable_checked)]
use std::sync::Arc;
pub enum Predicate<const EXPRESSION: bool> {}
pub trait Satisfied {}
impl Satisfied for Predicate<true> {}
pub trait Depth { const DEPTH: usize; }
/// Make it impossible to have cyclic Arc references.
pub struct AcArc<T: Depth, const D: usize> {
#[allow(dead_code)]
inner: Arc<T>,
}
impl<T: Depth, const D: usize> AcArc<T, D> {
pub fn new(item: T) -> Self
where Predicate<{T::DEPTH <= D}>: Satisfied, // crashes with == too.
{
Self {
inner: Arc::new(item),
}
}
}
// With the predicate on the impl instead of on the function, it gives a "normal" error.
// Though I still feel like main() should typecheck.
// impl<T: Depth, const D: usize> AcArc<T, D>
// where Predicate<{T::DEPTH == D}>: Satisfied,
// {
// pub fn new(item: T) -> Self
// {
// Self {
// inner: Arc::new(item),
// }
// }
// }
// this is where the depth increment is enforced.
// But compiler crashes without this.
// impl<T, const D: usize> Depth for AcArc<T, D>
// where
// T: Depth,
// {
// const DEPTH: usize = D + 1;
// }
impl Depth for u8 { const DEPTH: usize = 0; }
fn main() {
let arc : AcArc<u8, 0> = AcArc::new(42_u8); // comment this out and it compiles just fine.
println!("Hello, world!");
}
Meta
rustc --version --verbose
:
rustc 1.52.0-nightly (caca2121f 2021-03-05)
binary: rustc
commit-hash: caca2121ffe4cb47d8ea2d9469c493995f57e0b5
commit-date: 2021-03-05
host: x86_64-pc-windows-msvc
release: 1.52.0-nightly
LLVM version: 12.0.0
Error output
PS E:\hax\rust-crashie> cargo b
Compiling rust-crashie v0.1.0 (E:\hax\rust-crashie)
(((some irrelevant warning ommitted)))
warning: Error finalizing incremental compilation session directory `\\?\E:\hax\rust-crashie\target\debug\incremental\rust_crashie-2f5q55yas46ec\s-fwhefzjcfw-15fjgh-working`: The system cannot find the file specified. (os error 2)
warning: 4 warnings emitted
error: internal compiler error: Encountered error `Unimplemented` selecting `Binder(<^0 as Depth>)` during codegen
|
= note: delayed at compiler\rustc_trait_selection\src\traits\codegen.rs:68:32
error: internal compiler error: ty::ConstKind::Error constructed but no error reported.
|
= note: delayed at /rustc/caca2121ffe4cb47d8ea2d9469c493995f57e0b5\compiler\rustc_middle\src\ty\consts.rs:182:43
error: internal compiler error: `ErrorReported` without an error
--> src\main.rs:53:30
|
53 | let arc : AcArc<u8, 0> = AcArc::new(42_u8);
| ^^^^^^^^^^
|
= note: delayed at compiler\rustc_trait_selection\src\traits\error_reporting\mod.rs:747:31
thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler\rustc_errors\src\lib.rs:1012: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.52.0-nightly (caca2121f 2021-03-05) running on x86_64-pc-windows-msvc
note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
end of query stack
error: could not compile `rust-crashie`
To learn more, run the command again with --verbose.
Error with where
on impl instead
Though I still feel like this should typecheck, at least in the future some day?
error[E0599]: the function or associated item `new` exists for struct `AcArc<_, {_: usize}>`, but its trait bounds were not satisfied
--> src\main.rs:53:37
|
6 | pub enum Predicate<const EXPRESSION: bool> {}
| ------------------------------------------ doesn't satisfy `Predicate<{T::DEPTH == D}>: Satisfied`
...
13 | pub struct AcArc<T: Depth, const D: usize> {
| ------------------------------------------ function or associated item `new` not found for this
...
53 | let arc : AcArc<u8, 0> = AcArc::new(42_u8);
| ^^^ function or associated item cannot be called on `AcArc<_, {_: usize}>` due to unsatisfied trait bounds
|
= note: the following trait bounds were not satisfied:
`Predicate<{T::DEPTH == D}>: Satisfied`
Backtrace (`FULL`)
thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler\rustc_errors\src\lib.rs:1012:13
stack backtrace:
0: 0x7ffadc18879e - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h804aacc93092d135
1: 0x7ffadc1b404c - core::fmt::write::h2daf2a210ae0d5f0
2: 0x7ffadc17c158 - <std::io::IoSlice as core::fmt::Debug>::fmt::hfa239d9348f09840
3: 0x7ffadc18c93d - std::panicking::take_hook::h930d1e1d0a893a3f
4: 0x7ffadc18c409 - std::panicking::take_hook::h930d1e1d0a893a3f
5: 0x7ffadc6b23d5 - rustc_driver::report_ice::h5f2d10e8face884a
6: 0x7ffadc18d1a5 - std::panicking::rust_panic_with_hook::h291b58940b8c1567
7: 0x7ffadc18cd01 - rust_begin_unwind
8: 0x7ffadc1890ef - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h804aacc93092d135
9: 0x7ffadc18cc59 - rust_begin_unwind
10: 0x7ffadc1e583c - std::panicking::begin_panic_fmt::h21676d8d2c928240
11: 0x7ffae0914c24 - rustc_errors::HandlerInner::delay_as_bug::h84ea15161c493c2b
12: 0x7ffae09101d7 - <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop::h2aadc8469749ba5c
13: 0x7ffadc6bda87 - rustc_errors::snippet::MultilineAnnotation::increase_depth::h0d6a408d57c96b60
14: 0x7ffadc6c46ba - rustc_errors::snippet::MultilineAnnotation::increase_depth::h0d6a408d57c96b60
15: 0x7ffadc6bf46c - rustc_errors::snippet::MultilineAnnotation::increase_depth::h0d6a408d57c96b60
16: 0x7ffadc6b481d - <rustc_driver::Compilation as core::fmt::Debug>::fmt::h34129260871bdb31
17: 0x7ffadc6cccc6 - <rustc_middle::ty::SymbolName as core::fmt::Debug>::fmt::h7de05d943e0a531e
18: 0x7ffadc6c7d24 - rustc_errors::snippet::MultilineAnnotation::increase_depth::h0d6a408d57c96b60
19: 0x7ffadc6cddbd - <rustc_middle::ty::SymbolName as core::fmt::Debug>::fmt::h7de05d943e0a531e
20: 0x7ffadc6f101d - <tracing_subscriber::util::TryInitError as core::fmt::Display>::fmt::hc634bfbe27699956
21: 0x7ffadc19c83a - std::sys::windows::thread::Thread::new::h13c38e7cd538470c
22: 0x7ffb374c7034 - BaseThreadInitThunk
23: 0x7ffb375fd241 - RtlUserThreadStart
Metadata
Metadata
Assignees
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)C-bugCategory: This is a bug.Category: This is a bug.F-const_generics`#![feature(const_generics)]``#![feature(const_generics)]`F-generic_const_exprs`#![feature(generic_const_exprs)]``#![feature(generic_const_exprs)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.ICE tracked in rust-lang/glacier.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.