diff --git a/src/doc/rustdoc/src/unstable-features.md b/src/doc/rustdoc/src/unstable-features.md index dce98abcf53d7..b55db452f124c 100644 --- a/src/doc/rustdoc/src/unstable-features.md +++ b/src/doc/rustdoc/src/unstable-features.md @@ -222,13 +222,13 @@ all these files are linked from every page, changing where they are can be cumbe specially cache them. This flag will rename all these files in the output to include the suffix in the filename. For example, `light.css` would become `light-suf.css` with the above command. -### `--display-warnings`: display warnings when documenting or running documentation tests +### `--display-doctest-warnings`: display warnings when documenting or running documentation tests Using this flag looks like this: ```bash -$ rustdoc src/lib.rs -Z unstable-options --display-warnings -$ rustdoc --test src/lib.rs -Z unstable-options --display-warnings +$ rustdoc src/lib.rs -Z unstable-options --display-doctest-warnings +$ rustdoc --test src/lib.rs -Z unstable-options --display-doctest-warnings ``` The intent behind this flag is to allow the user to see warnings that occur within their library or diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 97930f106994a..ac440a395155c 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -137,7 +137,7 @@ crate struct Options { crate manual_passes: Vec, /// Whether to display warnings during doc generation or while gathering doctests. By default, /// all non-rustdoc-specific lints are allowed when generating docs. - crate display_warnings: bool, + crate display_doctest_warnings: bool, /// Whether to run the `calculate-doc-coverage` pass, which counts the number of public items /// with and without documentation. crate show_coverage: bool, @@ -192,7 +192,7 @@ impl fmt::Debug for Options { .field("persist_doctests", &self.persist_doctests) .field("default_passes", &self.default_passes) .field("manual_passes", &self.manual_passes) - .field("display_warnings", &self.display_warnings) + .field("display_doctest_warnings", &self.display_doctest_warnings) .field("show_coverage", &self.show_coverage) .field("crate_version", &self.crate_version) .field("render_options", &self.render_options) @@ -632,7 +632,7 @@ impl Options { let proc_macro_crate = crate_types.contains(&CrateType::ProcMacro); let playground_url = matches.opt_str("playground-url"); let maybe_sysroot = matches.opt_str("sysroot").map(PathBuf::from); - let display_warnings = matches.opt_present("display-warnings"); + let display_doctest_warnings = matches.opt_present("display-doctest-warnings"); let sort_modules_alphabetically = !matches.opt_present("sort-modules-by-appearance"); let resource_suffix = matches.opt_str("resource-suffix").unwrap_or_default(); let enable_minification = !matches.opt_present("disable-minification"); @@ -696,7 +696,7 @@ impl Options { test_args, default_passes, manual_passes, - display_warnings, + display_doctest_warnings, show_coverage, crate_version, test_run_directory, diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index bd1d970fc199b..d86b3b785d112 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -204,7 +204,6 @@ crate fn create_config( lint_opts, describe_lints, lint_cap, - display_warnings, .. }: RustdocOptions, ) -> rustc_interface::Config { @@ -237,7 +236,7 @@ crate fn create_config( maybe_sysroot, search_paths: libs, crate_types, - lint_opts: if !display_warnings { lint_opts } else { vec![] }, + lint_opts, lint_cap, cg: codegen_options, externs, diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 9222a0338ae6f..dbeea9cddf387 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -40,7 +40,7 @@ crate struct TestOptions { crate no_crate_inject: bool, /// Whether to emit compilation warnings when compiling doctests. Setting this will suppress /// the default `#![allow(unused)]`. - crate display_warnings: bool, + crate display_doctest_warnings: bool, /// Additional crate-level attributes to add to doctests. crate attrs: Vec, } @@ -72,7 +72,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> { maybe_sysroot: options.maybe_sysroot.clone(), search_paths: options.libs.clone(), crate_types, - lint_opts: if !options.display_warnings { lint_opts } else { vec![] }, + lint_opts: if !options.display_doctest_warnings { lint_opts } else { vec![] }, lint_cap: Some(options.lint_cap.unwrap_or_else(|| lint::Forbid)), cg: options.codegen_options.clone(), externs: options.externs.clone(), @@ -106,7 +106,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> { }; let test_args = options.test_args.clone(); - let display_warnings = options.display_warnings; + let display_doctest_warnings = options.display_doctest_warnings; let nocapture = options.nocapture; let externs = options.externs.clone(); let json_unused_externs = options.json_unused_externs; @@ -119,7 +119,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> { let crate_attrs = tcx.hir().attrs(CRATE_HIR_ID); let mut opts = scrape_test_config(crate_attrs); - opts.display_warnings |= options.display_warnings; + opts.display_doctest_warnings |= options.display_doctest_warnings; let enable_per_target_ignores = options.enable_per_target_ignores; let mut collector = Collector::new( tcx.crate_name(LOCAL_CRATE), @@ -163,7 +163,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> { Err(ErrorReported) => return Err(ErrorReported), }; - run_tests(test_args, nocapture, display_warnings, tests); + run_tests(test_args, nocapture, display_doctest_warnings, tests); // Collect and warn about unused externs, but only if we've gotten // reports for each doctest @@ -209,14 +209,18 @@ crate fn run(options: Options) -> Result<(), ErrorReported> { crate fn run_tests( mut test_args: Vec, nocapture: bool, - display_warnings: bool, + display_doctest_warnings: bool, tests: Vec, ) { test_args.insert(0, "rustdoctest".to_string()); if nocapture { test_args.push("--nocapture".to_string()); } - test::test_main(&test_args, tests, Some(test::Options::new().display_output(display_warnings))); + test::test_main( + &test_args, + tests, + Some(test::Options::new().display_output(display_doctest_warnings)), + ); } // Look for `#![doc(test(no_crate_inject))]`, used by crates in the std facade. @@ -224,7 +228,7 @@ fn scrape_test_config(attrs: &[ast::Attribute]) -> TestOptions { use rustc_ast_pretty::pprust; let mut opts = - TestOptions { no_crate_inject: false, display_warnings: false, attrs: Vec::new() }; + TestOptions { no_crate_inject: false, display_doctest_warnings: false, attrs: Vec::new() }; let test_attrs: Vec<_> = attrs .iter() @@ -504,7 +508,7 @@ crate fn make_test( let mut prog = String::new(); let mut supports_color = false; - if opts.attrs.is_empty() && !opts.display_warnings { + if opts.attrs.is_empty() && !opts.display_doctest_warnings { // If there aren't any attributes supplied by #![doc(test(attr(...)))], then allow some // lints that are commonly triggered in doctests. The crate-level test attributes are // commonly used to make tests fail in case they trigger warnings, so having this there in diff --git a/src/librustdoc/doctest/tests.rs b/src/librustdoc/doctest/tests.rs index c49e45c0e25a0..1851708096564 100644 --- a/src/librustdoc/doctest/tests.rs +++ b/src/librustdoc/doctest/tests.rs @@ -52,7 +52,8 @@ assert_eq!(2+2, 4); fn make_test_no_crate_inject() { // Even if you do use the crate within the test, setting `opts.no_crate_inject` will skip // adding it anyway. - let opts = TestOptions { no_crate_inject: true, display_warnings: false, attrs: vec![] }; + let opts = + TestOptions { no_crate_inject: true, display_doctest_warnings: false, attrs: vec![] }; let input = "use asdf::qwop; assert_eq!(2+2, 4);"; let expected = "#![allow(unused)] @@ -215,10 +216,10 @@ assert_eq!(2+2, 4);" } #[test] -fn make_test_display_warnings() { +fn make_test_display_doctest_warnings() { // If the user is asking to display doctest warnings, suppress the default `allow(unused)`. let mut opts = TestOptions::default(); - opts.display_warnings = true; + opts.display_doctest_warnings = true; let input = "assert_eq!(2+2, 4);"; let expected = "fn main() { assert_eq!(2+2, 4); diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 8246834a74688..f170561300cc2 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -419,8 +419,12 @@ fn opts() -> Vec { "URL", ) }), - unstable("display-warnings", |o| { - o.optflagmulti("", "display-warnings", "to print code warnings when testing doc") + unstable("display-doctest-warnings", |o| { + o.optflagmulti( + "", + "display-doctest-warnings", + "show warnings that originate in doctests", + ) }), stable("crate-version", |o| { o.optopt("", "crate-version", "crate version to print into documentation", "VERSION") diff --git a/src/librustdoc/markdown.rs b/src/librustdoc/markdown.rs index 80af2a7aaf5c8..2ae4897dc3496 100644 --- a/src/librustdoc/markdown.rs +++ b/src/librustdoc/markdown.rs @@ -120,7 +120,7 @@ crate fn test(options: Options) -> Result<(), String> { .map_err(|err| format!("{}: {}", options.input.display(), err))?; let mut opts = TestOptions::default(); opts.no_crate_inject = true; - opts.display_warnings = options.display_warnings; + opts.display_doctest_warnings = options.display_doctest_warnings; let mut collector = Collector::new( Symbol::intern(&options.input.display().to_string()), options.clone(), @@ -138,7 +138,7 @@ crate fn test(options: Options) -> Result<(), String> { crate::doctest::run_tests( options.test_args, options.nocapture, - options.display_warnings, + options.display_doctest_warnings, collector.tests, ); Ok(())