rust-lang / rust-lang/rust-analyzer

Run Doctest inside trait implementations in modules fails for some types

Open
#8,248 19 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-ide C-bug S-actionable
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() {}
    }
}

Screenshot_20210330_015905

The issue seems to be that the type name is, for some reason, dropped from the path passed to --package.

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.