Skip to content

Rustdoc does not obey --error-format for doctests error messages #81662

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
Nemo157 opened this issue Feb 2, 2021 · 1 comment · Fixed by #81675
Closed

Rustdoc does not obey --error-format for doctests error messages #81662

Nemo157 opened this issue Feb 2, 2021 · 1 comment · Fixed by #81675
Assignees
Labels
A-doctests Area: Documentation tests, run by rustdoc C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@Nemo157
Copy link
Member

Nemo157 commented Feb 2, 2021

I tried this code:

/// ```rust
/// foo();
/// ```
fn foo() {
    println!("Hello, world!");
}

I expected to see this happen: Running cargo test --doc --message-format=short uses short messages for all errors

Instead, this happened: The build failure for the doc test emits full error messages:

> cargo test --doc --message-format=short
   Compiling foo v0.1.0 (/tmp/tmp.RZdiSTk0tC/foo)
src/lib.rs:4:4: warning: function is never used: `foo`
warning: 1 warning emitted
    Finished test [unoptimized + debuginfo] target(s) in 0.11s
   Doc-tests foo

running 1 test
test src/lib.rs - foo (line 1) ... FAILED

failures:

---- src/lib.rs - foo (line 1) stdout ----
error[E0423]: expected function, found crate `foo`
 --> src/lib.rs:2:1
  |
4 | foo();
  | ^^^ not a function

error: aborting due to previous error

For more information about this error, try `rustc --explain E0423`.
Couldn't compile the test.

failures:
    src/lib.rs - foo (line 1)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.04s

error: test failed, to rerun pass '--doc'

Meta

rustc --version --verbose:

rustc 1.50.0-nightly (0f6f2d681 2020-12-06)
binary: rustc
commit-hash: 0f6f2d681b39c5f95459cd09cb936b6ceb27cd82
commit-date: 2020-12-06
host: x86_64-unknown-linux-gnu
release: 1.50.0-nightly
@Nemo157 Nemo157 added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. C-bug Category: This is a bug. A-doctests Area: Documentation tests, run by rustdoc labels Feb 2, 2021
@poliorcetics
Copy link
Contributor

@rustbot claim

@bors bors closed this as completed in e8aaa14 Feb 6, 2021
bors added a commit to rust-lang/cargo that referenced this issue Feb 24, 2021
Pass the error message format to rustdoc

- Goes with rust-lang/rust#81675.
- Will help with rust-lang/rust#81662.

This is my first PR to Cargo and I haven't finished reading the contributor guide yet, how should I add tests for this ? Did I had the code in the correct place ?
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-doctests Area: Documentation tests, run by rustdoc C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants