rust-lang / rust-lang/rust-analyzer

Never suggests importing anyhow::Result or anyhow::anyhow

Open
#19,198 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

For some reason Rust-analyzer never suggests importing anyhow::Result or anyhow::anyhow (a macro). I don't know if this is specific to anyhow but it's quite conspicuous because the import suggestion feature now works very reliably except for those imports (at least in my use).

As far as I remember they have never worked. It does work for anyhow::bail. At a guess Rust-analyzer doesn't suggest anything because anyhow is the name of the crate and it thinks you're going to type anyhow::, and Result is already available from the prelude. But I can't see any reason not to offer the import if there is one available. Especially if you type anyhow! because that's clearly not a crate name.

rust-analyzer version: rust-analyzer version: 0.3.2308-standalone (84b6936e08 2025-02-17)

rustc version: rustc 1.84.1 (e71f9a9a9 2025-01-27)

editor or extension: VSCode 0.3.2308

relevant settings: none

code snippet to reproduce:

fn foo() -> Result<()> {
}

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

No source file or test is named. Start by reproducing the issue with the provided Result<()> function and an anyhow! use, then trace rust-analyzer's import suggestions for anyhow::Result, anyhow::anyhow, and anyhow::bail. Done means the missing suggestions are offered and regression coverage verifies them.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.