rust-lang / rust-lang/rust-analyzer
Run Doctest inside trait implementations in modules fails for some types
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
When you have a trait implementation for a type inside a module (i.e. not crate root), for some types the Run Doctest lens at the top of doctests for trait methods fails to run any test.
It seems that affected types are primitive types (str, u32, char...) and types with non-alphanumerical characters in them (&T, (T, T), [T; N]...).
Curiously enough, the issue only seems to encounter within modules; when the trait implementation is moved to the crate root, Run Doctest does its job just fine regardless of the type used (as far as I could tell).
Example:
mod hi {
pub trait Trait {
fn foo();
}
impl Trait for char {
/// ```rust
/// assert_eq!(1 + 1, 2);
/// ```
fn foo() {}
}
}

The issue seems to be that the type name is, for some reason, dropped from the path passed to --package.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal Rust example in the issue and the Run Doctest action for trait methods inside a module. Inspect the path passed to --package, especially for primitive and non-alphanumeric types; done means the doctest runs for these implementations in modules as it does at crate root.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- testing-qa, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100