Closed
Description
Code
#[derive(Clone, Copy)]
#[repr(transparent)]
pub struct Handle(u64);
impl Default for Handle {
fn default() -> Self {
Handle(u64::MAX)
}
}
impl Handle {
fn as_usize(self) -> usize {
// transmute is used to get a proper compile
// time error when usize is not 64 bits long.
unsafe { std::mem::transmute(self) }
}
}
use std::ops::Index;
impl<T> Index<Handle> for [T] where Self: Index<usize> {
type Output = <Self as Index<usize>>::Output;
fn index(&self, index: Handle) -> &Self::Output {
&self[index.as_usize()]
}
}
Meta
$ rustc --version --verbose
rustc 1.57.0 (f1edd0429 2021-11-29)
binary: rustc
commit-hash: f1edd0429582dd29cccacaf50fd134b05593bd9c
commit-date: 2021-11-29
host: x86_64-unknown-linux-gnu
release: 1.57.0
LLVM version: 13.0.0
Error output
error: internal compiler error: broken MIR in DefId(0:13 ~ playground[20eb]::{impl#2}::index) (_3 = &(*_1)[_4]): bad assignment (&<[T] as std::ops::Index<usize>>::Output = &T): NoSolution
--> src/lib.rs:25:9
|
25 | &self[index.as_usize()]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:330:27
error: internal compiler error: broken MIR in Item(WithOptConstParam { did: DefId(0:13 ~ playground[20eb]::{impl#2}::index), const_param_did: None }) (end of phase Optimization) at bb2[0]:
encountered `Assign((_0, &(*_1)[_3]))` with incompatible types:
left-hand side has type: &<[T] as Index<usize>>::Output
right-hand side has type: &T
--> src/lib.rs:25:9
|
25 | &self[index.as_usize()]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: delayed at compiler/rustc_const_eval/src/transform/validate.rs:120:36
thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:1165: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.57.0 (f1edd0429 2021-11-29) running on x86_64-unknown-linux-gnu
note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type lib
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
end of query stack
error: could not compile `playground`
Backtrace
thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:1165:13
stack backtrace:
0: 0x7f707abfda9c - std::backtrace_rs::backtrace::libunwind::trace::hf6a6dfd7da937cb0
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
1: 0x7f707abfda9c - std::backtrace_rs::backtrace::trace_unsynchronized::hc596a19e4891f7f3
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
2: 0x7f707abfda9c - std::sys_common::backtrace::_print_fmt::hb16700db31584325
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/sys_common/backtrace.rs:67:5
3: 0x7f707abfda9c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h231c4190cfa75162
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/sys_common/backtrace.rs:46:22
4: 0x7f707ac5afdc - core::fmt::write::h2a1462b5f8eea807
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/fmt/mod.rs:1163:17
5: 0x7f707abedc05 - std::io::Write::write_fmt::h71ddfebc68685972
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/io/mod.rs:1696:15
6: 0x7f707ac00f60 - std::sys_common::backtrace::_print::hcc197d4bebf2b369
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/sys_common/backtrace.rs:49:5
7: 0x7f707ac00f60 - std::sys_common::backtrace::print::h335a66af06738c7c
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/sys_common/backtrace.rs:36:9
8: 0x7f707ac00f60 - std::panicking::default_hook::{{closure}}::h6fac9ac9c8b79e52
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/panicking.rs:210:50
9: 0x7f707ac00b15 - std::panicking::default_hook::h341c1030c6a1161b
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/panicking.rs:227:9
10: 0x7f707b3ed2b1 - rustc_driver::DEFAULT_HOOK::{{closure}}::{{closure}}::h932547f60770f26a
11: 0x7f7069205993 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::ha04241e5889574ec
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/alloc/src/boxed.rs:1705:9
12: 0x7f70691d7ebd - proc_macro::bridge::client::<impl proc_macro::bridge::Bridge>::enter::{{closure}}::{{closure}}::h79da094b1be6293d
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/proc_macro/src/bridge/client.rs:320:21
13: 0x7f707ac01779 - std::panicking::rust_panic_with_hook::h50680ff4b44510c6
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/panicking.rs:628:17
14: 0x7f707ac01230 - std::panicking::begin_panic_handler::{{closure}}::h9371c0fbb1e8465a
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/panicking.rs:521:13
15: 0x7f707abfdf44 - std::sys_common::backtrace::__rust_end_short_backtrace::h9b3efa22a5768c0f
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/sys_common/backtrace.rs:139:18
16: 0x7f707ac01199 - rust_begin_unwind
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/panicking.rs:517:5
17: 0x7f707abc5441 - core::panicking::panic_fmt::h23b9203e89cc61cf
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/panicking.rs:100:14
18: 0x7f707c4d1c3c - core::panicking::panic_display::h0c6ac292783ee908
19: 0x7f707d9fc866 - rustc_errors::HandlerInner::flush_delayed::hc35129b420cfd4e2
20: 0x7f707d9fb0ad - <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop::h3c24eb5201838cbf
21: 0x7f707cfed2a8 - core::ptr::drop_in_place<rustc_session::parse::ParseSess>::hd814f279f0e36752
22: 0x7f707cfef6ca - <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop::hf486b211acc1f0aa
23: 0x7f707cfc07ad - core::ptr::drop_in_place<rustc_interface::interface::Compiler>::hefd4f3f97698e310
24: 0x7f707cfc02ba - rustc_span::with_source_map::h6ab8a240e103b5b9
25: 0x7f707cfd22ac - scoped_tls::ScopedKey<T>::set::hd1fbd64c6f645895
26: 0x7f707cfc0ef5 - std::sys_common::backtrace::__rust_begin_short_backtrace::h0a1328c9fa7f7448
27: 0x7f707cfec962 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h4ea1ced06d6b3e97
28: 0x7f707ac0c933 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7bd677a5dc988be6
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/alloc/src/boxed.rs:1691:9
29: 0x7f707ac0c933 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7b1c1ba11c4db785
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/alloc/src/boxed.rs:1691:9
30: 0x7f707ac0c933 - std::sys::unix::thread::Thread::new::thread_start::h9c58c0d12d84e854
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/sys/unix/thread.rs:106:17
31: 0x7f707ab3beae - start_thread
at /builddir/glibc-2.32/nptl/pthread_create.c:463:8
32: 0x7f707aa582ff - __GI___clone
at /builddir/glibc-2.32/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95
33: 0x0 - <unknown>