Skip to content

range start index 1 out of range for slice of length 0 #98598

Closed
@purplg

Description

@purplg

Code

pub trait Foo {
    type Output: Foo;
    
    fn baz() -> Self::Output;
}

pub struct Bar;

impl Foo for &Bar {
    type Output = Bar;

    fn baz() -> Self::Output {
        Foo::baz();

        Self::Output {}
    }
}

Meta

I reproduced this bug on nightly and master but did not exist on stable or beta.

rustc --version --verbose:

rustc 1.64.0-dev
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.64.0-dev
LLVM version: 14.0.6
rustc 1.64.0-nightly (c80c4b8fd 2022-06-26)
binary: rustc
commit-hash: c80c4b8fdcf3da69cd483e2fec172c9b1f95842c
commit-date: 2022-06-26
host: x86_64-unknown-linux-gnu
release: 1.64.0-nightly
LLVM version: 14.0.5

Error output

thread 'rustc' panicked at 'range start index 1 out of range for slice of length 0', library/core/src/slice/index.rs:52:5
Backtrace

thread 'rustc' panicked at 'range start index 1 out of range for slice of length 0', library/core/src/slice/index.rs:52:5
stack backtrace:
   0: rust_begin_unwind
             at /rustc/20a6f3a8a8ce5ae18d06b12cd7904bc5294ca753/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/20a6f3a8a8ce5ae18d06b12cd7904bc5294ca753/library/core/src/panicking.rs:142:14
   2: core::slice::index::slice_start_index_len_fail_rt
             at /rustc/20a6f3a8a8ce5ae18d06b12cd7904bc5294ca753/library/core/src/slice/index.rs:52:5
   3: core::ops::function::FnOnce::call_once
             at /rustc/20a6f3a8a8ce5ae18d06b12cd7904bc5294ca753/library/core/src/ops/function.rs:248:5
   4: core::intrinsics::const_eval_select
             at /rustc/20a6f3a8a8ce5ae18d06b12cd7904bc5294ca753/library/core/src/intrinsics.rs:2376:5
   5: core::slice::index::slice_start_index_len_fail
             at /rustc/20a6f3a8a8ce5ae18d06b12cd7904bc5294ca753/library/core/src/slice/index.rs:42:9
   6: <rustc_middle::ty::generics::Generics>::own_substs
   7: <rustc_infer::infer::error_reporting::need_type_info::FindInferSourceVisitor as rustc_hir::intravisit::Visitor>::visit_expr
   8: <rustc_infer::infer::error_reporting::need_type_info::FindInferSourceVisitor as rustc_hir::intravisit::Visitor>::visit_expr
   9: <rustc_infer::infer::InferCtxt>::emit_inference_failure_err
  10: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::InferCtxtPrivExt>::maybe_report_ambiguity
  11: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::InferCtxtExt>::report_fulfillment_errors
  12: <rustc_infer::infer::InferCtxtBuilder>::enter::<&rustc_middle::ty::context::TypeckResults, <rustc_typeck::check::inherited::InheritedBuilder>::enter<rustc_typeck::check::typeck_with_fallback<rustc_typeck::check::typeck::{closure#0}>::{closure#1}, &rustc_middle::ty::context::TypeckResults>::{closure#0}>
  13: rustc_typeck::check::typeck
  14: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId, &rustc_middle::ty::context::TypeckResults>
  15: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalDefId, &rustc_middle::ty::context::TypeckResults>>
  16: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck
  17: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_typeck::check::typeck_item_bodies::{closure#0}>
  18: rustc_typeck::check::typeck_item_bodies
  19: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, (), ()>
  20: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), ()>>
  21: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::typeck_item_bodies, rustc_query_impl::plumbing::QueryCtxt>
  22: <rustc_session::session::Session>::time::<(), rustc_typeck::check_crate::{closure#7}>
  23: rustc_typeck::check_crate
  24: rustc_interface::passes::analysis
  25: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, (), core::result::Result<(), rustc_errors::ErrorGuaranteed>>
  26: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), core::result::Result<(), rustc_errors::ErrorGuaranteed>>>
  27: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
  28: <rustc_interface::passes::QueryContext>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}::{closure#3}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
  29: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorGuaranteed>>
  30: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
  31: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.64.0-nightly (20a6f3a8a 2022-06-25) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental

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

query stack during panic:
#0 [typeck] type-checking `<impl at src/lib.rs:9:1: 17:2>::some_function`
#1 [typeck_item_bodies] type-checking all item bodies
#2 [analysis] running analysis passes on this crate
end of query stack
For more information about this error, try `rustc --explain E0277`.
error: could not compile `rust-bug` due to previous error

Let me know if I can further assist.

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.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.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions