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: failure to relate an opaque to itself should result in an error later on #117392

Open
kmicklas opened this issue Oct 30, 2023 · 4 comments
Open
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kmicklas
Copy link
Contributor

Code

pub trait BorrowComposite {
    type Ref<'a>
    where
        Self: 'a;
}

impl BorrowComposite for () {
    type Ref<'a> = ();
}

pub trait Component<Args: BorrowComposite> {
    type Output;
}

impl<Args: BorrowComposite> Component<Args> for () {
    type Output = ();
}

struct Delay<Make> {
    _make: Make,
}

impl<
        Args: BorrowComposite,
        Make: for<'a> FnMut(Args::Ref<'a>) -> C,
        C: Component<Args>,
    > Component<Args> for Delay<Make>
{
    type Output = C::Output;
}

pub fn delay<
    Args: BorrowComposite,
    Make: for<'a> FnMut(Args::Ref<'a>) -> C,
    C: Component<Args>,
>(
    make: Make,
) -> impl Component<Args, Output = C::Output> {
    Delay { _make: make }
}

pub fn crash() -> impl Component<(), Output = ()> {
    delay(|()| delay(|()| ()))
}

Meta

rustc --version --verbose:

rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: x86_64-unknown-linux-gnu
release: 1.73.0
LLVM version: 17.0.2

The same issue occurs with the latest nightly too.

Error output

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: failure to relate an opaque to itself should result in an error later on
  --> crash/src/lib.rs:43:16
   |
43 |     delay(|()| delay(|()| ()))
   |                ^
   |
note: delayed at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/compiler/rustc_infer/src/infer/nll_relate/mod.rs:500:37
         0: <rustc_errors::HandlerInner>::emit_diagnostic
         1: <rustc_errors::Handler>::delay_span_bug::<rustc_span::span_encoding::Span, &str>
         2: rustc_borrowck::type_check::type_check
         3: rustc_borrowck::nll::compute_regions
         4: rustc_borrowck::do_mir_borrowck
         5: rustc_borrowck::mir_borrowck
         6: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
         7: <rustc_query_impl::query_impl::mir_borrowck::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId)>>::call_once
         8: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
         9: rustc_query_impl::query_impl::mir_borrowck::get_query_incr::__rust_end_short_backtrace
        10: <rustc_borrowck::type_check::TypeChecker>::prove_closure_bounds
        11: <rustc_borrowck::type_check::TypeChecker>::typeck_mir
        12: rustc_borrowck::type_check::type_check
        13: rustc_borrowck::nll::compute_regions
        14: rustc_borrowck::do_mir_borrowck
        15: rustc_borrowck::mir_borrowck
        16: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
        17: <rustc_query_impl::query_impl::mir_borrowck::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId)>>::call_once
        18: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
        19: rustc_query_impl::query_impl::mir_borrowck::get_query_incr::__rust_end_short_backtrace
        20: rustc_hir_analysis::collect::type_of::opaque::find_opaque_ty_constraints_for_rpit
        21: rustc_hir_analysis::collect::type_of::type_of
        22: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
        23: <rustc_query_impl::query_impl::type_of::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::DefId)>>::call_once
        24: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::DefId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
        25: rustc_query_impl::query_impl::type_of::get_query_incr::__rust_end_short_backtrace
        26: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::DefId, rustc_middle::query::erase::Erased<[u8; 8]>>>
        27: rustc_hir_analysis::check::check::check_mod_item_types
        28: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::check_mod_item_types::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 0]>>
        29: <rustc_query_impl::query_impl::check_mod_item_types::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalModDefId)>>::call_once
        30: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalModDefId, rustc_middle::query::erase::Erased<[u8; 0]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
        31: rustc_query_impl::query_impl::check_mod_item_types::get_query_incr::__rust_end_short_backtrace
        32: <rustc_middle::hir::map::Map>::for_each_module::<rustc_hir_analysis::check_crate::{closure#6}::{closure#0}>
        33: rustc_hir_analysis::check_crate
        34: rustc_interface::passes::analysis
        35: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
        36: <rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, ())>>::call_once
        37: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
        38: rustc_query_impl::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
        39: <rustc_interface::queries::QueryResult<&rustc_middle::ty::context::GlobalCtxt>>::enter::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#6}>
        40: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
        41: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
        42: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        43: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                   at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2007:9
        44: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                   at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2007:9
        45: std::sys::unix::thread::Thread::new::thread_start
                   at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys/unix/thread.rs:108:17
        46: start_thread
        47: __GI___clone3
  --> crash/src/lib.rs:43:16
   |
43 |     delay(|()| delay(|()| ()))
   |                ^

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.73.0 (cc66ad468 2023-10-03) 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:
end of query stack
Backtrace

It doesn't look like I get any more info with RUST_BACKTRACE=1.

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: failure to relate an opaque to itself should result in an error later on
  --> crash/src/lib.rs:43:16
   |
43 |     delay(|()| delay(|()| ()))
   |                ^
   |
note: delayed at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/compiler/rustc_infer/src/infer/nll_relate/mod.rs:500:37
         0: <rustc_errors::HandlerInner>::emit_diagnostic
         1: <rustc_errors::Handler>::delay_span_bug::<rustc_span::span_encoding::Span, &str>
         2: rustc_borrowck::type_check::type_check
         3: rustc_borrowck::nll::compute_regions
         4: rustc_borrowck::do_mir_borrowck
         5: rustc_borrowck::mir_borrowck
         6: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
         7: <rustc_query_impl::query_impl::mir_borrowck::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId)>>::call_once
         8: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
         9: rustc_query_impl::query_impl::mir_borrowck::get_query_incr::__rust_end_short_backtrace
        10: <rustc_borrowck::type_check::TypeChecker>::prove_closure_bounds
        11: <rustc_borrowck::type_check::TypeChecker>::typeck_mir
        12: rustc_borrowck::type_check::type_check
        13: rustc_borrowck::nll::compute_regions
        14: rustc_borrowck::do_mir_borrowck
        15: rustc_borrowck::mir_borrowck
        16: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
        17: <rustc_query_impl::query_impl::mir_borrowck::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId)>>::call_once
        18: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
        19: rustc_query_impl::query_impl::mir_borrowck::get_query_incr::__rust_end_short_backtrace
        20: rustc_hir_analysis::collect::type_of::opaque::find_opaque_ty_constraints_for_rpit
        21: rustc_hir_analysis::collect::type_of::type_of
        22: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
        23: <rustc_query_impl::query_impl::type_of::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::DefId)>>::call_once
        24: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::DefId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
        25: rustc_query_impl::query_impl::type_of::get_query_incr::__rust_end_short_backtrace
        26: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::DefId, rustc_middle::query::erase::Erased<[u8; 8]>>>
        27: rustc_hir_analysis::check::check::check_mod_item_types
        28: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::check_mod_item_types::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 0]>>
        29: <rustc_query_impl::query_impl::check_mod_item_types::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalModDefId)>>::call_once
        30: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalModDefId, rustc_middle::query::erase::Erased<[u8; 0]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
        31: rustc_query_impl::query_impl::check_mod_item_types::get_query_incr::__rust_end_short_backtrace
        32: <rustc_middle::hir::map::Map>::for_each_module::<rustc_hir_analysis::check_crate::{closure#6}::{closure#0}>
        33: rustc_hir_analysis::check_crate
        34: rustc_interface::passes::analysis
        35: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
        36: <rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, ())>>::call_once
        37: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
        38: rustc_query_impl::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
        39: <rustc_interface::queries::QueryResult<&rustc_middle::ty::context::GlobalCtxt>>::enter::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#6}>
        40: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
        41: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
        42: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        43: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                   at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2007:9
        44: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                   at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2007:9
        45: std::sys::unix::thread::Thread::new::thread_start
                   at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys/unix/thread.rs:108:17
        46: start_thread
        47: __GI___clone3
  --> crash/src/lib.rs:43:16
   |
43 |     delay(|()| delay(|()| ()))
   |                ^

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.73.0 (cc66ad468 2023-10-03) 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:
end of query stack

@kmicklas kmicklas 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 30, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 30, 2023
@kmicklas kmicklas changed the title ICE with lifetime GAT and HRTB closure ICE: failure to relate an opaque to itself should result in an error later on Oct 30, 2023
@matthiaskrgr
Copy link
Member

bit smaller:

pub trait BorrowComposite {
    type Ref<'a>: 'a;
}

impl BorrowComposite for () {
    type Ref<'a> = ();
}

pub trait Component<Args> {
    type Output;
}

impl<Args> Component<Args> for () {
    type Output = ();
}

pub fn delay<Args: BorrowComposite, Make: for<'a> FnMut(Args::Ref<'a>) -> C, C: Component<Args>>(
    make: Make,
) -> impl Component<Args> {
}

pub fn crash() -> impl Component<()> {
    delay(|()| delay(|()| ()))
}

pub fn main() {}

@matthiaskrgr
Copy link
Member

Regression in nightly-2022-09-14

found 10 bors merge commits in the specified range
commit[0] 2022-09-12: Auto merge of #101729 - oli-obk:miriup, r=oli-obk
commit[1] 2022-09-12: Auto merge of #101736 - GuillaumeGomez:rollup-f71kjdb, r=GuillaumeGomez
commit[2] 2022-09-13: Auto merge of #99556 - davidtwco:collapse-debuginfo, r=wesleywiser
commit[3] 2022-09-13: Auto merge of #100101 - BelovDV:issue-99429, r=petrochenkov
commit[4] 2022-09-13: Auto merge of #100640 - reitermarkus:socket-display-buffer, r=thomcc
commit[5] 2022-09-13: Auto merge of #96709 - jackh726:gats-stabilization, r=compiler-errors
commit[6] 2022-09-13: Auto merge of #101757 - Dylan-DPC:rollup-wkt6oe9, r=Dylan-DPC
commit[7] 2022-09-13: Auto merge of #101615 - compiler-errors:rpitit-perf, r=oli-obk
commit[8] 2022-09-13: Auto merge of #101086 - cjgillot:thir-param, r=oli-obk
commit[9] 2022-09-13: Auto merge of #101777 - matthiaskrgr:rollup-x2dyaa2, r=matthiaskrgr

@Jules-Bertholet
Copy link
Contributor

That "regression" would likely be due to #96709 which removed the GAT feature gate?

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 30, 2023
@compiler-errors
Copy link
Member

Probably just need to test before 2022-09-14 with the GAT feature gate enabled.

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Apr 15, 2024
@fmease fmease added A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. labels Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants