rust-lang / rust-lang/rust

`doctest` should not be `opt-in`

Open
#117,529 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-doctests C-bug T-rustdoc
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

BUG

compile_fail should not be ignored on test function.

Actual

compile_fail is ignored on test function.

$ cargo test && echo OK
...
OK
pub fn add(left: usize, right: usize) -> usize {
    left + right
}

#[cfg(test)]
mod tests {
    use super::*;

    /// ```compile_fail
    /// let mut x = 5;
    /// x += 2;
    /// ```
    #[test]
    fn it_works() {
        let result = add(2, 2);
        assert_eq!(result, 4);
    }
}

Expected

compile_fail should not be ignored on test function.

Same as on non-test function.

$ cargo test
...
Test compiled successfully, but it's marked `compile_fail`.
...
/// ```compile_fail
/// let mut x = 5;
/// x += 2;
/// ```
pub fn add(left: usize, right: usize) -> usize {
    left + right
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn it_works() {
        let result = add(2, 2);
        assert_eq!(result, 4);
    }
}
Version
  • rustc 1.73.0 (cc66ad468 2023-10-03)

  • cargo 1.73.0 (9c4383fb5 2023-08-26)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report with the supplied Rust examples and cargo test, focusing on doctest handling for compile_fail on functions marked with #[test]. Compare this behavior with the non-test function example. Done means the test-function doctest is no longer ignored and reports failure when it compiles successfully despite the compile_fail marker.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.