Skip to content

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

Closed
@DevJac

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)

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