Skip to content

ICE for return_position_impl_trait_in_trait #105197

New issue

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

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

Already on GitHub? # to your account

Closed
smessmer opened this issue Dec 3, 2022 · 4 comments · Fixed by #105255
Closed

ICE for return_position_impl_trait_in_trait #105197

smessmer opened this issue Dec 3, 2022 · 4 comments · Fixed by #105255
Assignees
Labels
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.

Comments

@smessmer
Copy link

smessmer commented Dec 3, 2022

Code

This commit introduces code that causes an ICE, i.e. before this commit it compiles fine and after the commit it ICEs:
smessmer/lockable@10923f1

This is on Rust nightly with features async_fn_in_trait and return_position_impl_trait_in_trait.

Meta

rustc --version --verbose:

rustc 1.67.0-nightly (32e613bba 2022-12-02)
binary: rustc
commit-hash: 32e613bbaafee1bcabba48a2257b838f8d1c03d3
commit-date: 2022-12-02
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4

Error output

error: internal compiler error: compiler/rustc_middle/src/ty/subst.rs:724:13: Region parameter out of range when substituting in region '_ (index=4, substs = [Self, K, V, ReEarlyBound(4, '_)])

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/compiler/rustc_errors/src/lib.rs:1575:9
stack backtrace:
   0:     0x7f0c109f5a5a - std::backtrace_rs::backtrace::libunwind::trace::h445f1a380ebe24fa
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f0c109f5a5a - std::backtrace_rs::backtrace::trace_unsynchronized::h8c542444dc84bbad
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f0c109f5a5a - std::sys_common::backtrace::_print_fmt::hd1e3793b0f95c644
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f0c109f5a5a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h515025d5c2825d78
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f0c0c959e4e - core::fmt::write::hfd15a46634ae3152
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/core/src/fmt/mod.rs:1208:17
   5:     0x7f0c109e9cc5 - std::io::Write::write_fmt::h74b2e38eb2a622bf
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/std/src/io/mod.rs:1682:15
   6:     0x7f0c109f5825 - std::sys_common::backtrace::_print::hd2af8aafbe5d4e4d
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7f0c109f5825 - std::sys_common::backtrace::print::hc83e0ce2c452dd90
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7f0c109f7baf - std::panicking::default_hook::{{closure}}::h6fa5498814662258
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/std/src/panicking.rs:267:22
   9:     0x7f0c109f78eb - std::panicking::default_hook::h27c5cc64dbc8482d
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/std/src/panicking.rs:286:9
  10:     0x7f0c0fc4ef24 - rustc_driver[1a6385c1c72d16e7]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f0c109f83ad - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h555d7d9f22ed347d
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/alloc/src/boxed.rs:2032:9
  12:     0x7f0c109f83ad - std::panicking::rust_panic_with_hook::hf0b4a17e8b00f779
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/std/src/panicking.rs:692:13
  13:     0x7f0c100911f1 - std[79527836cf90b5dd]::panicking::begin_panic::<rustc_errors[643e9caaba05b420]::ExplicitBug>::{closure#0}
  14:     0x7f0c10090256 - std[79527836cf90b5dd]::sys_common::backtrace::__rust_end_short_backtrace::<std[79527836cf90b5dd]::panicking::begin_panic<rustc_errors[643e9caaba05b420]::ExplicitBug>::{closure#0}, !>
  15:     0x7f0c100ed3a6 - std[79527836cf90b5dd]::panicking::begin_panic::<rustc_errors[643e9caaba05b420]::ExplicitBug>
  16:     0x7f0c1008e626 - std[79527836cf90b5dd]::panic::panic_any::<rustc_errors[643e9caaba05b420]::ExplicitBug>
  17:     0x7f0c1008dc66 - <rustc_errors[643e9caaba05b420]::HandlerInner>::bug::<&alloc[976f33e9556b75e2]::string::String>
  18:     0x7f0c1008d8c0 - <rustc_errors[643e9caaba05b420]::Handler>::bug::<&alloc[976f33e9556b75e2]::string::String>
  19:     0x7f0c101560be - rustc_middle[19d5e5a4d6179ade]::ty::context::tls::with_context_opt::<rustc_middle[19d5e5a4d6179ade]::ty::context::tls::with_opt<rustc_middle[19d5e5a4d6179ade]::util::bug::opt_span_bug_fmt<rustc_span[c03eaf4ea18165a3]::span_encoding::Span>::{closure#0}, ()>::{closure#0}, ()>
  20:     0x7f0c10158586 - rustc_middle[19d5e5a4d6179ade]::util::bug::opt_span_bug_fmt::<rustc_span[c03eaf4ea18165a3]::span_encoding::Span>
  21:     0x7f0c0e376e83 - rustc_middle[19d5e5a4d6179ade]::util::bug::bug_fmt
  22:     0x7f0c1009cce1 - <rustc_middle[19d5e5a4d6179ade]::ty::subst::SubstFolder as rustc_middle[19d5e5a4d6179ade]::ty::fold::TypeFolder>::fold_region::region_param_out_of_range
  23:     0x7f0c0dc1e5e4 - <rustc_middle[19d5e5a4d6179ade]::ty::generics::GenericPredicates>::instantiate_into
  24:     0x7f0c0dfb8be1 - <rustc_trait_selection[30af3b66b4bd6698]::traits::wf::WfPredicates>::compute_projection
  25:     0x7f0c0dfb174f - <rustc_trait_selection[30af3b66b4bd6698]::traits::wf::WfPredicates>::compute
  26:     0x7f0c0ddc0da7 - rustc_trait_selection[30af3b66b4bd6698]::traits::wf::predicate_obligations
  27:     0x7f0c0fd8ac67 - <&mut rustc_hir_analysis[9c428cfd855369e3]::check::wfcheck::check_return_position_impl_trait_in_trait_bounds::{closure#0}::{closure#0} as core[7075224b64f80aa]::ops::function::FnOnce<(&(rustc_middle[19d5e5a4d6179ade]::ty::Predicate, rustc_span[c03eaf4ea18165a3]::span_encoding::Span),)>>::call_once
  28:     0x7f0c0fd55631 - <rustc_trait_selection[30af3b66b4bd6698]::traits::engine::ObligationCtxt>::register_obligations::<core[7075224b64f80aa]::iter::adapters::flatten::FlatMap<core[7075224b64f80aa]::slice::iter::Iter<(rustc_middle[19d5e5a4d6179ade]::ty::Predicate, rustc_span[c03eaf4ea18165a3]::span_encoding::Span)>, alloc[976f33e9556b75e2]::vec::Vec<rustc_infer[7976ff388409cbf8]::traits::Obligation<rustc_middle[19d5e5a4d6179ade]::ty::Predicate>>, rustc_hir_analysis[9c428cfd855369e3]::check::wfcheck::check_return_position_impl_trait_in_trait_bounds::{closure#0}::{closure#0}>>
  29:     0x7f0c0ddba4fd - rustc_hir_analysis[9c428cfd855369e3]::check::wfcheck::check_fn_or_method
  30:     0x7f0c0ddab79b - rustc_hir_analysis[9c428cfd855369e3]::check::wfcheck::check_associated_item
  31:     0x7f0c0dda18e7 - rustc_hir_analysis[9c428cfd855369e3]::check::wfcheck::check_well_formed
  32:     0x7f0c0e25265c - <rustc_query_system[c29954e9c418d3e1]::dep_graph::graph::DepGraph<rustc_middle[19d5e5a4d6179ade]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[19d5e5a4d6179ade]::ty::context::TyCtxt, rustc_hir[d4549fac27bc3fb6]::hir_id::OwnerId, ()>
  33:     0x7f0c0e2513cd - rustc_query_system[c29954e9c418d3e1]::query::plumbing::get_query::<rustc_query_impl[81623dbe8f24b13f]::queries::check_well_formed, rustc_query_impl[81623dbe8f24b13f]::plumbing::QueryCtxt>
  34:     0x7f0c0ed47e08 - rustc_data_structures[61c58c87d46f5182]::sync::par_for_each_in::<&[rustc_hir[d4549fac27bc3fb6]::hir::TraitItemId], <rustc_middle[19d5e5a4d6179ade]::hir::ModuleItems>::par_trait_items<rustc_hir_analysis[9c428cfd855369e3]::check::wfcheck::check_mod_type_wf::{closure#2}>::{closure#0}>
  35:     0x7f0c0f51ab97 - rustc_hir_analysis[9c428cfd855369e3]::check::wfcheck::check_mod_type_wf
  36:     0x7f0c0e7bcebc - <rustc_query_system[c29954e9c418d3e1]::dep_graph::graph::DepGraph<rustc_middle[19d5e5a4d6179ade]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[19d5e5a4d6179ade]::ty::context::TyCtxt, rustc_span[c03eaf4ea18165a3]::def_id::LocalDefId, ()>
  37:     0x7f0c0e7bad8f - rustc_query_system[c29954e9c418d3e1]::query::plumbing::try_execute_query::<rustc_query_impl[81623dbe8f24b13f]::plumbing::QueryCtxt, rustc_query_system[c29954e9c418d3e1]::query::caches::VecCache<rustc_span[c03eaf4ea18165a3]::def_id::LocalDefId, ()>>
  38:     0x7f0c0f013913 - rustc_query_system[c29954e9c418d3e1]::query::plumbing::get_query::<rustc_query_impl[81623dbe8f24b13f]::queries::check_mod_type_wf, rustc_query_impl[81623dbe8f24b13f]::plumbing::QueryCtxt>
  39:     0x7f0c0df73f48 - rustc_data_structures[61c58c87d46f5182]::sync::par_for_each_in::<&[rustc_hir[d4549fac27bc3fb6]::hir_id::OwnerId], <rustc_middle[19d5e5a4d6179ade]::hir::map::Map>::par_for_each_module<rustc_hir_analysis[9c428cfd855369e3]::check_crate::{closure#5}::{closure#0}::{closure#0}>::{closure#0}>
  40:     0x7f0c0df73d33 - <rustc_session[2f16cc1ca0f45371]::session::Session>::track_errors::<rustc_hir_analysis[9c428cfd855369e3]::check_crate::{closure#5}, ()>
  41:     0x7f0c0df7364d - rustc_hir_analysis[9c428cfd855369e3]::check_crate
  42:     0x7f0c0df732eb - rustc_interface[ee8495dca531fc0c]::passes::analysis
  43:     0x7f0c0f37a83f - <rustc_query_system[c29954e9c418d3e1]::dep_graph::graph::DepGraph<rustc_middle[19d5e5a4d6179ade]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[19d5e5a4d6179ade]::ty::context::TyCtxt, (), core[7075224b64f80aa]::result::Result<(), rustc_errors[643e9caaba05b420]::ErrorGuaranteed>>
  44:     0x7f0c0f3794e7 - rustc_query_system[c29954e9c418d3e1]::query::plumbing::try_execute_query::<rustc_query_impl[81623dbe8f24b13f]::plumbing::QueryCtxt, rustc_query_system[c29954e9c418d3e1]::query::caches::DefaultCache<(), core[7075224b64f80aa]::result::Result<(), rustc_errors[643e9caaba05b420]::ErrorGuaranteed>>>
  45:     0x7f0c0f378f40 - rustc_query_system[c29954e9c418d3e1]::query::plumbing::get_query::<rustc_query_impl[81623dbe8f24b13f]::queries::analysis, rustc_query_impl[81623dbe8f24b13f]::plumbing::QueryCtxt>
  46:     0x7f0c0ed85b1b - <rustc_interface[ee8495dca531fc0c]::passes::QueryContext>::enter::<rustc_driver[1a6385c1c72d16e7]::run_compiler::{closure#1}::{closure#2}::{closure#2}, core[7075224b64f80aa]::result::Result<(), rustc_errors[643e9caaba05b420]::ErrorGuaranteed>>
  47:     0x7f0c0ed7d4ce - <rustc_interface[ee8495dca531fc0c]::interface::Compiler>::enter::<rustc_driver[1a6385c1c72d16e7]::run_compiler::{closure#1}::{closure#2}, core[7075224b64f80aa]::result::Result<core[7075224b64f80aa]::option::Option<rustc_interface[ee8495dca531fc0c]::queries::Linker>, rustc_errors[643e9caaba05b420]::ErrorGuaranteed>>
  48:     0x7f0c0ed784e8 - rustc_span[c03eaf4ea18165a3]::with_source_map::<core[7075224b64f80aa]::result::Result<(), rustc_errors[643e9caaba05b420]::ErrorGuaranteed>, rustc_interface[ee8495dca531fc0c]::interface::run_compiler<core[7075224b64f80aa]::result::Result<(), rustc_errors[643e9caaba05b420]::ErrorGuaranteed>, rustc_driver[1a6385c1c72d16e7]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  49:     0x7f0c0ed77fd5 - <scoped_tls[6605aed902b0fb11]::ScopedKey<rustc_span[c03eaf4ea18165a3]::SessionGlobals>>::set::<rustc_interface[ee8495dca531fc0c]::interface::run_compiler<core[7075224b64f80aa]::result::Result<(), rustc_errors[643e9caaba05b420]::ErrorGuaranteed>, rustc_driver[1a6385c1c72d16e7]::run_compiler::{closure#1}>::{closure#0}, core[7075224b64f80aa]::result::Result<(), rustc_errors[643e9caaba05b420]::ErrorGuaranteed>>
  50:     0x7f0c0ed775c2 - std[79527836cf90b5dd]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[ee8495dca531fc0c]::util::run_in_thread_pool_with_globals<rustc_interface[ee8495dca531fc0c]::interface::run_compiler<core[7075224b64f80aa]::result::Result<(), rustc_errors[643e9caaba05b420]::ErrorGuaranteed>, rustc_driver[1a6385c1c72d16e7]::run_compiler::{closure#1}>::{closure#0}, core[7075224b64f80aa]::result::Result<(), rustc_errors[643e9caaba05b420]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7075224b64f80aa]::result::Result<(), rustc_errors[643e9caaba05b420]::ErrorGuaranteed>>
  51:     0x7f0c0f4fc8e8 - <<std[79527836cf90b5dd]::thread::Builder>::spawn_unchecked_<rustc_interface[ee8495dca531fc0c]::util::run_in_thread_pool_with_globals<rustc_interface[ee8495dca531fc0c]::interface::run_compiler<core[7075224b64f80aa]::result::Result<(), rustc_errors[643e9caaba05b420]::ErrorGuaranteed>, rustc_driver[1a6385c1c72d16e7]::run_compiler::{closure#1}>::{closure#0}, core[7075224b64f80aa]::result::Result<(), rustc_errors[643e9caaba05b420]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7075224b64f80aa]::result::Result<(), rustc_errors[643e9caaba05b420]::ErrorGuaranteed>>::{closure#1} as core[7075224b64f80aa]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  52:     0x7f0c109ff5e3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hb948150b9fd67a86
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/alloc/src/boxed.rs:2000:9
  53:     0x7f0c109ff5e3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h2f842213b427eb19
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/alloc/src/boxed.rs:2000:9
  54:     0x7f0c109ff5e3 - std::sys::unix::thread::Thread::new::thread_start::h2adb6f1223042fb8
                               at /rustc/32e613bbaafee1bcabba48a2257b838f8d1c03d3/library/std/src/sys/unix/thread.rs:108:17
  55:     0x7f0c0c631b43 - start_thread
                               at ./nptl/./nptl/pthread_create.c:442:8
  56:     0x7f0c0c6c3a00 - clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
  57:                0x0 - <unknown>

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.67.0-nightly (32e613bba 2022-12-02) 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_well_formed] checking that `lockable_trait::Lockable::lock_all_entries` is well-formed
#1 [check_mod_type_wf] checking that types are well-formed in module `lockable_trait`
#2 [analysis] running analysis passes on this crate
end of query stack

@smessmer smessmer 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 Dec 3, 2022
@compiler-errors compiler-errors self-assigned this Dec 3, 2022
@compiler-errors
Copy link
Member

compiler-errors commented Dec 3, 2022

Minimized:

#![feature(async_fn_in_trait)]
#![feature(return_position_impl_trait_in_trait)]

use std::future::Future;
use std::marker::PhantomData;

trait Lockable<K, V> {
    async fn lock_all_entries(
        &self,
    ) -> impl Future<Output = Guard<'_>>;
}

struct Guard<'a>(PhantomData<&'a ()>);

searched nightlies: from nightly-2022-11-01 to nightly-2022-12-02
regressed nightly: nightly-2022-11-22
searched commit range: a28f3c8...b7bc90f
regressed commit: 7fe6f36

bisected with cargo-bisect-rustc v0.6.4

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --access github --timeout 30 --start 2022-11-01 --end 2022-12-02 --regress ice 

cc @cjgillot -- those bidirectional outlives predicates you install in gather_explicit_predicates_of for opaques don't line up correctly when we have nested RPITITs, it seems 🤔

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 8, 2022
…errors

Make nested RPIT inherit the parent opaque's generics.

Fixes rust-lang#105197

r? `@compiler-errors`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 8, 2022
…errors

Make nested RPIT inherit the parent opaque's generics.

Fixes rust-lang#105197

r? ``@compiler-errors``
@bors bors closed this as completed in e826a9a Dec 9, 2022
RalfJung pushed a commit to RalfJung/miri that referenced this issue Dec 9, 2022
Make nested RPIT inherit the parent opaque's generics.

Fixes rust-lang/rust#105197

r? ```@compiler-errors```
@smessmer
Copy link
Author

Thanks, fix confirmed

JohnTitor pushed a commit to JohnTitor/rust that referenced this issue Jan 12, 2023
…jgillot

Revert "Make nested RPITIT inherit the parent opaque's generics."

This reverts commit e2d41f4, and adjusts the `tests/ui/async-await/in-trait/nested-rpit.rs` test.

r? `@cjgillot`

fixes rust-lang#106332, manually verified because it had no minimization :/

reopens rust-lang#105197
cc rust-lang#106729
@matthiaskrgr matthiaskrgr reopened this Jan 13, 2023
@Luk-ESC
Copy link
Contributor

Luk-ESC commented Oct 12, 2023

Couldn't reproduce this with the minimized version or the original commit

@compiler-errors
Copy link
Member

Oh, yeah, this got fixed by changing the capture rules for RPITIT.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
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.
Projects
Development

Successfully merging a pull request may close this issue.

4 participants