about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-04-06 17:38:41 +0000
committerbors <bors@rust-lang.org>2018-04-06 17:38:41 +0000
commiteeea94c11d02ff62fb011d1afdda9301fdf9726b (patch)
treeb5d4db96d45d602e79fea56dc9a35d706e1286eb /src
parent7678d5021e5c984af52f4d1e9147f7a2d6a7ddc3 (diff)
parent8145a77a28bc6189583493aeafeec188a8f47963 (diff)
downloadrust-eeea94c11d02ff62fb011d1afdda9301fdf9726b.tar.gz
rust-eeea94c11d02ff62fb011d1afdda9301fdf9726b.zip
Auto merge of #49064 - QuietMisdreavus:piercing-the-veil, r=GuillaumeGomez
rustdoctest: suppress the default allow(unused) under --display-warnings

If you're passing rustdoc `--display-warnings`, you probably want to see the default ones too. This change modifies `test::make_test` to suppress the default `#![allow(unused)]` if the `--display-warnings` CLI flag was provided to rustdoc.

cc https://github.com/rust-lang/rust/issues/41574
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/markdown.rs1
-rw-r--r--src/librustdoc/test.rs27
2 files changed, 26 insertions, 2 deletions
diff --git a/src/librustdoc/markdown.rs b/src/librustdoc/markdown.rs
index daa8966b104..f14d4c602d0 100644
--- a/src/librustdoc/markdown.rs
+++ b/src/librustdoc/markdown.rs
@@ -149,6 +149,7 @@ pub fn test(input: &str, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
 
     let mut opts = TestOptions::default();
     opts.no_crate_inject = true;
+    opts.display_warnings = display_warnings;
     let mut collector = Collector::new(input.to_owned(), cfgs, libs, externs,
                                        true, opts, maybe_sysroot, None,
                                        Some(PathBuf::from(input)),
diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs
index ab11b0d62e9..cb532276c66 100644
--- a/src/librustdoc/test.rs
+++ b/src/librustdoc/test.rs
@@ -46,7 +46,12 @@ use html::markdown;
 
 #[derive(Clone, Default)]
 pub struct TestOptions {
+    /// Whether to disable the default `extern crate my_crate;` when creating doctests.
     pub no_crate_inject: bool,
+    /// Whether to emit compilation warnings when compiling doctests. Setting this will suppress
+    /// the default `#![allow(unused)]`.
+    pub display_warnings: bool,
+    /// Additional crate-level attributes to add to doctests.
     pub attrs: Vec<String>,
 }
 
@@ -113,7 +118,8 @@ pub fn run(input_path: &Path,
     let crate_name = crate_name.unwrap_or_else(|| {
         ::rustc_trans_utils::link::find_crate_name(None, &hir_forest.krate().attrs, &input)
     });
-    let opts = scrape_test_config(hir_forest.krate());
+    let mut opts = scrape_test_config(hir_forest.krate());
+    opts.display_warnings |= display_warnings;
     let mut collector = Collector::new(crate_name,
                                        cfgs,
                                        libs,
@@ -153,6 +159,7 @@ fn scrape_test_config(krate: &::rustc::hir::Crate) -> TestOptions {
 
     let mut opts = TestOptions {
         no_crate_inject: false,
+        display_warnings: false,
         attrs: Vec::new(),
     };
 
@@ -357,7 +364,7 @@ pub fn make_test(s: &str,
     let mut line_offset = 0;
     let mut prog = String::new();
 
-    if opts.attrs.is_empty() {
+    if opts.attrs.is_empty() && !opts.display_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
@@ -787,6 +794,7 @@ assert_eq!(2+2, 4);
         //adding it anyway
         let opts = TestOptions {
             no_crate_inject: true,
+            display_warnings: false,
             attrs: vec![],
         };
         let input =
@@ -957,4 +965,19 @@ assert_eq!(2+2, 4);".to_string();
         let output = make_test(input, None, true, &opts);
         assert_eq!(output, (expected.clone(), 1));
     }
+
+    #[test]
+    fn make_test_display_warnings() {
+        //if the user is asking to display doctest warnings, suppress the default allow(unused)
+        let mut opts = TestOptions::default();
+        opts.display_warnings = true;
+        let input =
+"assert_eq!(2+2, 4);";
+        let expected =
+"fn main() {
+assert_eq!(2+2, 4);
+}".to_string();
+        let output = make_test(input, None, false, &opts);
+        assert_eq!(output, (expected.clone(), 1));
+    }
 }