Skip to content

Commit c3c0f80

Browse files
committed
Auto merge of #73314 - GuillaumeGomez:display-warnings, r=jyn514
Rename "--display-warnings" to "--display-doctest-warnings" Fixes #41574. cc `@ollie27` r? `@kinnison`
2 parents ec9a1bd + b531a7f commit c3c0f80

File tree

9 files changed

+66
-25
lines changed

9 files changed

+66
-25
lines changed

src/doc/rustdoc/src/unstable-features.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,13 @@ all these files are linked from every page, changing where they are can be cumbe
222222
specially cache them. This flag will rename all these files in the output to include the suffix in
223223
the filename. For example, `light.css` would become `light-suf.css` with the above command.
224224

225-
### `--display-warnings`: display warnings when documenting or running documentation tests
225+
### `--display-doctest-warnings`: display warnings when documenting or running documentation tests
226226

227227
Using this flag looks like this:
228228

229229
```bash
230-
$ rustdoc src/lib.rs -Z unstable-options --display-warnings
231-
$ rustdoc --test src/lib.rs -Z unstable-options --display-warnings
230+
$ rustdoc src/lib.rs -Z unstable-options --display-doctest-warnings
231+
$ rustdoc --test src/lib.rs -Z unstable-options --display-doctest-warnings
232232
```
233233

234234
The intent behind this flag is to allow the user to see warnings that occur within their library or

src/librustdoc/config.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ crate struct Options {
137137
crate manual_passes: Vec<String>,
138138
/// Whether to display warnings during doc generation or while gathering doctests. By default,
139139
/// all non-rustdoc-specific lints are allowed when generating docs.
140-
crate display_warnings: bool,
140+
crate display_doctest_warnings: bool,
141141
/// Whether to run the `calculate-doc-coverage` pass, which counts the number of public items
142142
/// with and without documentation.
143143
crate show_coverage: bool,
@@ -192,7 +192,7 @@ impl fmt::Debug for Options {
192192
.field("persist_doctests", &self.persist_doctests)
193193
.field("default_passes", &self.default_passes)
194194
.field("manual_passes", &self.manual_passes)
195-
.field("display_warnings", &self.display_warnings)
195+
.field("display_doctest_warnings", &self.display_doctest_warnings)
196196
.field("show_coverage", &self.show_coverage)
197197
.field("crate_version", &self.crate_version)
198198
.field("render_options", &self.render_options)
@@ -632,7 +632,7 @@ impl Options {
632632
let proc_macro_crate = crate_types.contains(&CrateType::ProcMacro);
633633
let playground_url = matches.opt_str("playground-url");
634634
let maybe_sysroot = matches.opt_str("sysroot").map(PathBuf::from);
635-
let display_warnings = matches.opt_present("display-warnings");
635+
let display_doctest_warnings = matches.opt_present("display-doctest-warnings");
636636
let sort_modules_alphabetically = !matches.opt_present("sort-modules-by-appearance");
637637
let resource_suffix = matches.opt_str("resource-suffix").unwrap_or_default();
638638
let enable_minification = !matches.opt_present("disable-minification");
@@ -696,7 +696,7 @@ impl Options {
696696
test_args,
697697
default_passes,
698698
manual_passes,
699-
display_warnings,
699+
display_doctest_warnings,
700700
show_coverage,
701701
crate_version,
702702
test_run_directory,

src/librustdoc/core.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ crate fn create_config(
204204
lint_opts,
205205
describe_lints,
206206
lint_cap,
207-
display_warnings,
208207
..
209208
}: RustdocOptions,
210209
) -> rustc_interface::Config {
@@ -237,7 +236,7 @@ crate fn create_config(
237236
maybe_sysroot,
238237
search_paths: libs,
239238
crate_types,
240-
lint_opts: if !display_warnings { lint_opts } else { vec![] },
239+
lint_opts,
241240
lint_cap,
242241
cg: codegen_options,
243242
externs,

src/librustdoc/doctest.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ crate struct TestOptions {
4040
crate no_crate_inject: bool,
4141
/// Whether to emit compilation warnings when compiling doctests. Setting this will suppress
4242
/// the default `#![allow(unused)]`.
43-
crate display_warnings: bool,
43+
crate display_doctest_warnings: bool,
4444
/// Additional crate-level attributes to add to doctests.
4545
crate attrs: Vec<String>,
4646
}
@@ -72,7 +72,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
7272
maybe_sysroot: options.maybe_sysroot.clone(),
7373
search_paths: options.libs.clone(),
7474
crate_types,
75-
lint_opts: if !options.display_warnings { lint_opts } else { vec![] },
75+
lint_opts: if !options.display_doctest_warnings { lint_opts } else { vec![] },
7676
lint_cap: Some(options.lint_cap.unwrap_or_else(|| lint::Forbid)),
7777
cg: options.codegen_options.clone(),
7878
externs: options.externs.clone(),
@@ -106,7 +106,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
106106
};
107107

108108
let test_args = options.test_args.clone();
109-
let display_warnings = options.display_warnings;
109+
let display_doctest_warnings = options.display_doctest_warnings;
110110
let nocapture = options.nocapture;
111111
let externs = options.externs.clone();
112112
let json_unused_externs = options.json_unused_externs;
@@ -119,7 +119,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
119119
let crate_attrs = tcx.hir().attrs(CRATE_HIR_ID);
120120

121121
let mut opts = scrape_test_config(crate_attrs);
122-
opts.display_warnings |= options.display_warnings;
122+
opts.display_doctest_warnings |= options.display_doctest_warnings;
123123
let enable_per_target_ignores = options.enable_per_target_ignores;
124124
let mut collector = Collector::new(
125125
tcx.crate_name(LOCAL_CRATE),
@@ -163,7 +163,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
163163
Err(ErrorReported) => return Err(ErrorReported),
164164
};
165165

166-
run_tests(test_args, nocapture, display_warnings, tests);
166+
run_tests(test_args, nocapture, display_doctest_warnings, tests);
167167

168168
// Collect and warn about unused externs, but only if we've gotten
169169
// reports for each doctest
@@ -209,22 +209,26 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
209209
crate fn run_tests(
210210
mut test_args: Vec<String>,
211211
nocapture: bool,
212-
display_warnings: bool,
212+
display_doctest_warnings: bool,
213213
tests: Vec<test::TestDescAndFn>,
214214
) {
215215
test_args.insert(0, "rustdoctest".to_string());
216216
if nocapture {
217217
test_args.push("--nocapture".to_string());
218218
}
219-
test::test_main(&test_args, tests, Some(test::Options::new().display_output(display_warnings)));
219+
test::test_main(
220+
&test_args,
221+
tests,
222+
Some(test::Options::new().display_output(display_doctest_warnings)),
223+
);
220224
}
221225

222226
// Look for `#![doc(test(no_crate_inject))]`, used by crates in the std facade.
223227
fn scrape_test_config(attrs: &[ast::Attribute]) -> TestOptions {
224228
use rustc_ast_pretty::pprust;
225229

226230
let mut opts =
227-
TestOptions { no_crate_inject: false, display_warnings: false, attrs: Vec::new() };
231+
TestOptions { no_crate_inject: false, display_doctest_warnings: false, attrs: Vec::new() };
228232

229233
let test_attrs: Vec<_> = attrs
230234
.iter()
@@ -504,7 +508,7 @@ crate fn make_test(
504508
let mut prog = String::new();
505509
let mut supports_color = false;
506510

507-
if opts.attrs.is_empty() && !opts.display_warnings {
511+
if opts.attrs.is_empty() && !opts.display_doctest_warnings {
508512
// If there aren't any attributes supplied by #![doc(test(attr(...)))], then allow some
509513
// lints that are commonly triggered in doctests. The crate-level test attributes are
510514
// commonly used to make tests fail in case they trigger warnings, so having this there in

src/librustdoc/doctest/tests.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ assert_eq!(2+2, 4);
5252
fn make_test_no_crate_inject() {
5353
// Even if you do use the crate within the test, setting `opts.no_crate_inject` will skip
5454
// adding it anyway.
55-
let opts = TestOptions { no_crate_inject: true, display_warnings: false, attrs: vec![] };
55+
let opts =
56+
TestOptions { no_crate_inject: true, display_doctest_warnings: false, attrs: vec![] };
5657
let input = "use asdf::qwop;
5758
assert_eq!(2+2, 4);";
5859
let expected = "#![allow(unused)]
@@ -215,10 +216,10 @@ assert_eq!(2+2, 4);"
215216
}
216217

217218
#[test]
218-
fn make_test_display_warnings() {
219+
fn make_test_display_doctest_warnings() {
219220
// If the user is asking to display doctest warnings, suppress the default `allow(unused)`.
220221
let mut opts = TestOptions::default();
221-
opts.display_warnings = true;
222+
opts.display_doctest_warnings = true;
222223
let input = "assert_eq!(2+2, 4);";
223224
let expected = "fn main() {
224225
assert_eq!(2+2, 4);

src/librustdoc/lib.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,12 @@ fn opts() -> Vec<RustcOptGroup> {
419419
"URL",
420420
)
421421
}),
422-
unstable("display-warnings", |o| {
423-
o.optflagmulti("", "display-warnings", "to print code warnings when testing doc")
422+
unstable("display-doctest-warnings", |o| {
423+
o.optflagmulti(
424+
"",
425+
"display-doctest-warnings",
426+
"show warnings that originate in doctests",
427+
)
424428
}),
425429
stable("crate-version", |o| {
426430
o.optopt("", "crate-version", "crate version to print into documentation", "VERSION")

src/librustdoc/markdown.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ crate fn test(options: Options) -> Result<(), String> {
120120
.map_err(|err| format!("{}: {}", options.input.display(), err))?;
121121
let mut opts = TestOptions::default();
122122
opts.no_crate_inject = true;
123-
opts.display_warnings = options.display_warnings;
123+
opts.display_doctest_warnings = options.display_doctest_warnings;
124124
let mut collector = Collector::new(
125125
Symbol::intern(&options.input.display().to_string()),
126126
options.clone(),
@@ -138,7 +138,7 @@ crate fn test(options: Options) -> Result<(), String> {
138138
crate::doctest::run_tests(
139139
options.test_args,
140140
options.nocapture,
141-
options.display_warnings,
141+
options.display_doctest_warnings,
142142
collector.tests,
143143
);
144144
Ok(())

src/test/rustdoc-ui/display-output.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// check-pass
2+
// compile-flags:-Zunstable-options --display-doctest-warnings --test
3+
// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR"
4+
// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
5+
6+
/// ```
7+
/// let x = 12;
8+
/// ```
9+
pub fn foo() {}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
running 1 test
3+
test $DIR/display-output.rs - foo (line 6) ... ok
4+
5+
successes:
6+
7+
---- $DIR/display-output.rs - foo (line 6) stdout ----
8+
warning: unused variable: `x`
9+
--> $DIR/display-output.rs:7:5
10+
|
11+
LL | let x = 12;
12+
| ^ help: if this is intentional, prefix it with an underscore: `_x`
13+
|
14+
= note: `#[warn(unused_variables)]` on by default
15+
16+
warning: 1 warning emitted
17+
18+
19+
20+
successes:
21+
$DIR/display-output.rs - foo (line 6)
22+
23+
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
24+

0 commit comments

Comments
 (0)