Repository: rust
Issue: Wrong file reported in "within type" compiler errors
Labels: A-diagnostics,P-low,T-compiler,D-papercut

### Code

```rust
use std::path::Path;
fn main() {
    let _buf: Path = "a/b/c/d/".as_ref();
}
```

I expected to see this happen: Mention either no file at all, or provide the correct path to the actually-used file, e.g. `/home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/path.rs`, or wherever the file actually lives. (My guess is wrong, I can't figure out the actual location.)

Instead, this happened:
- 1.70.0 does not provide a reference to `path.rs` at all.
- 1.72.0, 1.76.0, and nightly reference a non-existent file `/rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/path.rs:1992:12` that I cannot open.

```console
$ cargo +1.70.0 --version
cargo 1.70.0 (ec8a8a0ca 2023-04-25)
$ cargo +1.72.0 --version
cargo 1.72.0 (103a7ff2e 2023-08-15)
$ cargo +1.70.0 run
   Compiling pathtest v0.1.0 (/tmp/pathtest)
error[E0308]: mismatched types
 --> src/main.rs:3:22
  |
3 |     let _buf: Path = "a/b/c/d/".as_ref();
  |               ----   ^^^^^^^^^^^^^^^^^^^ expected `Path`, found `&_`
  |               |
  |               expected due to this
  |
  = note: expected struct `Path`
          found reference `&_`

error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
 --> src/main.rs:3:9
  |
3 |     let _buf: Path = "a/b/c/d/".as_ref();
  |         ^^^^ doesn't have a size known at compile-time
  |
  = help: within `Path`, the trait `Sized` is not implemented for `[u8]`
  = note: required because it appears within the type `Path`
  = note: all local variables must have a statically known size
  = help: unsized locals are gated as an unstable feature
help: consider borrowing here
  |
3 |     let _buf: &Path = "a/b/c/d/".as_ref();
  |               +

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `pathtest` (bin "pathtest") due to 2 previous errors
[$? = 101]
$ cargo +1.72.0 run
   Compiling pathtest v0.1.0 (/tmp/pathtest)
error[E0308]: mismatched types
 --> src/main.rs:3:22
  |
3 |     let _buf: Path = "a/b/c/d/".as_ref();
  |               ----   ^^^^^^^^^^^^^^^^^^^ expected `Path`, found `&_`
  |               |
  |               expected due to this
  |
  = note: expected struct `Path`
          found reference `&_`

error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
 --> src/main.rs:3:9
  |
3 |     let _buf: Path = "a/b/c/d/".as_ref();
  |         ^^^^ doesn't have a size known at compile-time
  |
  = help: within `Path`, the trait `Sized` is not implemented for `[u8]`
note: required because it appears within the type `Path`
 --> /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/path.rs:1992:12
  = note: all local variables must have a statically known size
  = help: unsized locals are gated as an unstable feature
help: consider borrowing here
  |
3 |     let _buf: &Path = "a/b/c/d/".as_ref();
  |               +

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `pathtest` (bin "pathtest") due to 2 previous errors
[$? = 101]
```

### Version it worked on

It definitely "worked" on Rust 1.70.0. (Quotation marks because it "worked" by not indicating any file at all.)

### Versions with regression

At least 1.72.0 and current stable (1.76.0) are affected.

```console
$ rustc +1.72.0 --version --verbose
rustc 1.72.0 (5680fa18f 2023-08-23)
binary: rustc
commit-hash: 5680fa18feaa87f3ff04063800aec256c3d4b4be
commit-date: 2023-08-23
host: x86_64-unknown-linux-gnu
release: 1.72.0
LLVM version: 16.0.5
$ rustc --version --verbose
rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-unknown-linux-gnu
release: 1.76.0
LLVM version: 17.0.6
```

@rustbot modify labels: +regression-from-1.70-to-1.72 -regression-untriaged