Skip to content

fix: import trait associated items for builtin types - #23363

Open
KrishnaAdityaSrivastava wants to merge 2 commits into
rust-lang:masterfrom
KrishnaAdityaSrivastava:fix-builtin-type-trait-completion
Open

KrishnaAdityaSrivastava wants to merge 2 commits into
rust-lang:masterfrom
KrishnaAdityaSrivastava:fix-builtin-type-trait-completion

Conversation

@KrishnaAdityaSrivastava

@KrishnaAdityaSrivastava KrishnaAdityaSrivastava commented Sep 14, 2026

Copy link
Copy Markdown

Summary

Fixes #23135.

Trait associated items can be accessed through builtin types, but rust-analyzer previously failed to offer the corresponding import/completion for paths such as:

fn main() {
    bool::fmt(todo!());
}

rustc resolves fmt through traits such as core::fmt::Debug and core::fmt::Display, but rust-analyzer did not find those trait candidates during qualified-path import resolution.

Changes

  • Handle builtin types when resolving qualified-path imports.
  • Consider applicable trait candidates when resolving associated items on the resolved type.
  • Generate the appropriate trait import when the associated item comes from a trait.
  • Preserve the existing import resolution path for modules and other qualifiers.
  • Add a regression test for trait associated items accessed through bool.

Tests

  • cargo test -p ide-completion flyimport
  • cargo clippy -p ide-db -p ide-completion --all-targets -- --cap-lints warn
  • cargo xtask tidy

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 14, 2026
@ChayimFriedman2

Copy link
Copy Markdown
Contributor

This issue was already claimed. @szupzj18 do you still want to work on it?

Also, @KrishnaAdityaSrivastava did you use AI for this? Please read our AI policy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot import and complete like bool::fmt

3 participants