Closed
Description
Code
use std::ops::BitAnd;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn is_set() {
assert!(0xffu8.bit::<0>());
}
}
trait Bits {
fn bit<const I: u8>(self) -> bool;
}
impl<T> Bits for T where
T: Copy + BitAnd<T, Output=T> + From<u8> + Eq
{
fn bit<const I: usize>(self) -> bool {
let i = 1 << I;
let mask = T::from(i);
mask & self == mask
}
}
Meta
rustc --version --verbose
:
rustc 1.52.1 (9bc8c42bb 2021-05-09)
binary: rustc
commit-hash: 9bc8c42bb2f19e745a63f3445f1ac248fb015e53
commit-date: 2021-05-09
host: x86_64-apple-darwin
release: 1.52.1
LLVM version: 12.0.0
Error output
error: internal compiler error: /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/compiler/rustc_middle/src/ty/consts/int.rs:230:13: expected int of size 8, but got size 1
thread 'rustc' panicked at 'Box<Any>', /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/std/src/panic.rs:59:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: the compiler unexpectedly panicked. this is a bug.
Backtrace
$ RUST_BACKTRACE=1 cargo test
thread 'rustc' panicked at 'Box<Any>', /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/std/src/panic.rs:59:5
stack backtrace:
0: std::panicking::begin_panic
1: std::panic::panic_any
2: rustc_errors::HandlerInner::bug
3: rustc_errors::Handler::bug
4: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
5: rustc_middle::ty::context::tls::with_opt::{{closure}}
6: rustc_middle::ty::context::tls::with_opt
7: rustc_middle::util::bug::opt_span_bug_fmt
8: rustc_middle::util::bug::bug_fmt
9: rustc_middle::ty::consts::int::ScalarInt::assert_bits::{{closure}}
10: rustc_codegen_llvm::common::<impl rustc_codegen_ssa::traits::consts::ConstMethods for rustc_codegen_llvm::context::CodegenCx>::scalar_to_backend
11: rustc_codegen_ssa::mir::operand::OperandRef<V>::from_const
12: rustc_codegen_ssa::mir::operand::<impl rustc_codegen_ssa::mir::FunctionCx<Bx>>::codegen_operand
13: rustc_codegen_ssa::mir::rvalue::<impl rustc_codegen_ssa::mir::FunctionCx<Bx>>::codegen_rvalue_operand
14: rustc_codegen_ssa::mir::codegen_mir
15: rustc_codegen_ssa::base::codegen_instance
16: <rustc_middle::mir::mono::MonoItem as rustc_codegen_ssa::mono_item::MonoItemExt>::define
17: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
18: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
19: rustc_codegen_llvm::base::compile_codegen_unit
20: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
21: rustc_interface::passes::QueryContext::enter
22: rustc_interface::queries::Queries::ongoing_codegen
23: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
24: rustc_span::with_source_map
25: rustc_interface::interface::create_compiler_and_run
26: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.