Closed
Description
A function that compiles and runs successfully outside of a trait causes an ICE when it's in a trait. The expectation is that this should work similarly to other generics on trait functions--while they will prevent a trait object reference, they should otherwise be allowed. (On playground)
#![feature(const_generics)]
fn test<const A: i32>() -> i32 { A }
trait T {
fn test<const A: i32>(&self) -> i32 { A }
}
struct S();
impl T for S {}
fn main() {
let foo = S();
println!("{}", test::<{8i32}>());
println!("{}", foo.test::<{16i32}>()); // <- Causes ICE
}
Error and relevant backtrace:
error: internal compiler error: src/librustc_codegen_ssa/mir/operand.rs:79: unevaluated constant in `OperandRef::from_const`
thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:643:9
stack backtrace:
0: backtrace::backtrace::libunwind::trace
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.34/src/backtrace/libunwind.rs:88
1: backtrace::backtrace::trace_unsynchronized
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.34/src/backtrace/mod.rs:66
2: std::sys_common::backtrace::_print
at src/libstd/sys_common/backtrace.rs:47
3: std::sys_common::backtrace::print
at src/libstd/sys_common/backtrace.rs:36
4: std::panicking::default_hook::{{closure}}
at src/libstd/panicking.rs:200
5: std::panicking::default_hook
at src/libstd/panicking.rs:214
6: rustc::util::common::panic_hook
7: std::panicking::rust_panic_with_hook
at src/libstd/panicking.rs:481
8: std::panicking::begin_panic
9: rustc_errors::Handler::bug
10: rustc::util::bug::opt_span_bug_fmt::{{closure}}
11: rustc::ty::context::tls::with_opt::{{closure}}
12: rustc::ty::context::tls::with_context_opt
13: rustc::ty::context::tls::with_opt
14: rustc::util::bug::opt_span_bug_fmt
15: rustc::util::bug::bug_fmt
16: rustc_codegen_ssa::mir::operand::OperandRef<V>::from_const
17: rustc_codegen_ssa::mir::operand::<impl rustc_codegen_ssa::mir::FunctionCx<Bx>>::codegen_operand
18: rustc_codegen_ssa::mir::rvalue::<impl rustc_codegen_ssa::mir::FunctionCx<Bx>>::codegen_rvalue_operand
19: rustc_codegen_ssa::mir::codegen_mir
20: rustc_codegen_ssa::base::codegen_instance
21: <rustc::mir::mono::MonoItem as rustc_codegen_ssa::mono_item::MonoItemExt>::define
22: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
23: rustc::dep_graph::graph::DepGraph::with_task
24: rustc_codegen_llvm::base::compile_codegen_unit
25: rustc_codegen_ssa::base::codegen_crate
26: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
27: rustc::util::common::time
28: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
29: rustc_interface::passes::create_global_ctxt::{{closure}}
30: rustc_interface::passes::BoxedGlobalCtxt::enter
31: rustc_interface::queries::Query<T>::compute
32: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::ongoing_codegen
33: rustc_interface::interface::run_compiler_in_existing_thread_pool
34: std::thread::local::LocalKey<T>::with
35: scoped_tls::ScopedKey<T>::set
36: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
query stack during panic:
end of query stack
error: aborting due to previous error
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: rustc 1.39.0-nightly (2111aed0a 2019-08-17) running on x86_64-unknown-linux-gnu
note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type bin
Metadata
Metadata
Assignees
Labels
Area: const generics (parameters and arguments)Category: This is a bug.`#![feature(const_generics)]`Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Relevant to the compiler team, which will review and decide on the PR/issue.ICE tracked in rust-lang/glacier.This issue requires a nightly compiler in some way.