rust-lang / rust-lang/rust-analyzer

Attrs for generic parameter with impl Trait

Open
#16,478 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

rust-analyzer version: latest master (but really anything recent)

rustc version: rustc 1.74.0 (79e9716c9 2023-11-13)

relevant settings: None

Rust-analyzer panics when fetching Attrs for functions that have parameter types specified with impl Trait syntax.

trait Foo {}
impl Foo for () {}
fn foo(x: impl Foo) {
    ()
}

In the example above the function is generic over type of x , but ra panics when I attempt to fetch Attrs for the generic parameter.
More info and workaround can be seen in https://github.com/rust-lang/rust-analyzer/pull/16092#discussion_r1457269627

The bug happens in https://github.com/rust-lang/rust-analyzer/blob/8f6a72871ec87ed53cfe43a09fb284168a284e7e/crates/hir-def/src/generics.rs#L562 with the function file_id_and_params_of returning empty generic_params_list for the example above

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in crates/hir-def/src/generics.rs at file_id_and_params_of, using the minimal Foo and impl Trait example from the report to reproduce the panic when fetching Attrs for the generic parameter. Trace why generic_params_list is empty, then verify that fetching Attrs for the example no longer panics.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.