Skip to content

rustdoc --test that passes with Rust 1.31.0 and fails with Rust 1.32.0, involving use paths #57767

Closed
@carols10cents

Description

@carols10cents

I'm not sure what changed in here, but a contributor to the book just discovered we have a doctest that passed with stable 1.31.0 and fails to compile with stable 1.32.0.

If I extract the code into a library and remove the rustdoc specific bits (the code hiding #s), it compiles successfully with both Rust 1.31.0 and Rust 1.32.0, so I suspect something with rustdoc to be the cause? I'm not entirely sure though.

I looked for recent PRs and issues and didn't find anything that looked relevant, other than uniform path stabilization, and I hope it's not that.

This is the one test from the book extracted for reproduction (but still within a markdown file as it is in the book because that seems important):

# Rustdoc Weirdness Example

Here is the doc test that passes with Rust 1.31.0 and fails with Rust 1.32.0:

```rust
//! # Art
//!
//! A library for modeling artistic concepts.

pub mod kinds {
    /// The primary colors according to the RYB color model.
    pub enum PrimaryColor {
        Red,
        Yellow,
        Blue,
    }

    /// The secondary colors according to the RYB color model.
    pub enum SecondaryColor {
        Orange,
        Green,
        Purple,
    }
}

pub mod utils {
    use crate::kinds::*;

    /// Combines two primary colors in equal amounts to create
    /// a secondary color.
    pub fn mix(c1: PrimaryColor, c2: PrimaryColor) -> SecondaryColor {
        // --snip--
#         SecondaryColor::Orange
    }
}
# fn main() {}
```

Weird, right???

To reproduce, put this text into something.md. If you use Rust 1.31.0 and run rustdoc --test something.md, it results in 1 test passing. If you use Rust 1.32.0 and run rustdoc --test something.md, it can't compile the test and results in these compiler errors:

---- src/ch14-02-publishing-to-crates-io.md - Rustdoc_Weirdness_Example (line 5) stdout ----
error[E0432]: unresolved import `crate::kinds`
  --> src/ch14-02-publishing-to-crates-io.md:27:16
   |
24 |     use crate::kinds::*;
   |                ^^^^^ maybe a missing `extern crate kinds;`?

error[E0433]: failed to resolve: use of undeclared type or module `SecondaryColor`
  --> src/ch14-02-publishing-to-crates-io.md:33:9
   |
30 |         SecondaryColor::Orange
   |         ^^^^^^^^^^^^^^ use of undeclared type or module `SecondaryColor`

error[E0412]: cannot find type `PrimaryColor` in this scope
  --> src/ch14-02-publishing-to-crates-io.md:31:20
   |
28 |     pub fn mix(c1: PrimaryColor, c2: PrimaryColor) -> SecondaryColor {
   |                    ^^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `PrimaryColor` in this scope
  --> src/ch14-02-publishing-to-crates-io.md:31:38
   |
28 |     pub fn mix(c1: PrimaryColor, c2: PrimaryColor) -> SecondaryColor {
   |                                      ^^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `SecondaryColor` in this scope
  --> src/ch14-02-publishing-to-crates-io.md:31:55
   |
28 |     pub fn mix(c1: PrimaryColor, c2: PrimaryColor) -> SecondaryColor {
   |                                                       ^^^^^^^^^^^^^^ not found in this scope

thread 'src/ch14-02-publishing-to-crates-io.md - Rustdoc_Weirdness_Example (line 5)' panicked at 'couldn't compile the test', src/librustdoc/test.rs:323:13

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions