Closed
Description
I wanted to change Cow
to use the pattern in the code below (which changes Cow
variance w.r.t to <B as ToOwned>::Owned
),
but got an ICE. I managed to reduce it the code below.
Code
#![feature(min_specialization)]
use std::fmt::{self, Display};
pub enum Cow<'a, B: ?Sized + 'a, O = <B as ToOwned>::Owned>
where
B: ToOwned,
{
Borrowed(&'a B),
Owned(O),
}
impl ToString for Cow<'_, str> {
fn to_string(&self) -> String {
panic!()
}
}
impl<B: ?Sized> Display for Cow<'_, B> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
panic!()
}
}
The same code with the current definition of Cow
works (same as std
):
#![feature(min_specialization)]
use std::fmt::{self, Display};
pub enum Cow<'a, B: ?Sized + 'a>
where
B: ToOwned,
{
Borrowed(&'a B),
Owned(<B as ToOwned>::Owned),
}
impl ToString for Cow<'_, str> {
fn to_string(&self) -> String {
panic!()
}
}
impl<B: ?Sized + ToOwned> Display for Cow<'_, B> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
panic!()
}
}
Meta
rustc --version --verbose
:
rustc 1.50.0-nightly (825637983 2020-11-18)
binary: rustc
commit-hash: 8256379832b5ecb7f71e8c5e2018446482223c12
commit-date: 2020-11-18
host: x86_64-unknown-linux-gnu
release: 1.50.0-nightly
Error output
error: internal compiler error: compiler\rustc_trait_selection\src\traits\specialize\mod.rs:101:21: When translating substitutions for specialization, the expected specialization failed to hold
thread 'rustc' panicked at 'Box<Any>', compiler\rustc_errors\src\lib.rs:958:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
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.50.0-nightly (825637983 2020-11-18) 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:
#0 [check_mod_impl_wf] checking that impls are well-formed in top-level module
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error
Backtrace
thread 'rustc' panicked at 'Box<Any>', compiler/rustc_errors/src/lib.rs:958:9
stack backtrace:
0: std::panicking::begin_panic
1: rustc_errors::HandlerInner::bug
2: rustc_errors::Handler::bug
3: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
4: rustc_middle::ty::context::tls::with_opt::{{closure}}
5: rustc_middle::ty::context::tls::with_opt
6: rustc_middle::util::bug::opt_span_bug_fmt
7: rustc_middle::util::bug::bug_fmt
8: rustc_trait_selection::traits::specialize::translate_substs::{{closure}}
9: rustc_trait_selection::traits::specialize::translate_substs
10: rustc_typeck::impl_wf_check::min_specialization::check_always_applicable
11: rustc_infer::infer::InferCtxtBuilder::enter
12: rustc_typeck::impl_wf_check::min_specialization::check_min_specialization
13: <rustc_typeck::impl_wf_check::ImplWfCheck as rustc_hir::itemlikevisit::ItemLikeVisitor>::visit_item
14: rustc_middle::hir::map::Map::visit_item_likes_in_module
15: rustc_typeck::impl_wf_check::check_mod_impl_wf
16: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::check_mod_impl_wf>::compute
17: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
18: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
19: rustc_data_structures::stack::ensure_sufficient_stack
20: rustc_query_system::query::plumbing::get_query_impl
21: rustc_query_system::query::plumbing::ensure_query_impl
22: rustc_typeck::impl_wf_check::impl_wf_check
23: rustc_typeck::check_crate
24: rustc_interface::passes::analysis
25: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
26: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
27: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
28: rustc_data_structures::stack::ensure_sufficient_stack
29: rustc_query_system::query::plumbing::get_query_impl
30: rustc_interface::passes::QueryContext::enter
31: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
32: rustc_span::with_source_map
33: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
note: the compiler unexpectedly panicked. this is a bug.
log with RUSTC_LOG=rustc_trait_selection::traits::specialize
$ env RUSTC_LOG=rustc_trait_selection::traits::specialize cargo +stage1debug build
Compiling playground v0.1.0 (/opt/workspace/playground)
DEBUG rustc_trait_selection::traits::specialize::specialization_graph insert_blindly: impl_def_id=DefId(5:4335 ~ alloc[ac87]::string::{impl#40}) st=None
DEBUG rustc_trait_selection::traits::specialize::specialization_graph insert_blindly: impl_def_id=DefId(5:4339 ~ alloc[ac87]::string::{impl#41}) st=CharSimplifiedType
DEBUG rustc_trait_selection::traits::specialize::specialization_graph insert_blindly: impl_def_id=DefId(5:4342 ~ alloc[ac87]::string::{impl#42}) st=StrSimplifiedType
DEBUG rustc_trait_selection::traits::specialize::specialization_graph insert_blindly: impl_def_id=DefId(5:4344 ~ alloc[ac87]::string::{impl#43}) st=AdtSimplifiedType(DefId(5:405 ~ alloc[ac87]::borrow::Cow))
DEBUG rustc_trait_selection::traits::specialize::specialization_graph insert_blindly: impl_def_id=DefId(5:4346 ~ alloc[ac87]::string::{impl#44}) st=AdtSimplifiedType(DefId(5:5557 ~ alloc[ac87]::string::String))
DEBUG rustc_trait_selection::traits::specialize::specialization_graph insert(DefId(0:16 ~ playground[cc5d]::{impl#0})): inserting TraitRef <Cow<'_, str> as std::string::ToString> into specialization graph
DEBUG rustc_trait_selection::traits::specialize::specialization_graph insert(impl_def_id=DefId(0:16 ~ playground[cc5d]::{impl#0}), simplified_self=Some(AdtSimplifiedType(DefId(0:6 ~ playground[cc5d]::Cow))))
DEBUG rustc_trait_selection::traits::specialize::specialization_graph insert: impl_def_id=DefId(0:16 ~ playground[cc5d]::{impl#0}), simplified_self=Some(AdtSimplifiedType(DefId(0:6 ~ playground[cc5d]::Cow))), possible_sibling=DefId(5:4335 ~ alloc[ac87]::string::{impl#40})
DEBUG rustc_trait_selection::traits::specialize specializes(DefId(0:16 ~ playground[cc5d]::{impl#0}), DefId(5:4335 ~ alloc[ac87]::string::{impl#40}))
DEBUG rustc_trait_selection::traits::specialize translate_substs(ParamEnv { caller_bounds: [], reveal: UserFacing }, DefId(5:4093 ~ alloc[ac87]::str::{impl#4}), [], Impl(DefId(5:4093 ~ alloc[ac87]::str::{impl#4})))
DEBUG rustc_trait_selection::traits::specialize fulfill_implication(ParamEnv { caller_bounds: [], reveal: UserFacing }, trait_ref=<Cow<'_, str, std::string::String> as std::string::ToString> |- DefId(5:4335 ~ alloc[ac87]::string::{impl#40}) applies)
DEBUG rustc_trait_selection::traits::specialize fulfill_implication: an impl for <Cow<'_, str, std::string::String> as std::string::ToString> specializes <_ as std::string::ToString>
DEBUG rustc_trait_selection::traits::specialize specializes(DefId(5:4335 ~ alloc[ac87]::string::{impl#40}), DefId(0:16 ~ playground[cc5d]::{impl#0}))
DEBUG rustc_trait_selection::traits::specialize fulfill_implication(ParamEnv { caller_bounds: [TraitPredicate(<T as std::fmt::Display>)], reveal: UserFacing }, trait_ref=<T as std::string::ToString> |- DefId(0:16 ~ playground[cc5d]::{impl#0}) applies)
DEBUG rustc_trait_selection::traits::specialize translate_substs(ParamEnv { caller_bounds: [TraitPredicate(<T as std::fmt::Display>)], reveal: UserFacing }, DefId(5:4093 ~ alloc[ac87]::str::{impl#4}), [], Impl(DefId(5:4093 ~ alloc[ac87]::str::{impl#4})))
DEBUG rustc_trait_selection::traits::specialize fulfill_implication: <T as std::string::ToString> does not unify with <Cow<'_, str, std::string::String> as std::string::ToString>
DEBUG rustc_trait_selection::traits::specialize::specialization_graph descending as child of TraitRef <T as std::string::ToString>
DEBUG rustc_trait_selection::traits::specialize::specialization_graph insert(impl_def_id=DefId(0:16 ~ playground[cc5d]::{impl#0}), simplified_self=Some(AdtSimplifiedType(DefId(0:6 ~ playground[cc5d]::Cow))))
DEBUG rustc_trait_selection::traits::specialize::specialization_graph placing as new sibling
DEBUG rustc_trait_selection::traits::specialize::specialization_graph insert_blindly: impl_def_id=DefId(0:16 ~ playground[cc5d]::{impl#0}) st=AdtSimplifiedType(DefId(0:6 ~ playground[cc5d]::Cow))
DEBUG rustc_trait_selection::traits::specialize translate_substs(ParamEnv { caller_bounds: [], reveal: UserFacing }, DefId(0:16 ~ playground[cc5d]::{impl#0}), [ReEarlyBound(0, '_)], Impl(DefId(5:4335 ~ alloc[ac87]::string::{impl#40})))
DEBUG rustc_trait_selection::traits::specialize fulfill_implication(ParamEnv { caller_bounds: [], reveal: UserFacing }, trait_ref=<Cow<'_, str> as std::string::ToString> |- DefId(5:4335 ~ alloc[ac87]::string::{impl#40}) applies)
DEBUG rustc_trait_selection::traits::specialize translate_substs(ParamEnv { caller_bounds: [], reveal: UserFacing }, DefId(5:4093 ~ alloc[ac87]::str::{impl#4}), [], Impl(DefId(5:4093 ~ alloc[ac87]::str::{impl#4})))
DEBUG rustc_trait_selection::traits::specialize fulfill_implication: for impls on <Cow<'_, str> as std::string::ToString> and <_ as std::string::ToString>, could not fulfill: [FulfillmentError(Obligation(predicate=ProjectionPredicate(ProjectionTy { substs: [str], item_def_id: DefId(5:397 ~ alloc[ac87]::borrow::ToOwned::Owned) }, <str as std::borrow::ToOwned>::Owned), depth=2),MismatchedProjectionTypes(Sorts(ExpectedFound { expected: std::string::String, found: <str as std::borrow::ToOwned>::Owned })))] given []
error: internal compiler error: compiler/rustc_trait_selection/src/traits/specialize/mod.rs:101:21: When translating substitutions for specialization, the expected specialization failed to hold
thread 'rustc' panicked at 'Box<Any>', compiler/rustc_errors/src/lib.rs:958:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Metadata
Metadata
Assignees
Labels
Area: Trait impl specializationCategory: This is a bug.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Low priorityRelevant to the compiler team, which will review and decide on the PR/issue.ICE tracked in rust-lang/glacier.Performance or correctness regression from one stable version to another.