Repository: rust
Issue: Regression: source code location is bad in nightly (doctests)
Labels: T-rustdoc,C-bug,A-doctests,E-needs-mcve,I-prioritize,regression-untriaged

### Code

I tried this code in xso/src/from_xml_doc.md :


#### Example without codec

```rust
# // extern crate alloc;
# use xso::FromXml;
#[derive(FromXml, Debug, PartialEq)]
#[xml(namespace = "urn:example", name = "foo")]
struct Foo {
    #[xml(text)]
    a: String,
};

let foo: Foo = xso::from_bytes(b"<foo xmlns='urn:example'>hello</foo>").unwrap();
assert_eq!(foo, Foo {
    a: "hello".to_string(),
});
```

(i commented extern crate alloc but in start it was just not there)

I expected to see this happen: reporting error produced in xso/src/from_xml_doc.md line ~600

Instead, this happened: reported error produced in xso/src/lib.rs line ~600 (does not exist)

```
failures:

---- xso/src/lib.rs - FromXml (line 648) stdout ----
error[E0433]: failed to resolve: could not find `alloc` in the list of imported crates
 --> xso/src/lib.rs:652:10
  |
7 | #[derive(FromXml, Debug, PartialEq)]
  |          ^^^^^^^ could not find `alloc` in the list of imported crates
  |
  = note: this error originates in the derive macro `FromXml` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this module
  |
3 + use std::string;
  |

error[E0433]: failed to resolve: could not find `alloc` in the list of imported crates
 --> xso/src/lib.rs:652:10
  |
7 | #[derive(FromXml, Debug, PartialEq)]
  |          ^^^^^^^ could not find `alloc` in the list of imported crates
  |
  = note: this error originates in the derive macro `FromXml` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this struct
  |
3 + use std::string::String;
  |

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0433`.
Couldn't compile the test.

failures:
    xso/src/lib.rs - FromXml (line 648)

test result: FAILED. 9 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.39s

error: doctest failed, to rerun pass `--doc`
```

### Version it worked on

Works on stable:

```
---- xso/src/from_xml_doc.md - FromXml (line 590) stdout ----
error[E0433]: failed to resolve: could not find `alloc` in the list of imported crates
 --> xso/src/from_xml_doc.md:594:10
  |
7 | #[derive(FromXml, Debug, PartialEq)]
  |          ^^^^^^^ could not find `alloc` in the list of imported crates
  |
  = note: this error originates in the derive macro `FromXml` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this module
  |
3 + use std::string;
  |

error[E0433]: failed to resolve: could not find `alloc` in the list of imported crates
 --> xso/src/from_xml_doc.md:594:10
  |
7 | #[derive(FromXml, Debug, PartialEq)]
  |          ^^^^^^^ could not find `alloc` in the list of imported crates
  |
  = note: this error originates in the derive macro `FromXml` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this struct
  |
3 + use std::string::String;
  |

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0433`.
Couldn't compile the test.

failures:
    xso/src/from_xml_doc.md - FromXml (line 590)

test result: FAILED. 9 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.04s

error: doctest failed, to rerun pass `--doc`
```

### Version with regression

`rustc --version --verbose`:
```
rustc 1.85.0-nightly (4ba4ac612 2024-12-18)
binary: rustc
commit-hash: 4ba4ac612d36e3409e8e1e31e12acc028808f85f
commit-date: 2024-12-18
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.6
```

<!--
@rustbot modify labels: +regression-from-stable-to-{channel} -regression-untriaged
-->