From b1542c92ab0dc6743cd42a5256c47169a04379c6 Mon Sep 17 00:00:00 2001 From: yukang Date: Mon, 10 Nov 2025 10:01:18 +0800 Subject: [PATCH] Prefer to use file.stable_id over file.name from source map --- compiler/rustc_errors/src/emitter.rs | 4 ++-- compiler/rustc_expand/src/proc_macro_server.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 81a7ee1ff45fe..31a89ddd9d16f 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -1704,7 +1704,7 @@ impl HumanEmitter { } // print out the span location and spacer before we print the annotated source // to do this, we need to know if this span will be primary - let is_primary = primary_lo.file.name == annotated_file.file.name; + let is_primary = primary_lo.file.stable_id == annotated_file.file.stable_id; if is_primary { let loc = primary_lo.clone(); if !self.short_message { @@ -3108,7 +3108,7 @@ impl FileWithAnnotatedLines { ) { for slot in file_vec.iter_mut() { // Look through each of our files for the one we're adding to - if slot.file.name == file.name { + if slot.file.stable_id == file.stable_id { // See if we already have a line for it for line_slot in &mut slot.lines { if line_slot.line_index == line_index { diff --git a/compiler/rustc_expand/src/proc_macro_server.rs b/compiler/rustc_expand/src/proc_macro_server.rs index 295573f449267..0e063011eea49 100644 --- a/compiler/rustc_expand/src/proc_macro_server.rs +++ b/compiler/rustc_expand/src/proc_macro_server.rs @@ -749,7 +749,7 @@ impl server::Span for Rustc<'_, '_> { let self_loc = self.psess().source_map().lookup_char_pos(first.lo()); let other_loc = self.psess().source_map().lookup_char_pos(second.lo()); - if self_loc.file.name != other_loc.file.name { + if self_loc.file.stable_id != other_loc.file.stable_id { return None; }