Repository: rust
Issue: rustdoc --test mis-reports origins of #[deny(warnings)]
Labels: T-rustdoc,A-lints,A-diagnostics,C-bug,A-doctests

Here's an example I stumbled onto with a copy of `rand 0.5.6`:

```
 RUSTFLAGS="--cap-lints warn" cargo test --doc  --verbose
... 
 test src/prng/chacha.rs - prng::chacha::ChaChaRng::new_unseeded (line 115) ... ok
test src/prelude.rs - prelude (line 17) ... ok
test src/rngs/jitter.rs - rngs::jitter::JitterRng (line 72) ... FAILED
test src/lib.rs - sample (line 1020) ... ok
test src/rngs/adapter/read.rs - rngs::adapter::read::ReadRng (line 35) ... ok
test src/rngs/jitter.rs - rngs::jitter::JitterRng::new_with_timer (line 318) ... ok
...
failures:

---- src/rngs/jitter.rs - rngs::jitter::JitterRng (line 72) stdout ----
error: trait objects without an explicit `dyn` are deprecated
  --> src/rngs/jitter.rs:79:33
   |
10 | fn try_main() -> Result<(), Box<Error>> {
   |                                 ^^^^^ help: use `dyn`: `dyn Error`
   |
note: lint level defined here
  --> src/rngs/jitter.rs:71:9
   |
2  | #![deny(warnings)]
   |         ^^^^^^^^
   = note: `#[deny(bare_trait_objects)]` implied by `#[deny(warnings)]`

error: aborting due to previous error

Couldn't compile the test.

failures:
    src/rngs/jitter.rs - rngs::jitter::JitterRng (line 72)

```

Note there is a lot wrong here:

1. The line numbers on the "source listing" don't correspond at all to the context line given ( 2 vs 71 )
2. The lines cited don't at all correspond with any of the files mentioned.

```
cat -n src/rngs/jitter.rs | grep -C3 "^\s*71\s"
    68	/// https://github.com/usnistgov/SP800-90B_EntropyAssessment).
    69	///
    70	/// Use the following code using [`timer_stats`] to collect the data:
    71	///
    72	/// ```no_run
    73	/// use rand::jitter::JitterRng;
    74	/// #
```
```
 cat -n src/rngs/jitter.rs | grep -C3 "^\s*2\s"
     1	// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
     2	// file at the top-level directory of this distribution and at
     3	// https://rust-lang.org/COPYRIGHT.
     4	//
     5	// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
```

No, instead, this rule is inserted somewhere else entirely:

```
 grep -C3 "deny" -nr src/
src/lib.rs-226-       html_favicon_url = "https://www.rust-lang.org/favicon.ico",
src/lib.rs-227-       html_root_url = "https://docs.rs/rand/0.5.6")]
src/lib.rs-228-
src/lib.rs:229:#![deny(missing_docs)]
src/lib.rs:230:#![deny(missing_debug_implementations)]
src/lib.rs:231:#![doc(test(attr(allow(unused_variables), deny(warnings))))]
src/lib.rs-232-
src/lib.rs-233-#![cfg_attr(not(feature="std"), no_std)]
src/lib.rs-234-#![cfg_attr(all(feature="alloc", not(feature="std")), feature(alloc))]
```

Obviously macros are to blame here, but as it stands, this makes this reported error source entirely useless, not only is it getting the line _and_ the file wrong, it cites a literal string that doesn't even exist as-stated in the source code, presenting it under the guise of being literal source code.

I'm probably gonna also have to file another bug about that whole "`--cap-lints warn` does absolutely nothing" deal it has going on there.