Skip to content

delegation: OOM #155060

Open
Open

Description

@matthiaskrgr

I tried this code:

#![feature(fn_delegation)]
trait Trait<T> {
    fn foo<U>(&self, _: dyn Trait) {}
}

reuse Trait::<_>::foo::<i32> as x;

fn main() {}

I expected to see this happen:
no oom

Instead, this happened:
oom

Meta

rustc --version --verbose:

rustc 1.96.0-nightly (a87c9b960 2026-04-09)
binary: rustc
commit-hash: a87c9b96031d4d8698bb0cd6533e83bc6d77ddaa
commit-date: 2026-04-09
host: x86_64-unknown-linux-gnu
release: 1.96.0-nightly
LLVM version: 22.1.2
Backtrace

   8,68%  librustc_driver-5ecf1647954ff888.so             [.] rustc_query_impl::execution::collect_active_query_jobs
   4,59%  librustc_driver-5ecf1647954ff888.so             [.] rustc_query_impl::execution::collect_active_query_jobs_inner::<rustc_middle::query::caches::DefIdCache<rustc_middle::query::erase::ErasedData<[u8; 16]>>>
   3,57%  librustc_driver-5ecf1647954ff888.so             [.] rustc_query_impl::execution::collect_active_query_jobs_inner::<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::ErasedData<[u8; 0]>, rustc_middle::dep_graph::graph::DepNodeIndex>>

Activity

  1. added
    I-compilememIssue: Problems and improvements with respect to memory usage during compilation.
    C-bugCategory: This is a bug.
    on Apr 9, 2026
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Apr 9, 2026
  3. spqr79 commented on Apr 9, 2026

    @spqr79
  4. aerooneqq commented on Apr 10, 2026

    @aerooneqq
    Contributor

    #154389 will fix OOM, the problem that delayed lowering of delegations causes query cycles will be hopefully soon fixed with more infrastructural solution.

  5. petrochenkov commented on Apr 15, 2026

    @petrochenkov
    Contributor

    Output now:

    error: internal compiler error: query cycle when printing cycle detected
      |
      = note: ...when lowering the delayed AST owner `x`
    note: ...which requires computing function signature of `Trait::foo`...
     --> src/main.rs:5:5
      |
    5 |     fn foo<U>(&self, _: dyn Trait) {}
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      = note: ...which requires calculating trimmed def paths...
      = note: ...which requires looking up span for `x`...
      = note: ...which requires getting HIR ID of `x`...
      = note: ...which again requires lowering the delayed AST owner `x`, completing the cycle
      = note: cycle used when getting HIR crate items
      = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
    
    error[E0391]: cycle detected when getting HIR crate items
      |
      = note: ...which requires lowering the delayed AST owner `x`...
    note: ...which requires computing function signature of `Trait::foo`...
     --> src/main.rs:5:5
      |
    5 |     fn foo<U>(&self, _: dyn Trait) {}
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      = note: ...which requires calculating trimmed def paths...
      = note: ...which again requires getting HIR crate items, completing the cycle
      = note: cycle used when running analysis passes on crate `playground`
      = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
    
    For more information about this error, try `rustc --explain E0391`.
    
  6. aerooneqq commented on Apr 22, 2026

    @aerooneqq
    Contributor

    Other examples from #154169 (will not reopen it, let this issue track the problem):

    #![feature(fn_delegation)]
    #![allow(incomplete_features)]
    
    trait Trait<T> {
        fn foo(&self, x: T) -> S { x }
    }
    struct F;
    
    struct S<T>(F, T);
    
    impl<T, U> Trait<T> for S<U> {
        reuse to_reuse::foo { &self.0 }
    }
    
    fn main() {
        let s = S(F, 42);
        assert_eq!(S::<i32>::foo(F, 1), 1);
    }
    #![feature(fn_delegation)]
    #![allow(incomplete_features)]
    
    trait Trait {
        fn foo() -> Self::Assoc;
        fn bar(&self) -> u8;
    }
    
    impl Trait for u8 {
        fn bar(&self) -> u8 { 1 }
    }
    
    struct S(u8);
    
    impl Trait for S {
        reuse Trait::* { &self.0 }
        fn bar(&self) -> u8 { 2 }
    }
    
    fn main() {}
    #![feature(fn_delegation)]
    #![allow(incomplete_features)]
    
    trait Trait {
        fn foo(&self) -> Self::Assoc<3> {
            [(); 3]
        }
    }
    
    impl () {
        reuse Trait::*;
    }
    
    fn main() {}
  7. added
    T-compilerRelevant to the compiler 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 Oct 7, 2026
  8. added
    I-cycleIssue: A query cycle occurred while none was expected
    on Oct 29, 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.F-fn_delegation`#![feature(fn_delegation)]`I-compilememIssue: Problems and improvements with respect to memory usage during compilation.I-cycleIssue: A query cycle occurred while none was expectedT-compilerRelevant to the compiler 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