- Notifications
You must be signed in to change notification settings - Fork 13.9k
Description
guess_head_span ends up calling ensure_source_file_source_present, which calls add_external_src. If the source file of the span is an imported file, then whether or not this method succeeds depends on the current file on disk:
rust/compiler/rustc_span/src/lib.rs
Lines 1447 to 1451 in 0f6ba39
| if self.src_hash.matches(&src) { | |
| normalize_src(&mut src, BytePos::from_usize(0)); | |
| *src_kind = ExternalSourceKind::Present(Lrc::new(src)); | |
| return true; | |
| } |
However, the hash of the external crate depends on the hash of the file at the time the external crate was compiled, not the time the current crate is compiled. If the external crate is a Cargo dependency (in ~/.cargo/registry), then changing a file in the dependency will not cause it to be re-built, allowing a new compilation session to read in a different file than the one used to originally compile the external crate.
Since guess_head_span falls back to the passed-in span if reading the source file fails, the span that we end up using depends on global untracked state (the current contents of an external crate's file on disk).