Skip to content

error: internal compiler error: src/librustc/ty/relate.rs:753: impossible case reached: can't relate: (T,) with Lifetime('_#1r) #57156

Closed
@KamilaBorowska

Description

@KamilaBorowska

I tried the following code in editions 2015 and 2018:

use std::cell::Cell;

trait CloneablePredicate<'a, T>: 'a + Fn(T) -> bool {
    fn clone_boxed(&self) -> Box<dyn CloneablePredicate<'a, T, Output = bool>>;
}

impl<'a, T, F> CloneablePredicate<'a, T> for F
where
    F: 'a + Clone + Fn(T) -> bool,
{
    fn clone_boxed(&self) -> Box<dyn CloneablePredicate<'a, T, Output = bool>> {
        Box::new(self.clone())
    }
}

impl<'a, T> Clone for Box<dyn CloneablePredicate<'a, T, Output = bool>>
where
    T: 'a,
{
    fn clone(&self) -> Self {
        self.clone_boxed()
    }
}

fn main() {
    let cell = Cell::new(4);
    let x: Box<dyn CloneablePredicate<i32, Output = bool>> = Box::new(move |x| {
        let minus_one = cell.get() - 1;
        cell.set(minus_one);
        x == minus_one
    });
    let y = x.clone();
    println!("{}", x(3));
    println!("{}", x(3));
    println!("{}", y(3));
    println!("{}", y(3));
}

I expected it to print:

true
false
true
false

And this does happen on stable, but not on beta or nightly, where I get this (this particular error is from nightly):

error: internal compiler error: src/librustc/ty/relate.rs:753: impossible case reached: can't relate: (T,) with Lifetime('_#1r)

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:590:9
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
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.33.0-nightly (a7be40c65 2018-12-26) running on x86_64-unknown-linux-gnu

Meta:

rustc --version --verbose:

rustc 1.33.0-nightly (a7be40c65 2018-12-26)
binary: rustc
commit-hash: a7be40c65ae8ace467c9c40b0a22642973e31a13
commit-date: 2018-12-26
host: x86_64-unknown-linux-gnu
release: 1.33.0-nightly
LLVM version: 8.0

Backtrace:

error: internal compiler error: src/librustc/ty/relate.rs:753: impossible case reached: can't relate: (T,) with Lifetime('_#1r)

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:590:9
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:70
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:58
             at src/libstd/panicking.rs:200
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:215
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:482
   6: std::panicking::begin_panic
   7: rustc_errors::Handler::bug
   8: rustc::util::bug::opt_span_bug_fmt::{{closure}}
   9: rustc::ty::context::tls::with_opt::{{closure}}
  10: rustc::ty::context::tls::with_context_opt
  11: rustc::ty::context::tls::with_opt
  12: rustc::util::bug::opt_span_bug_fmt
  13: rustc::util::bug::bug_fmt
  14: <rustc::ty::subst::Kind<'tcx> as rustc::ty::relate::Relate<'tcx>>::relate
  15: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once
  16: <smallvec::SmallVec<A> as core::iter::traits::FromIterator<<A as smallvec::Array>::Item>>::from_iter
  17: <core::result::Result<T, E> as rustc::ty::context::InternIteratorElement<T, R>>::intern_with
  18: <rustc::ty::sty::ExistentialTraitRef<'tcx> as rustc::ty::relate::Relate<'tcx>>::relate
  19: rustc::infer::InferCtxt::commit_if_ok
  20: rustc::infer::InferCtxt::commit_if_ok
  21: rustc::traits::project::opt_normalize_projection_type
  22: rustc::traits::project::normalize_projection_type
  23: rustc::ty::context::GlobalCtxt::enter_local
  24: rustc_traits::normalize_projection_ty::normalize_projection_ty
  25: rustc::ty::query::__query_compute::normalize_projection_ty
  26: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::normalize_projection_ty<'tcx>>::compute
  27: rustc::dep_graph::graph::DepGraph::with_task_impl
  28: <rustc::ty::query::plumbing::JobOwner<'a, 'tcx, Q>>::start
  29: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  30: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_get_with
  31: <rustc::traits::query::normalize::QueryNormalizer<'cx, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
  32: <smallvec::SmallVec<A> as core::iter::traits::FromIterator<<A as smallvec::Array>::Item>>::from_iter
  33: rustc::ty::fold::TypeFoldable::fold_with
  34: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable<'tcx> for &'tcx rustc::ty::TyS<'tcx>>::super_fold_with
  35: <rustc::traits::query::normalize::QueryNormalizer<'cx, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
  36: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable<'tcx> for &'tcx rustc::ty::TyS<'tcx>>::super_fold_with
  37: <rustc::traits::query::normalize::QueryNormalizer<'cx, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
  38: rustc::traits::query::normalize::<impl rustc::infer::at::At<'cx, 'gcx, 'tcx>>::normalize
  39: rustc::ty::context::GlobalCtxt::enter_local
  40: rustc_traits::normalize_erasing_regions::normalize_ty_after_erasing_regions
  41: rustc::ty::query::__query_compute::normalize_ty_after_erasing_regions
  42: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::normalize_ty_after_erasing_regions<'tcx>>::compute
  43: rustc::dep_graph::graph::DepGraph::with_task_impl
  44: <rustc::ty::query::plumbing::JobOwner<'a, 'tcx, Q>>::start
  45: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  46: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_get_with
  47: rustc::traits::query::normalize_erasing_regions::<impl rustc::ty::context::TyCtxt<'cx, 'tcx, 'tcx>>::normalize_erasing_regions
  48: <rustc::ty::layout::LayoutCx<'tcx, rustc::ty::context::TyCtxt<'a, 'tcx, 'tcx>> as rustc_target::abi::LayoutOf>::layout_of
  49: rustc::traits::object_safety::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'tcx>>::virtual_call_violation_for_method::{{closure}}
  50: rustc::traits::object_safety::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'tcx>>::virtual_call_violation_for_method
  51: <&mut I as core::iter::iterator::Iterator>::next
  52: <core::iter::Filter<I, P> as core::iter::iterator::Iterator>::next
  53: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T, I>>::from_iter
  54: rustc::traits::object_safety::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'tcx>>::object_safety_violations_for_trait
  55: <core::iter::FlatMap<I, U, F> as core::iter::iterator::Iterator>::next
  56: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T, I>>::from_iter
  57: rustc::traits::object_safety::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'tcx>>::object_safety_violations
  58: rustc::traits::object_safety::is_object_safe_provider
  59: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::is_object_safe<'tcx>>::compute
  60: rustc::dep_graph::graph::DepGraph::with_task_impl
  61: <rustc::ty::query::plumbing::JobOwner<'a, 'tcx, Q>>::start
  62: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  63: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_get_with
  64: <rustc_data_structures::obligation_forest::ObligationForest<O>>::process_obligations
  65: <rustc::traits::fulfill::FulfillmentContext<'tcx> as rustc::traits::engine::TraitEngine<'tcx>>::select_where_possible
  66: <rustc::traits::fulfill::FulfillmentContext<'tcx> as rustc::traits::engine::TraitEngine<'tcx>>::select_all_or_error
  67: rustc_typeck::check::FnCtxt::select_all_obligations_or_error
  68: rustc::ty::context::GlobalCtxt::enter_local
  69: rustc_typeck::check::wfcheck::check_item_well_formed
  70: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::check_item_well_formed<'tcx>>::compute
  71: rustc::dep_graph::graph::DepGraph::with_task_impl
  72: <rustc::ty::query::plumbing::JobOwner<'a, 'tcx, Q>>::start
  73: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  74: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_get_with
  75: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::ensure_query
  76: <rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'v>>::visit_item
  77: rustc::hir::Crate::visit_all_item_likes
  78: rustc_typeck::check_crate
  79: <std::thread::local::LocalKey<T>>::with
  80: rustc::ty::context::TyCtxt::create_and_enter
  81: rustc_driver::driver::compile_input
  82: rustc_driver::run_compiler_with_pool
  83: <scoped_tls::ScopedKey<T>>::set
  84: rustc_driver::run_compiler
  85: <scoped_tls::ScopedKey<T>>::set
query stack during panic:
#0 [normalize_projection_ty] normalizing `Canonical { max_universe: U0, variables: [CanonicalVarInfo { kind: Region(U0) }, CanonicalVarInfo { kind: Region(U0) }], value: ParamEnvAnd { param_env: ParamEnv { caller_bounds: [Binder(TraitPredicate(<Self as CloneablePredicate<'_, T>>)), Binder(TraitPredicate(<T as std::marker::Sized>)), Binder(ProjectionPredicate(ProjectionTy { substs: [Self, (T,)], item_def_id: DefId(2/0:985 ~ core[7549]::ops[0]::function[0]::FnOnce[0]::Output[0]) }, bool)), Binder(TraitPredicate(<Self as std::ops::Fn<(T,)>>)), Binder(TraitPredicate(<Self as std::ops::FnMut<(T,)>>)), Binder(TraitPredicate(<Self as std::ops::FnOnce<(T,)>>)), Binder(OutlivesPredicate(Self, ReLateBound(DebruijnIndex(1), BrAnon(0))))], reveal: All }, value: ProjectionTy { substs: [Self, ReLateBound(DebruijnIndex(0), BrAnon(1)), T], item_def_id: DefId(2/0:985 ~ core[7549]::ops[0]::function[0]::FnOnce[0]::Output[0]) } } }`
#1 [normalize_ty_after_erasing_regions] normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [Binder(TraitPredicate(<Self as CloneablePredicate<'a, T>>)), Binder(TraitPredicate(<T as std::marker::Sized>)), Binder(ProjectionPredicate(ProjectionTy { substs: [Self, (T,)], item_def_id: DefId(2/0:985 ~ core[7549]::ops[0]::function[0]::FnOnce[0]::Output[0]) }, bool)), Binder(TraitPredicate(<Self as std::ops::Fn<(T,)>>)), Binder(TraitPredicate(<Self as std::ops::FnMut<(T,)>>)), Binder(TraitPredicate(<Self as std::ops::FnOnce<(T,)>>)), Binder(OutlivesPredicate(Self, ReEarlyBound(1, 'a)))], reveal: All }, value: &dyn CloneablePredicate<T, Output=<Self as std::ops::FnOnce<T>>::Output> }`
#2 [is_object_safe] determine object safety of trait `CloneablePredicate`
#3 [check_item_well_formed] processing `<impl std::clone::Clone for std::boxed::Box<(dyn CloneablePredicate<'a, T, Output=bool, Output=bool> + 'a)>>`
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.33.0-nightly (a7be40c65 2018-12-26) running on x86_64-unknown-linux-gnu

Metadata

Metadata

Labels

I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions