Skip to content

ICE: impl_trait_in_fn_trait_return index out of bounds #132518

Closed as not planned
Closed as not planned
@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

#![feature(impl_trait_in_fn_trait_return)]
trait Original {}

trait Erased {
    fn f(&self) -> Box<dyn Fn()>;
}

impl<T: Original> Erased for T {
    fn f(&self) -> Box<dyn Fn() -> impl Debug> {}
}

original:

trait Original {
    type Output = &'a i32;
}

trait Erased {
    fn f(&self) -> Box<dyn Fn()>;
}

impl<T: Original> Erased for T {
    fn f(&self) -> Box<dyn Fn() -> impl Debug> {
        Box::new(<T as Original>::f())
        //~^ ERROR the associated type `impl Fn()` may not live long enough
    }
}

fn main () {}

Version information

rustc 1.84.0-nightly (ef972a346 2024-11-02)
binary: rustc
commit-hash: ef972a346668ed4234d1a43ed4ad7ca4e9c58d51
commit-date: 2024-11-02
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1

Possibly related line of code:

struct ToFreshVars<'tcx> {
args: Vec<ty::GenericArg<'tcx>>,
}
impl<'tcx> BoundVarReplacerDelegate<'tcx> for ToFreshVars<'tcx> {
fn replace_region(&mut self, br: ty::BoundRegion) -> ty::Region<'tcx> {
self.args[br.var.index()].expect_region()
}
fn replace_ty(&mut self, bt: ty::BoundTy) -> Ty<'tcx> {
self.args[bt.var.index()].expect_ty()
}
fn replace_const(&mut self, bv: ty::BoundVar) -> ty::Const<'tcx> {
self.args[bv.index()].expect_const()

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zcrate-attr=feature(impl_trait_in_fn_trait_return)

Program output

error[E0404]: expected trait, found derive macro `Debug`
 --> /tmp/icemaker_global_tempdir.aLWTMBZ9RJ13/rustc_testrunner_tmpdir_reporting.jCrqcENVHurl/mvce.rs:8:41
  |
8 |     fn f(&self) -> Box<dyn Fn() -> impl Debug> {}
  |                                         ^^^^^ not a trait
  |
help: consider importing this trait instead
  |
1 + use std::fmt::Debug;
  |

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.aLWTMBZ9RJ13/rustc_testrunner_tmpdir_reporting.jCrqcENVHurl/mvce.rs:9:2
  |
9 | }
  |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.aLWTMBZ9RJ13/rustc_testrunner_tmpdir_reporting.jCrqcENVHurl/mvce.rs`

error[E0582]: binding for associated type `Output` references an anonymous lifetime, which does not appear in the trait input types
 --> /tmp/icemaker_global_tempdir.aLWTMBZ9RJ13/rustc_testrunner_tmpdir_reporting.jCrqcENVHurl/mvce.rs:8:36
  |
8 |     fn f(&self) -> Box<dyn Fn() -> impl Debug> {}
  |                                    ^^^^^^^^^^
  |
  = note: lifetimes appearing in an associated or opaque type are not considered constrained
  = note: consider introducing a named lifetime parameter

thread 'rustc' panicked at compiler/rustc_infer/src/infer/mod.rs:1227:26:
index out of bounds: the len is 0 but the index is 0
stack backtrace:
   0:     0x74b5c82584aa - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hce429173f4835cf6
   1:     0x74b5c8a040ca - core::fmt::write::hd474fbdfe63c8008
   2:     0x74b5c9e7b011 - std::io::Write::write_fmt::ha6b1be51a74d6c82
   3:     0x74b5c8258302 - std::sys::backtrace::BacktraceLock::print::h9a37e75f7192ac21
   4:     0x74b5c825a806 - std::panicking::default_hook::{{closure}}::hd9ac8cf20a0b7897
   5:     0x74b5c825a650 - std::panicking::default_hook::hdde16dcfa738c4aa
   6:     0x74b5c72ddb49 - std[85c38ff02e03f0e6]::panicking::update_hook::<alloc[39d8aefd6e9d2d6]::boxed::Box<rustc_driver_impl[8ea1370c87ac4c52]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x74b5c825af18 - std::panicking::rust_panic_with_hook::h6eef9cc88a2d4e79
   8:     0x74b5c825acea - std::panicking::begin_panic_handler::{{closure}}::h1205ca5cc99eca9e
   9:     0x74b5c8258959 - std::sys::backtrace::__rust_end_short_backtrace::hc8595ee39bc3afe1
  10:     0x74b5c825a9ac - rust_begin_unwind
  11:     0x74b5c4ccefd0 - core::panicking::panic_fmt::h1d5a93f25b0815c9
  12:     0x74b5c692a2bb - core::panicking::panic_bounds_check::hf94db17f1ec1b22c
  13:     0x74b5ca632f0d - <rustc_middle[b16c40c3cb132ea9]::ty::fold::BoundVarReplacer<<rustc_infer[276bb3fd71d62c97]::infer::InferCtxt>::instantiate_binder_with_fresh_vars::ToFreshVars> as rustc_type_ir[45f01c5603667543]::fold::FallibleTypeFolder<rustc_middle[b16c40c3cb132ea9]::ty::context::TyCtxt>>::try_fold_region.cold
  14:     0x74b5c98510f0 - <&rustc_middle[b16c40c3cb132ea9]::ty::list::RawList<(), rustc_middle[b16c40c3cb132ea9]::ty::generic_args::GenericArg> as rustc_type_ir[45f01c5603667543]::fold::TypeFoldable<rustc_middle[b16c40c3cb132ea9]::ty::context::TyCtxt>>::try_fold_with::<rustc_middle[b16c40c3cb132ea9]::ty::fold::BoundVarReplacer<<rustc_infer[276bb3fd71d62c97]::infer::InferCtxt>::instantiate_binder_with_fresh_vars::ToFreshVars>>
  15:     0x74b5c98517c2 - <rustc_middle[b16c40c3cb132ea9]::ty::fold::BoundVarReplacer<<rustc_infer[276bb3fd71d62c97]::infer::InferCtxt>::instantiate_binder_with_fresh_vars::ToFreshVars> as rustc_type_ir[45f01c5603667543]::fold::TypeFolder<rustc_middle[b16c40c3cb132ea9]::ty::context::TyCtxt>>::fold_ty
  16:     0x74b5c9850ed0 - <rustc_infer[276bb3fd71d62c97]::infer::InferCtxt>::instantiate_binder_with_fresh_vars::<rustc_type_ir[45f01c5603667543]::predicate::ExistentialProjection<rustc_middle[b16c40c3cb132ea9]::ty::context::TyCtxt>>
  17:     0x74b5c984bd50 - <rustc_type_ir[45f01c5603667543]::binder::Binder<rustc_middle[b16c40c3cb132ea9]::ty::context::TyCtxt, rustc_type_ir[45f01c5603667543]::predicate::ExistentialProjection<rustc_middle[b16c40c3cb132ea9]::ty::context::TyCtxt>> as rustc_type_ir[45f01c5603667543]::relate::Relate<rustc_middle[b16c40c3cb132ea9]::ty::context::TyCtxt>>::relate::<rustc_infer[276bb3fd71d62c97]::infer::relate::type_relating::TypeRelating>
  18:     0x74b5c8b06f81 - <&rustc_middle[b16c40c3cb132ea9]::ty::list::RawList<(), rustc_type_ir[45f01c5603667543]::binder::Binder<rustc_middle[b16c40c3cb132ea9]::ty::context::TyCtxt, rustc_type_ir[45f01c5603667543]::predicate::ExistentialPredicate<rustc_middle[b16c40c3cb132ea9]::ty::context::TyCtxt>>> as rustc_type_ir[45f01c5603667543]::relate::Relate<rustc_middle[b16c40c3cb132ea9]::ty::context::TyCtxt>>::relate::<rustc_infer[276bb3fd71d62c97]::infer::relate::type_relating::TypeRelating>::{closure#2}
  19:     0x74b5c8af1086 - rustc_type_ir[45f01c5603667543]::relate::structurally_relate_tys::<rustc_middle[b16c40c3cb132ea9]::ty::context::TyCtxt, rustc_infer[276bb3fd71d62c97]::infer::relate::type_relating::TypeRelating>::{closure#0}
  20:     0x74b5c8ae9027 - <rustc_infer[276bb3fd71d62c97]::infer::relate::type_relating::TypeRelating as rustc_type_ir[45f01c5603667543]::relate::TypeRelation<rustc_middle[b16c40c3cb132ea9]::ty::context::TyCtxt>>::tys
  21:     0x74b5c8aecd82 - rustc_type_ir[45f01c5603667543]::relate::structurally_relate_tys::<rustc_middle[b16c40c3cb132ea9]::ty::context::TyCtxt, rustc_infer[276bb3fd71d62c97]::infer::relate::type_relating::TypeRelating>::{closure#0}
  22:     0x74b5c8ae9027 - <rustc_infer[276bb3fd71d62c97]::infer::relate::type_relating::TypeRelating as rustc_type_ir[45f01c5603667543]::relate::TypeRelation<rustc_middle[b16c40c3cb132ea9]::ty::context::TyCtxt>>::tys
  23:     0x74b5c9b26aa1 - rustc_hir_analysis[614b5c894f29c678]::check::check::check_impl_items_against_trait
  24:     0x74b5c9b1586d - rustc_hir_analysis[614b5c894f29c678]::check::check::check_item_type
  25:     0x74b5c63ea51b - rustc_hir_analysis[614b5c894f29c678]::check::wfcheck::check_well_formed
  26:     0x74b5c8dc9907 - rustc_query_impl[c0318c643aee4f05]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c0318c643aee4f05]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b16c40c3cb132ea9]::query::erase::Erased<[u8; 1usize]>>
  27:     0x74b5c8dc9058 - rustc_query_system[708ef94f36d60214]::query::plumbing::try_execute_query::<rustc_query_impl[c0318c643aee4f05]::DynamicConfig<rustc_query_system[708ef94f36d60214]::query::caches::VecCache<rustc_span[94bdfa138cad1541]::def_id::LocalDefId, rustc_middle[b16c40c3cb132ea9]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[c0318c643aee4f05]::plumbing::QueryCtxt, false>
  28:     0x74b5c8dc8cd0 - rustc_query_impl[c0318c643aee4f05]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  29:     0x74b5c8dc9b80 - rustc_hir_analysis[614b5c894f29c678]::check::wfcheck::check_mod_type_wf
  30:     0x74b5c8dc99af - rustc_query_impl[c0318c643aee4f05]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c0318c643aee4f05]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b16c40c3cb132ea9]::query::erase::Erased<[u8; 1usize]>>
  31:     0x74b5c999ac7d - rustc_query_system[708ef94f36d60214]::query::plumbing::try_execute_query::<rustc_query_impl[c0318c643aee4f05]::DynamicConfig<rustc_query_system[708ef94f36d60214]::query::caches::DefaultCache<rustc_span[94bdfa138cad1541]::def_id::LocalModDefId, rustc_middle[b16c40c3cb132ea9]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[c0318c643aee4f05]::plumbing::QueryCtxt, false>
  32:     0x74b5c999aa18 - rustc_query_impl[c0318c643aee4f05]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  33:     0x74b5c911db2f - rustc_hir_analysis[614b5c894f29c678]::check_crate
  34:     0x74b5c8ee384a - rustc_interface[46946d42a40348f7]::passes::run_required_analyses
  35:     0x74b5c95d451e - rustc_interface[46946d42a40348f7]::passes::analysis
  36:     0x74b5c95d44ef - rustc_query_impl[c0318c643aee4f05]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c0318c643aee4f05]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b16c40c3cb132ea9]::query::erase::Erased<[u8; 1usize]>>
  37:     0x74b5c99a1bae - rustc_query_system[708ef94f36d60214]::query::plumbing::try_execute_query::<rustc_query_impl[c0318c643aee4f05]::DynamicConfig<rustc_query_system[708ef94f36d60214]::query::caches::SingleCache<rustc_middle[b16c40c3cb132ea9]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[c0318c643aee4f05]::plumbing::QueryCtxt, false>
  38:     0x74b5c99a188e - rustc_query_impl[c0318c643aee4f05]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  39:     0x74b5c9865292 - rustc_interface[46946d42a40348f7]::interface::run_compiler::<core[d9ceb9bc2a384707]::result::Result<(), rustc_span[94bdfa138cad1541]::ErrorGuaranteed>, rustc_driver_impl[8ea1370c87ac4c52]::run_compiler::{closure#0}>::{closure#1}
  40:     0x74b5c98f0590 - std[85c38ff02e03f0e6]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[46946d42a40348f7]::util::run_in_thread_with_globals<rustc_interface[46946d42a40348f7]::util::run_in_thread_pool_with_globals<rustc_interface[46946d42a40348f7]::interface::run_compiler<core[d9ceb9bc2a384707]::result::Result<(), rustc_span[94bdfa138cad1541]::ErrorGuaranteed>, rustc_driver_impl[8ea1370c87ac4c52]::run_compiler::{closure#0}>::{closure#1}, core[d9ceb9bc2a384707]::result::Result<(), rustc_span[94bdfa138cad1541]::ErrorGuaranteed>>::{closure#0}, core[d9ceb9bc2a384707]::result::Result<(), rustc_span[94bdfa138cad1541]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d9ceb9bc2a384707]::result::Result<(), rustc_span[94bdfa138cad1541]::ErrorGuaranteed>>
  41:     0x74b5c98f09ab - <<std[85c38ff02e03f0e6]::thread::Builder>::spawn_unchecked_<rustc_interface[46946d42a40348f7]::util::run_in_thread_with_globals<rustc_interface[46946d42a40348f7]::util::run_in_thread_pool_with_globals<rustc_interface[46946d42a40348f7]::interface::run_compiler<core[d9ceb9bc2a384707]::result::Result<(), rustc_span[94bdfa138cad1541]::ErrorGuaranteed>, rustc_driver_impl[8ea1370c87ac4c52]::run_compiler::{closure#0}>::{closure#1}, core[d9ceb9bc2a384707]::result::Result<(), rustc_span[94bdfa138cad1541]::ErrorGuaranteed>>::{closure#0}, core[d9ceb9bc2a384707]::result::Result<(), rustc_span[94bdfa138cad1541]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d9ceb9bc2a384707]::result::Result<(), rustc_span[94bdfa138cad1541]::ErrorGuaranteed>>::{closure#1} as core[d9ceb9bc2a384707]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  42:     0x74b5c98f1479 - std::sys::pal::unix::thread::Thread::new::thread_start::h00969398ad9e9953
  43:     0x74b5cb27839d - <unknown>
  44:     0x74b5cb2fd49c - <unknown>
  45:                0x0 - <unknown>

error: 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: please make sure that you have updated to the latest nightly

note: rustc 1.84.0-nightly (ef972a346 2024-11-02) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z crate-attr=feature(impl_trait_in_fn_trait_return) -Z dump-mir-dir=dir

query stack during panic:
#0 [check_well_formed] checking that `<impl at /tmp/icemaker_global_tempdir.aLWTMBZ9RJ13/rustc_testrunner_tmpdir_reporting.jCrqcENVHurl/mvce.rs:7:1: 7:31>` is well-formed
#1 [check_mod_type_wf] checking that types are well-formed in top-level module
end of query stack
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0404, E0582, E0601.
For more information about an error, try `rustc --explain E0404`.

@rustbot label +F-impl_trait_in_fn_trait_return

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-impl_trait_in_fn_trait_return`#![feature(impl_trait_in_fn_trait_return)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-has-bisectionStatus: A bisection has been found for this issueS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-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