Skip to content

Marking a doctest code block as edition2018 causes it not to run #65980

Closed

Description

@DevJac

I have a fresh Rust library, started with cargo new --lib foo, and I have the following in lib.rs:

/// Adds 1
/// ```edition2018
/// assert_eq!(1 + 1, 999)
/// ```
pub fn add_1(n: i32) -> i32 {
    n + 1
}

I can cargo build and cargo test this library. The doctest is obviously never run because 1 + 1 == 999 is false. The output from cargo test confirms this, showing that zero test were run.

The doctest book lead me to believe the doctest should still work, even if marked as edition2018.

Cargo.toml is:

[package]
name = "foo"
version = "0.1.0"
authors = ["..."]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cargo version: cargo 1.38.0 (23ef9a4ef 2019-08-20)
rustc version: rustc 1.38.0 (625451e37 2019-09-23)

Activity

  1. ehuss commented on Oct 31, 2019

    @ehuss
    Contributor

    That's really strange! It works on nightly...any nightly!

    I think it is due to this code:

    x if allow_error_code_check && x.starts_with("edition") => {
    // allow_error_code_check is true if we're on nightly, which
    // is needed for edition support
    data.edition = x[7..].parse::<Edition>().ok();

    Was this maybe forgotten to be stabilized when editions were stabilized?

  2. added
    A-doctestsArea: Documentation tests, run by rustdoc
    C-bugCategory: This is a bug.
    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
    on Nov 6, 2019
  3. DevJac commented on Nov 8, 2019

    @DevJac
    Author

    This still happens with Rust 1.39.0. I created a minimal project that demonstrates this bug at https://github.com/DevJac/rust_edition2018_doctest_bug_demo .

  4. ehuss commented on Nov 9, 2019

    @ehuss
    Contributor

    I posted PR #66238 to fix this.

  5. added a commit that references this issue on Nov 17, 2019
    18668f9
  6. added a commit that references this issue on Nov 18, 2019
    d67ca28
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

    A-doctestsArea: Documentation tests, run by rustdocC-bugCategory: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions