Skip to content

Doctests do not set profile codegen options #6570

Open
@bspeice

Description

@bspeice

Problem
As currently stands, there's an inconsistency in doctests running with debug_assertions on even when code was compiled through cargo test --release. I would've expected that cargo test --release means that the doctests get compiled in release mode as well, but that doesn't appear to be the case.

Steps

//! Here's a doctest:
//!
//! ```rust
//! use doctest_da::my_function;
//!
//! if cfg!(debug_assertions) {
//!     assert!(my_function().is_ok());
//! } else {
//!     assert!(my_function().is_err());
//! }
//! ```

pub fn my_function() -> Result<(), ()>{
    if cfg!(debug_assertions) {
        Ok(())
    } else {
        Err(())
    }
}

Notes

I'm a bit confused on where exactly this issue may need to be filed. It seems related to #5777 and #5218, but because this hits doctests, #4669 and rust-lang/rust#45599 may take precedence. Let me know if I should move.

Output of cargo version:

cargo 1.32.0 (8610973aa 2019-01-02)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-doctestsArea: rustdoc --testA-profilesArea: profilesC-bugCategory: bugS-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or review

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions