]> git.lizzy.rs Git - rust.git/commitdiff
rustdoc: add #[allow(unused)] to every doctest
authorQuietMisdreavus <grey@quietmisdreavus.net>
Sat, 4 Nov 2017 19:13:44 +0000 (14:13 -0500)
committerQuietMisdreavus <grey@quietmisdreavus.net>
Sun, 5 Nov 2017 15:30:00 +0000 (09:30 -0600)
also modify the order crate attributes are applied, to have a better
order of how things can override lints, either per-crate or per-test

src/librustdoc/test.rs

index 9316805b9322abf6ea84759058393cd7c25dbfc4..9bbd16355be387a6afa8b3db40ab4213861ef369 100644 (file)
@@ -337,15 +337,23 @@ pub fn make_test(s: &str,
 
     let mut prog = String::new();
 
-    // First push any outer attributes from the example, assuming they
-    // are intended to be crate attributes.
-    prog.push_str(&crate_attrs);
+    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
+        // that case may cause some tests to pass when they shouldn't have.
+        prog.push_str("#![allow(unused)]\n");
+    }
 
-    // Next, any attributes for other aspects such as lints.
+    // Next, any attributes that came from the crate root via #![doc(test(attr(...)))].
     for attr in &opts.attrs {
         prog.push_str(&format!("#![{}]\n", attr));
     }
 
+    // Now push any outer attributes from the example, assuming they
+    // are intended to be crate attributes.
+    prog.push_str(&crate_attrs);
+
     // Don't inject `extern crate std` because it's already injected by the
     // compiler.
     if !s.contains("extern crate") && !opts.no_crate_inject && cratename != Some("std") {