Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
robinhundt opened this issue Oct 1, 2022 · 2 comments · Fixed by #105247
Closed

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

robinhundt opened this issue Oct 1, 2022 · 2 comments · Fixed by #105247
Labels
C-bug Category: This is a bug. F-return_position_impl_trait_in_trait `#![feature(return_position_impl_trait_in_trait)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@robinhundt
Copy link

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

@robinhundt robinhundt added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 1, 2022
@robinhundt
Copy link
Author

@rustbot label +requires-nightly +F-return_position_impl_trait_in_trait

@rustbot rustbot added F-return_position_impl_trait_in_trait `#![feature(return_position_impl_trait_in_trait)]` requires-nightly This issue requires a nightly compiler in some way. labels Oct 1, 2022
@compiler-errors
Copy link
Member

This doesn't ICE after #102334, but it does fail to compile with:

error[E0310]: the parameter type `Item` may not live long enough
  --> /home/gh-compiler-errors/test.rs:11:5
   |
11 |     fn foo<'a>(&'a self) -> impl Debug where Item: 'a {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `Item` will meet its required lifetime bounds...
   |
note: ...that is required by this bound
  --> /home/gh-compiler-errors/test.rs:11:52
   |
11 |     fn foo<'a>(&'a self) -> impl Debug where Item: 'a {
   |                                                    ^^
help: consider adding an explicit lifetime bound...
   |
10 | impl<Item: 'static, D: Debug + Clone> Foo<Item> for D {
   |          +++++++++

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-return_position_impl_trait_in_trait `#![feature(return_position_impl_trait_in_trait)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants