Closed
Description
While experimenting to reduce some boilerplate I came across this; removing either From
implementation results in a successful build.
Code
#![feature(generic_const_exprs)]
struct GenericStruct<const T: usize> { val: i64 }
impl<const T: usize> From<GenericStruct<T>> for GenericStruct<{T + 1}> {
fn from(other: GenericStruct<T>) -> Self {
Self { val: other.val }
}
}
impl<const T: usize> From<GenericStruct<{T + 1}>> for GenericStruct<T> {
fn from(other: GenericStruct<{T + 1}>) -> Self {
Self { val: other.val }
}
}
Meta
rustc --version --verbose
:
rustc 1.57.0-nightly (05044c2e6 2021-09-26)
binary: rustc
commit-hash: 05044c2e6c043929a11537d7f6169eb3a2397bb8
commit-date: 2021-09-26
host: x86_64-unknown-linux-gnu
release: 1.57.0-nightly
LLVM version: 13.0.0
Error output
Checking rust-ice v0.1.0 (/tmp/rust-ice)
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
--> src/lib.rs:1:12
|
1 | #![feature(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
thread 'rustc' panicked at 'already borrowed: BorrowMutError', compiler/rustc_infer/src/infer/combine.rs:954:50
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-nightly (05044c2e6 2021-09-26) running on x86_64-unknown-linux-gnu
note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type lib
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
#0 [specialization_graph_of] building specialization graph of trait `core::convert::From`
#1 [coherent_trait] coherence checking all impls of trait `core::convert::From`
end of query stack
warning: `rust-ice` (lib) generated 1 warning
error: could not compile `rust-ice`; 1 warning emitted
Backtrace
thread 'rustc' panicked at 'already borrowed: BorrowMutError', compiler/rustc_infer/src/infer/combine.rs:954:50
stack backtrace:
0: rust_begin_unwind
at /rustc/05044c2e6c043929a11537d7f6169eb3a2397bb8/library/std/src/panicking.rs:517:5
1: core::panicking::panic_fmt
at /rustc/05044c2e6c043929a11537d7f6169eb3a2397bb8/library/core/src/panicking.rs:100:14
2: core::result::unwrap_failed
at /rustc/05044c2e6c043929a11537d7f6169eb3a2397bb8/library/core/src/result.rs:1617:5
3: <rustc_infer::infer::combine::ConstInferUnifier as rustc_middle::ty::relate::TypeRelation>::consts
4: <rustc_infer::infer::combine::ConstInferUnifier as rustc_middle::ty::relate::TypeRelation>::relate_with_variance
5: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once
6: <core::result::Result<T,E> as rustc_middle::ty::context::InternIteratorElement<T,R>>::intern_with
7: rustc_middle::ty::context::TyCtxt::mk_substs
8: rustc_middle::ty::relate::relate_substs
9: <rustc_infer::infer::combine::ConstInferUnifier as rustc_middle::ty::relate::TypeRelation>::consts
10: <rustc_infer::infer::combine::ConstInferUnifier as rustc_middle::ty::relate::TypeRelation>::consts
11: <rustc_infer::infer::combine::ConstInferUnifier as rustc_middle::ty::relate::TypeRelation>::relate_with_variance
12: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once
13: <core::result::Result<T,E> as rustc_middle::ty::context::InternIteratorElement<T,R>>::intern_with
14: rustc_middle::ty::context::TyCtxt::mk_substs
15: rustc_middle::ty::relate::relate_substs
16: <rustc_infer::infer::combine::ConstInferUnifier as rustc_middle::ty::relate::TypeRelation>::consts
17: rustc_infer::infer::combine::<impl rustc_infer::infer::InferCtxt>::unify_const_variable
18: rustc_infer::infer::combine::<impl rustc_infer::infer::InferCtxt>::super_combine_consts
19: <core::result::Result<T,E> as rustc_middle::ty::context::InternIteratorElement<T,R>>::intern_with
20: rustc_middle::ty::relate::super_relate_tys
21: rustc_middle::ty::relate::TypeRelation::relate
22: <core::result::Result<T,E> as rustc_middle::ty::context::InternIteratorElement<T,R>>::intern_with
23: rustc_middle::ty::relate::relate_substs
24: rustc_infer::infer::InferCtxt::commit_if_ok
25: rustc_infer::infer::at::At::eq_impl_headers
26: rustc_trait_selection::traits::coherence::overlap_within_probe
27: rustc_infer::infer::InferCtxtBuilder::enter
28: <rustc_middle::traits::specialization_graph::Children as rustc_trait_selection::traits::specialize::specialization_graph::ChildrenExt>::insert
29: <rustc_middle::traits::specialization_graph::Graph as rustc_trait_selection::traits::specialize::specialization_graph::GraphExt>::insert
30: rustc_trait_selection::traits::specialize::specialization_graph_provider
31: rustc_query_system::query::plumbing::try_execute_query
32: rustc_query_system::query::plumbing::get_query
33: rustc_typeck::coherence::coherent_trait
34: rustc_query_system::query::plumbing::try_execute_query
35: rustc_query_system::query::plumbing::get_query
36: rustc_session::session::Session::track_errors
37: rustc_typeck::check_crate
38: rustc_interface::passes::analysis
39: rustc_query_system::query::plumbing::try_execute_query
40: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
41: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
42: rustc_span::with_source_map
43: rustc_interface::interface::create_compiler_and_run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 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-nightly (05044c2e6 2021-09-26) 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:
#0 [specialization_graph_of] building specialization graph of trait `core::convert::From`
#1 [coherent_trait] coherence checking all impls of trait `core::convert::From`
#2 [analysis] running analysis passes on this crate
end of query stack