-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to display warnings in rustdoc #41678
Conversation
a65bab9
to
85521a1
Compare
Travis found a failure |
85521a1
to
90344be
Compare
90344be
to
f30ed77
Compare
src/librustdoc/markdown.rs
Outdated
@@ -166,6 +166,9 @@ pub fn test(input: &str, cfgs: Vec<String>, libs: SearchPaths, externs: Externs, | |||
old_find_testable_code(&input_str, &mut collector, DUMMY_SP); | |||
find_testable_code(&input_str, &mut collector, DUMMY_SP); | |||
test_args.insert(0, "rustdoctest".to_string()); | |||
if display_warnings { | |||
test_args.insert(1, "--display-stdout".to_string()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come this was added? I thought rustc output went to stderr?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of the tag is up to debate. I'm using it to make the difference between warnings and errors, but it's clearly misleading. What name should we give it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I may not even understand what this is doing. What is it doing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So for now, when running rustdoc --test
, warnings aren't displayed. Some people want them to be displayed anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then why not call it --display-warnings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GuillaumeGomez that's not too helpful of a description, though? You're basically just restating the title and description of this PR.
This flag is implemented inside of libtest which means that it has nothing to do with doctest warnings, and is an instantly stable interface to all test binaries that we generate, hence my hesitation. If we can avoid it that would be great, but I do not understand what this flag is doing inside of the test harness.
Can you explain what's going on inside of libtest to why this is being passed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aaaaah. My bad. So basically, in libtest, if I have the display-stdout
option enabled, for every non-failing test, I display what the test sent to the output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be done without exposing a new flag from libtest? Just by modifying internal data structures or using a custom api from libtest?
@@ -172,6 +172,7 @@ pub fn opts() -> Vec<RustcOptGroup> { | |||
or `#![doc(html_playground_url=...)]`", | |||
"URL")), | |||
unstable(optflag("", "enable-commonmark", "to enable commonmark doc rendering/testing")), | |||
unstable(optflag("", "display-warnings", "to print code warnings when testing doc")), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you open a tracking issue for this as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean besides the one already opened? (in the PR description)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that can suffice, but then this PR should not close that issue.
Updated. |
Looks like a good strategy to me, but CI seems to be failing? |
bb91763
to
d5863e9
Compare
Yep, forgot to update some pieces of code. |
@bors: r+ |
📌 Commit d5863e9 has been approved by |
…s, r=alexcrichton Add option to display warnings in rustdoc Part of rust-lang#41574. r? @alexcrichton The output for this file: ```rust /// ``` /// fn foo(x: u32) {} /// /// foo(2); /// let x = 1; /// panic!(); /// ``` fn foo() {} /// ``` /// fn foo(x: u32) {} /// /// foo(2); /// let x = 1; /// ``` fn foo2() {} /// ``` /// fn foo(x: u32) {} /// /// foo(2); /// let x = 1; /// panic!(); /// ``` fn foo3() {} fn main() { } ``` is the following: ``` > ./build/x86_64-apple-darwin/stage1/bin/rustdoc -Z unstable-options --display-warnings --test test.rs running 3 tests test test.rs - foo (line 1) ... FAILED test test.rs - foo3 (line 18) ... FAILED test test.rs - foo2 (line 10) ... ok successes: ---- test.rs - foo2 (line 10) stdout ---- warning: unused variable: `x` --> <anon>:2:8 | 2 | fn foo(x: u32) {} | ^ | = note: #[warn(unused_variables)] on by default warning: unused variable: `x` --> <anon>:5:5 | 5 | let x = 1; | ^ | = note: #[warn(unused_variables)] on by default successes: test.rs - foo2 (line 10) failures: ---- test.rs - foo (line 1) stdout ---- warning: unused variable: `x` --> <anon>:2:8 | 2 | fn foo(x: u32) {} | ^ | = note: #[warn(unused_variables)] on by default warning: unused variable: `x` --> <anon>:5:5 | 5 | let x = 1; | ^ | = note: #[warn(unused_variables)] on by default thread 'rustc' panicked at 'test executable failed: thread 'main' panicked at 'explicit panic', <anon>:6 note: Run with `RUST_BACKTRACE=1` for a backtrace. ', src/librustdoc/test.rs:317 note: Run with `RUST_BACKTRACE=1` for a backtrace. ---- test.rs - foo3 (line 18) stdout ---- warning: unused variable: `x` --> <anon>:2:8 | 2 | fn foo(x: u32) {} | ^ | = note: #[warn(unused_variables)] on by default warning: unused variable: `x` --> <anon>:5:5 | 5 | let x = 1; | ^ | = note: #[warn(unused_variables)] on by default thread 'rustc' panicked at 'test executable failed: thread 'main' panicked at 'explicit panic', <anon>:6 note: Run with `RUST_BACKTRACE=1` for a backtrace. ', src/librustdoc/test.rs:317 failures: test.rs - foo (line 1) test.rs - foo3 (line 18) test result: FAILED. 1 passed; 2 failed; 0 ignored; 0 measured ```
Part of #41574.
r? @alexcrichton
The output for this file:
is the following: