Skip to content

ICE with lifetime bound on generic trait parameter in function returning RPITIT #102552

Closed
@robinhundt

Description

@robinhundt

Code

#![feature(return_position_impl_trait_in_trait)]

use core::fmt::Debug;


trait Foo<Item> {
    fn foo<'a>(&'a self) -> impl Debug where Item: 'a;
}

impl<Item, D: Debug + Clone> Foo<Item> for D {
    fn foo<'a>(&'a self) -> impl Debug where Item: 'a {
        self.clone()
    }
}

[Playground]

Meta

rustc --version --verbose:

rustc 1.66.0-nightly (8ce3204af 2022-09-30)
binary: rustc
commit-hash: 8ce3204af9463db3192ea1eb31c45c2f6d4b5ae6
commit-date: 2022-09-30
host: x86_64-unknown-linux-gnu
release: 1.66.0-nightly
LLVM version: 15.0.2

Error output

error: internal compiler error: compiler/rustc_middle/src/ty/subst.rs:610:13: Region parameter out of range when substituting in region 'a (index=2)

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/8ce3204af9463db3192ea1eb31c45c2f6d4b5ae6/compiler/rustc_errors/src/lib.rs:1496:9

query stack during panic:
#0 [check_mod_item_types] checking item types in top-level module
#1 [analysis] running analysis passes on this crate
end of query stack
warning: `playground` (lib) generated 1 warning
error: could not compile `playground`; 1 warning emitted

Backtrace

error: internal compiler error: compiler/rustc_middle/src/ty/subst.rs:610:13: Region parameter out of range when substituting in region 'a (index=2)

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/8ce3204af9463db3192ea1eb31c45c2f6d4b5ae6/compiler/rustc_errors/src/lib.rs:1496:9
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: std::panic::panic_any::<rustc_errors::ExplicitBug>
   2: <rustc_errors::HandlerInner>::bug::<&alloc::string::String>
   3: <rustc_errors::Handler>::bug::<&alloc::string::String>
   4: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, ()>::{closure#0}, ()>
   5: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>
   6: rustc_middle::util::bug::bug_fmt
   7: <rustc_middle::ty::subst::SubstFolder as rustc_middle::ty::fold::TypeFolder>::fold_region::region_param_out_of_range
   8: <rustc_middle::ty::generics::GenericPredicates>::instantiate_into
   9: <rustc_middle::ty::generics::GenericPredicates>::instantiate
  10: rustc_trait_selection::traits::project::opt_normalize_projection_type
  11: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc_middle::ty::fold::TypeFolder>::fold_ty
  12: <rustc_infer::infer::InferCtxt as rustc_trait_selection::infer::InferCtxtExt>::partially_normalize_associated_types_in::<rustc_middle::ty::sty::FnSig>
  13: <rustc_trait_selection::traits::engine::ObligationCtxt>::normalize::<rustc_middle::ty::sty::FnSig>
  14: <rustc_infer::infer::InferCtxtBuilder>::enter::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_hir_analysis::check::compare_method::compare_predicate_entailment::{closure#0}>
  15: rustc_hir_analysis::check::compare_method::compare_impl_method
  16: rustc_hir_analysis::check::check::check_item_type
  17: rustc_hir_analysis::check::check::check_mod_item_types
  18: <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, ()>
  19: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalDefId, ()>>
  20: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::check_mod_item_types, rustc_query_impl::plumbing::QueryCtxt>
  21: <rustc_middle::hir::map::Map>::for_each_module::<rustc_hir_analysis::check_crate::{closure#6}::{closure#0}>
  22: rustc_hir_analysis::check_crate
  23: rustc_interface::passes::analysis
  24: <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>>
  25: 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>>>
  26: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
  27: <rustc_interface::passes::QueryContext>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}::{closure#3}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
  28: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>
  29: <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.

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.66.0-nightly (8ce3204af 2022-09-30) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
#0 [check_mod_item_types] checking item types in top-level module
#1 [analysis] running analysis passes on this crate
end of query stack

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-return_position_impl_trait_in_trait`#![feature(return_position_impl_trait_in_trait)]`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.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