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
Member

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

Activity

added
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.
on Jan 20, 2019
ehuss

ehuss commented on Jan 20, 2019

@ehuss
Contributor

This was regressed by #54861 and has been fixed by #56793.

carols10cents

carols10cents commented on Jan 20, 2019

@carols10cents
MemberAuthor

Aha. I don't know why I didn't think to check beta last night, but is indeed not an issue in 1.33.0-beta.1.

I don't think the fix is significant enough for a point release in and of itself, but if one ends up happening (i don't see anything nominated right now) I think it'd be worth considering including the fix.

Going to close this but tag the fixed PR. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

        Participants

        @ehuss@carols10cents

        Issue actions

          `rustdoc --test` that passes with Rust 1.31.0 and fails with Rust 1.32.0, involving `use` paths · Issue #57767 · rust-lang/rust