Skip to content

Slow autocomplete for methods generic over a trait with Deref super-trait and GAT #19502

@robinhundt

Description

@robinhundt

In my code base I've noticed significant performance regressions of r-a in certain methods after adding a generic associated type (GAT) to a trait. I've reduced the issue to the following. We need:

  • A trait with Deref as a super-trait
  • A GAT which needs to implement the trait itself
  • A method generic over this trait

If any of these is not present, autocomplete works fine, but if all three are present, autocomplete is unusably slow in the generic method, even for other parameters.

rust-analyzer version: rust-analyzer version: 0.3.2362-standalone

rustc version: rustc 1.85.1 (4eb161250 2025-03-15)

editor or extension: VSCode on NixOs-unstable

relevant settings: None

code snippet to reproduce:

use std::{marker::PhantomData, ops::Deref};

trait Foo<T>: Deref<Target = u8> {
    type FooKind<E>: Foo<E>;

    fn foo(&mut self) {
        todo!()
    }
}


fn slow_autocomplete(f: &mut impl Foo<u8>, a: u8) {
    a.  // <-- Cursor here
}

fn fast_autocomplete(a: u8) {
    a.  // <-- Cursor here
}

struct Frob<T>(PhantomData<T>);

impl<T> Deref for Frob<T> {
    type Target = u8;

    fn deref(&self) -> &Self::Target {
        todo!()
    }
}

impl<T> Foo<T> for Frob<T> {
    type FooKind<E> = Frob<E>;
}

fn autocomplete_concrete_foo(f: Frob<u8>) {
    f.  // <-- Cursor here
}

Here is a GIF of the slow autocomplete.

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-chalkchalk related issueA-perfperformance issuesC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions