Skip to content

ICE Type parameter I/#1 (I/1) out of range when substituting #59956

Closed
@DutchGhost

Description

@DutchGhost

The following code ICE's on stable, beta and nightly, on both editions:

use std::marker::PhantomData;

struct Invariant<'id, I = Self> {
    lifetime: PhantomData<*mut &'id I>,
}

trait Contract<'s> {
    type Item: for<'r> Contract<'r>;
}

impl <'a, 'b> Contract<'b> for Invariant<'a> {
    type Item = Invariant<'b>;
}
Backtrace:

error: internal compiler error: src/librustc/ty/subst.rs:480: Type parameter `I/#1` (I/1) out of range when substituting (root type=Some(Invariant<'id, I>)) substs=[ReEarlyBound(0, 'a)]
  --> src/lib.rs:11:32
   |
11 | impl <'a, 'b> Contract<'b> for Invariant<'a> {
   |                                ^^^^^^^^^^^^^

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:558:9
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::span_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::span_bug_fmt
  14: <rustc::ty::subst::SubstFolder<'a, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
  15: <smallvec::SmallVec<A> as core::iter::traits::collect::FromIterator<<A as smallvec::Array>::Item>>::from_iter
  16: rustc::ty::fold::TypeFoldable::fold_with
  17: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable<'tcx> for &'tcx rustc::ty::TyS<'tcx>>::super_fold_with
  18: <rustc::ty::subst::SubstFolder<'a, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
  19: <(dyn rustc_typeck::astconv::AstConv<'gcx, 'tcx> + 'o)>::create_substs_for_ast_path::{{closure}}
  20: <(dyn rustc_typeck::astconv::AstConv<'gcx, 'tcx> + 'o)>::create_substs_for_ast_path
  21: rustc::hir::PathSegment::with_generic_args
  22: <(dyn rustc_typeck::astconv::AstConv<'gcx, 'tcx> + 'o)>::ast_path_substs_for_ty
  23: <(dyn rustc_typeck::astconv::AstConv<'gcx, 'tcx> + 'o)>::def_to_ty
  24: <(dyn rustc_typeck::astconv::AstConv<'gcx, 'tcx> + 'o)>::ast_ty_to_ty
  25: rustc_typeck::collect::type_of
  26: rustc::ty::query::__query_compute::type_of
  27: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::type_of<'tcx>>::compute
  28: rustc::dep_graph::graph::DepGraph::with_task_impl
  29: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  30: <rustc_typeck::collect::CollectItemTypesVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_item
  31: rustc::hir::map::Map::visit_item_likes_in_module
  32: rustc_typeck::collect::collect_mod_item_types
  33: rustc::ty::query::__query_compute::collect_mod_item_types
  34: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::collect_mod_item_types<'tcx>>::compute
  35: rustc::dep_graph::graph::DepGraph::with_task_impl
  36: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  37: rustc_typeck::collect::collect_item_types
  38: rustc::util::common::time
  39: rustc_typeck::check_crate
  40: <std::thread::local::LocalKey<T>>::with
  41: rustc::ty::context::TyCtxt::create_and_enter
  42: rustc_driver::driver::compile_input
  43: rustc_driver::run_compiler_with_pool
  44: <scoped_tls::ScopedKey<T>>::set
  45: rustc_driver::run_compiler
  46: syntax::with_globals
  47: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:87
  48: <F as alloc::boxed::FnBox<A>>::call_box
  49: std::sys::unix::thread::Thread::new::thread_start
             at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf/src/liballoc/boxed.rs:759
             at src/libstd/sys_common/thread.rs:14
             at src/libstd/sys/unix/thread.rs:81
  50: start_thread
  51: __clone
query stack during panic:
error[E0391]: cycle detected when processing `<impl at src/lib.rs:11:1: 13:2>`
  --> src/lib.rs:11:1
   |
11 | impl <'a, 'b> Contract<'b> for Invariant<'a> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: ...which again requires processing `<impl at src/lib.rs:11:1: 13:2>`, completing the cycle
note: cycle used when collecting item types in top-level module
  --> src/lib.rs:1:1
   |
1  | / use std::marker::PhantomData;
2  | |
3  | | struct Invariant<'id, I = Self> {
4  | |     lifetime: PhantomData<*mut &'id I>,
...  |
12 | |     type Item = Invariant<'b>;
13 | | }
   | |_^

error[E0391]: cycle detected when processing `<impl at src/lib.rs:11:1: 13:2>`
  --> src/lib.rs:11:1
   |
11 | impl <'a, 'b> Contract<'b> for Invariant<'a> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: ...which requires processing `<impl at src/lib.rs:11:1: 13:2>`...
  --> src/lib.rs:11:1
   |
11 | impl <'a, 'b> Contract<'b> for Invariant<'a> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: ...which again requires processing `<impl at src/lib.rs:11:1: 13:2>`, completing the cycle
note: cycle used when collecting item types in top-level module
  --> src/lib.rs:1:1
   |
1  | / use std::marker::PhantomData;
2  | |
3  | | struct Invariant<'id, I = Self> {
4  | |     lifetime: PhantomData<*mut &'id I>,
...  |
12 | |     type Item = Invariant<'b>;
13 | | }
   | |_^

#0 [type_of] processing `<[type error] as Contract<'b>>`
#1 [collect_mod_item_types] collecting item types in top-level module
end of query stack
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0391`.

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.34.0 (91856ed52 2019-04-10) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type lib

note: some of the compiler flags provided by cargo are hidden

error: Could not compile `playground`.

To learn more, run the command again with --verbose.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions