Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

min_specialization with default generic causes an ICE #79224

Closed
ohadravid opened this issue Nov 20, 2020 · 3 comments · Fixed by #98525
Closed

min_specialization with default generic causes an ICE #79224

ohadravid opened this issue Nov 20, 2020 · 3 comments · Fixed by #98525
Labels
A-specialization Area: Trait impl specialization C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-low Low priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ohadravid
Copy link
Contributor

ohadravid commented Nov 20, 2020

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

@ohadravid ohadravid added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 20, 2020
@jonas-schievink jonas-schievink added the A-specialization Area: Trait impl specialization label Nov 20, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Dec 12, 2020
@matthiaskrgr
Copy link
Member

This ICEs since 1.44
@rustbot modify labels: +regression-from-stable-to-stable

@rustbot rustbot added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Dec 20, 2020
@apiraino apiraino added P-low Low priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Dec 24, 2020
@apiraino
Copy link
Contributor

apiraino commented Dec 24, 2020

Assigning P-low as discussed as part of the Prioritization Working Group procedure and removing I-prioritize.

@Alexendoo
Copy link
Member

No longer appears to ICE since #90887

@Alexendoo Alexendoo added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Mar 9, 2022
JohnTitor added a commit to JohnTitor/rust that referenced this issue Jun 26, 2022
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
bors added a commit to rust-lang-ci/rust that referenced this issue Jun 29, 2022
Rollup of 7 pull requests

Successful merges:

 - rust-lang#97423 (Simplify memory ordering intrinsics)
 - rust-lang#97542 (Use typed indices in argument mismatch algorithm)
 - rust-lang#97786 (Account for `-Z simulate-remapped-rust-src-base` when resolving remapped paths)
 - rust-lang#98277 (Fix trait object reborrow suggestion)
 - rust-lang#98525 (Add regression test for rust-lang#79224)
 - rust-lang#98549 (interpret: do not prune requires_caller_location stack frames quite so early)
 - rust-lang#98603 (Some borrowck diagnostic fixes)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in b8bb6f9 Jun 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-specialization Area: Trait impl specialization C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-low Low priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants