X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustdoc%2Fdoctest.rs;h=56ccdfae1d8bc1bb2b62ff4254decc8aca379051;hb=1e55c31cbbc43a21c93ed5652dc39c267e6557af;hp=de4a3732e736bbcc68b89fadb052d71d375a56f4;hpb=23a436606b118bd2fbb12f64fce21e7f9d355349;p=rust.git diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index de4a3732e73..56ccdfae1d8 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -38,9 +38,6 @@ crate struct TestOptions { /// Whether to disable the default `extern crate my_crate;` when creating doctests. crate no_crate_inject: bool, - /// Whether to emit compilation warnings when compiling doctests. Setting this will suppress - /// the default `#![allow(unused)]`. - crate display_doctest_warnings: bool, /// Additional crate-level attributes to add to doctests. crate attrs: Vec, } @@ -65,6 +62,8 @@ } }); + debug!(?lint_opts); + let crate_types = if options.proc_macro_crate { vec![CrateType::ProcMacro] } else { vec![CrateType::Rlib] }; @@ -72,7 +71,7 @@ maybe_sysroot: options.maybe_sysroot.clone(), search_paths: options.libs.clone(), crate_types, - lint_opts: if !options.display_doctest_warnings { lint_opts } else { vec![] }, + lint_opts, lint_cap: Some(options.lint_cap.unwrap_or(lint::Forbid)), cg: options.codegen_options.clone(), externs: options.externs.clone(), @@ -106,7 +105,6 @@ }; let test_args = options.test_args.clone(); - 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; @@ -118,8 +116,7 @@ let collector = global_ctxt.enter(|tcx| { let crate_attrs = tcx.hir().attrs(CRATE_HIR_ID); - let mut opts = scrape_test_config(crate_attrs); - opts.display_doctest_warnings |= options.display_doctest_warnings; + let opts = scrape_test_config(crate_attrs); let enable_per_target_ignores = options.enable_per_target_ignores; let mut collector = Collector::new( tcx.crate_name(LOCAL_CRATE), @@ -165,7 +162,7 @@ Err(ErrorReported) => return Err(ErrorReported), }; - run_tests(test_args, nocapture, display_doctest_warnings, tests); + run_tests(test_args, nocapture, tests); // Collect and warn about unused externs, but only if we've gotten // reports for each doctest @@ -208,29 +205,19 @@ Ok(()) } -crate fn run_tests( - mut test_args: Vec, - nocapture: bool, - display_doctest_warnings: bool, - tests: Vec, -) { +crate fn run_tests(mut test_args: Vec, nocapture: 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_doctest_warnings)), - ); + test::test_main(&test_args, tests, None); } // Look for `#![doc(test(no_crate_inject))]`, used by crates in the std facade. fn scrape_test_config(attrs: &[ast::Attribute]) -> TestOptions { use rustc_ast_pretty::pprust; - let mut opts = - TestOptions { no_crate_inject: false, display_doctest_warnings: false, attrs: Vec::new() }; + let mut opts = TestOptions { no_crate_inject: false, attrs: Vec::new() }; let test_attrs: Vec<_> = attrs .iter() @@ -510,7 +497,7 @@ fn drop(&mut self) { let mut prog = String::new(); let mut supports_color = false; - if opts.attrs.is_empty() && !opts.display_doctest_warnings { + if opts.attrs.is_empty() { // 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