Skip to content

ICE: error from fully_perform, with HRTB on GAT #136666

Description

@Lunderberg

Code

Minimal example below, with rust playground link. This may be related to #130797, as both involve type inference when there is a HRTB over a GAT, though that bug specifically involves usage with trait objects, where this bug did not occur when using trait objects.

trait FunctionLikeTrait {}

impl<Func> FunctionLikeTrait for Func where Func: Fn() {}

trait ArgTrait {
    type Unwrapped<'a>;
}

impl<'t> ArgTrait for &'t () {
    type Unwrapped<'a> = &'a ();
}

struct FunctionWrapper<Func, Arg> {
    _phantom: std::marker::PhantomData<(Func, Arg)>,
}

impl<Func, Arg> FunctionLikeTrait for FunctionWrapper<Func, Arg>
where
    Func: Fn(Arg),
    for<'a> Arg: ArgTrait<Unwrapped<'a> = Arg>,
{
}

fn apply_func<Func, Arg>(_: Func)
where
    FunctionWrapper<Func, Arg>: FunctionLikeTrait,
{
}

fn main() {
    apply_func(|_: &()| {});
}

Meta

rustc --version --verbose:

rustc 1.86.0-nightly (a9730c3b5 2025-02-05)
binary: rustc
commit-hash: a9730c3b5f84a001c052c60c97ed0765e9ceac04
commit-date: 2025-02-05
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7

Also tested on stable channel, with the same behavior.

rustc 1.84.1 (e71f9a9a9 2025-01-27)
binary: rustc
commit-hash: e71f9a9a98b0faf423844bf0ba7438f29dc27d58
commit-date: 2025-01-27
host: x86_64-unknown-linux-gnu
release: 1.84.1
LLVM version: 19.1.5

Error output

<output>
   Compiling bug_mwe v0.1.0 (/home/username/bug_mwe)
note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: error performing operation: fully_perform
  --> src/main.rs:31:5
   |
31 |     apply_func(|_: &()| {});
   |     ^^^^^^^^^^^^^^^^^^^^^^^
   |
note: delayed at /rustc/a9730c3b5f84a001c052c60c97ed0765e9ceac04/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs:87:25 - disabled backtrace
  --> src/main.rs:31:5
   |
31 |     apply_func(|_: &()| {});
   |     ^^^^^^^^^^^^^^^^^^^^^^^

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: please attach the file at `/home/username/bug_mwe/rustc-ice-2025-02-06T15_08_40-780362.txt` to your bug report

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C link-arg=-B/usr/local/libexec/mold

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

query stack during panic:
end of query stack
error: could not compile `bug_mwe` (bin "bug_mwe")

Caused by:
  process didn't exit successfully: `/home/username/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name bug_mwe --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=81c7c60b51af13e3 -C extra-filename=-bca91fa17f684345 --out-dir /home/username/bug_mwe/target/debug/deps -L dependency=/home/username/bug_mwe/target/debug/deps -C link-arg=-B/usr/local/libexec/mold` (exit status: 101)
Backtrace

<backtrace>
note: delayed at /rustc/a9730c3b5f84a001c052c60c97ed0765e9ceac04/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs:87:25
         0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         1: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
         2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
         3: <rustc_errors::DiagCtxtHandle>::span_delayed_bug::<rustc_span::span_encoding::Span, alloc::string::String>
         4: <rustc_borrowck::type_check::TypeChecker>::fully_perform_op::<(), rustc_middle::ty::ParamEnvAnd<rustc_middle::traits::query::type_op::ProvePredicate>>
         5: <rustc_borrowck::type_check::TypeChecker>::normalize_and_prove_instantiated_predicates
         6: <rustc_borrowck::type_check::TypeVerifier as rustc_middle::mir::visit::Visitor>::visit_const_operand
         7: <rustc_borrowck::type_check::TypeVerifier as rustc_middle::mir::visit::Visitor>::visit_body
         8: rustc_borrowck::type_check::type_check
         9: rustc_borrowck::nll::compute_regions
        10: rustc_borrowck::do_mir_borrowck
        11: 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]>>
        12: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>, rustc_query_system::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        13: rustc_query_impl::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
        14: rustc_interface::passes::run_required_analyses
        15: rustc_interface::passes::analysis
        16: 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; 0]>>
        17: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 0]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        18: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
        19: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
        20: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
        21: std::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
        22: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        23: std::sys::pal::unix::thread::Thread::new::thread_start
        24: start_thread
                   at ./nptl/pthread_create.c:447:8
        25: clone3
                   at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78:0

Activity

  1. added
    C-bugCategory: This is a bug.
    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.
    on Feb 6, 2025
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Feb 6, 2025
  3. added
    T-typesRelevant to the types team, which will review and decide on the PR/issue.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Feb 6, 2025
  4. theemathas commented on Feb 7, 2025

    @theemathas
    Contributor

    Slightly simplified and reorganized:

    // Needed so that rust can infer that the A in what() is &()
    trait IsRef<T> {}
    struct Dummy;
    impl<'a> IsRef<&'a ()> for Dummy {}
    
    trait WithLifetime {
        type Output<'a>;
    }
    impl<'t> WithLifetime for &'t () {
        type Output<'a> = &'a ();
    }
    
    // Needed to prevent the two Foo impls from overlapping
    struct Wrap<A>(A);
    
    trait Unimplemented {}
    
    trait Foo {}
    impl<T> Foo for T where T: Unimplemented {}
    impl<A> Foo for Wrap<A>
    where
        Dummy: IsRef<A>,
        for<'a> A: WithLifetime<Output<'a> = A>,
    {
    }
    
    fn what<A>()
    where
        Wrap<A>: Foo,
    {
    }
    
    fn main() {
        what();
    }
  5. added
    S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.
    on Mar 9, 2025
  6. lcnr commented on Oct 5, 2026

    @lcnr
    Contributor

    duplicate of #124440. Will be fixed by next-solver

  7. added 3 commits that reference this issue on Oct 7, 2026
  8. added a commit that references this issue on Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types 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