rustdoc: add #[allow(unused)] to every doctest

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
This commit is contained in:
QuietMisdreavus 2017-11-04 14:13:44 -05:00
parent dcd343bfbc
commit 5abc524073

View 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") {