Skip to content

Compiler panics while trying to implement DispatchFromDyn #71036

Closed
@timothee-haudebourg

Description

@timothee-haudebourg

I was playing with DisplatchFromDyn while I encountered a

thread 'rustc' panicked at 'index out of bounds: the len is 1 but the index is 1'

The simplest example I have producing the bug is

#![feature(unsize, dispatch_from_dyn)]

use std::marker::Unsize;
use std::ops::DispatchFromDyn;

struct Inner<'a, T: ?Sized> {
	value: &'a T
}

impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Inner<'a, U>> for Inner<'a, T> {}

impl<'a, T: ?Sized> Inner<'a, T> {
	fn new(value: &'a T) -> Inner<'a, T> {
		Inner {
			value
		}
	}
}

pub struct Local<'a, T: ?Sized> {
	inner: &'a Inner<'a, T>
}

impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Local<'a, U>> for Local<'a, T> {}

impl<'a, T: ?Sized> Local<'a, T> {
	fn new(inner: &'a Inner<'a, T>) -> Local<'a, T> {
		Local {
			inner
		}
	}
}

Here is a link to the playground.
It works if I remove the Inner struct and put the &'a T directly in Local.

The complete backtrace is

thread 'rustc' panicked at 'index out of bounds: the len is 1 but the index is 1', /rustc/94d346360da50f159e0dc777dc9bc3c5b6b51a00/src/librustc_middle/ty/subst.rs:333:43
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1069
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1504
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:218
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:515
  12: rust_begin_unwind
             at src/libstd/panicking.rs:419
  13: core::panicking::panic_fmt
             at src/libcore/panicking.rs:111
  14: core::panicking::panic_bounds_check
             at src/libcore/panicking.rs:69
  15: rustc_trait_selection::traits::select::SelectionContext::assemble_candidates
  16: rustc_trait_selection::traits::select::SelectionContext::candidate_from_obligation_no_cache
  17: rustc_query_system::dep_graph::graph::DepGraph<K>::with_anon_task
  18: rustc_trait_selection::traits::select::SelectionContext::candidate_from_obligation
  19: rustc_trait_selection::traits::select::SelectionContext::evaluate_stack
  20: rustc_query_system::dep_graph::graph::DepGraph<K>::with_anon_task
  21: rustc_trait_selection::traits::select::SelectionContext::evaluate_predicate_recursively
  22: rustc_infer::infer::InferCtxt::probe
  23: rustc_trait_selection::traits::select::SelectionContext::evaluate_root_obligation
  24: rustc_middle::ty::context::GlobalCtxt::enter_local
  25: rustc_traits::evaluate_obligation::evaluate_obligation
  26: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::evaluate_obligation>::compute
  27: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  28: rustc_query_system::query::plumbing::get_query
  29: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt>::evaluate_obligation
  30: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt>::evaluate_obligation_no_overflow
  31: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt>::suggest_change_mut
  32: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::InferCtxtExt>::report_selection_error
  33: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::InferCtxtExt>::report_fulfillment_errors
  34: rustc_middle::ty::context::GlobalCtxt::enter_local
  35: rustc_typeck::coherence::builtin::check_trait
  36: rustc_typeck::coherence::coherent_trait
  37: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::coherent_trait>::compute
  38: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  39: rustc_query_system::query::plumbing::get_query
  40: rustc_query_system::query::plumbing::ensure_query
  41: rustc_session::session::Session::track_errors
  42: rustc_typeck::check_crate
  43: rustc_interface::passes::analysis
  44: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  45: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  46: rustc_query_system::query::plumbing::get_query
  47: rustc_middle::ty::context::tls::enter_global
  48: rustc_interface::interface::run_compiler_in_existing_thread_pool
  49: scoped_tls::ScopedKey<T>::set
  50: rustc_ast::attr::with_globals
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/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.44.0-nightly (94d346360 2020-04-09) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
#0 [evaluate_obligation] evaluating trait selection obligation `&mut T: std::marker::Unsize`
#1 [coherent_trait] coherence checking all impls of trait `std::ops::DispatchFromDyn`
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

For more information about this error, try `rustc --explain E0601`.
error: could not compile `playground`.

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

This issue has been assigned to @doctorn via this comment.

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-dispatch_from_dyn`#![feature(dispatch_from_dyn)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions