rust-analyzer: Run Doctest inside trait implementations in modules fails for some types

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.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 19 (10 by maintainers)

Most upvoted comments

I don’t think a helper function is useful right now. Most code will probably have to handle special cases anyways if similar functionality is required.