Skip to content

Commit e24793c

Browse files
authored
Unrolled build for #143264
Rollup merge of #143264 - Muscraft:fix-suggestion-filename, r=compiler-errors fix: Emit suggestion filename if primary diagnostic span is dummy While working on using `annotate-snippets` as `rustc`'s emitter, I came across [`tests/ui/resolve/resolve-conflict-extern-crate-vs-extern-crate.stderr`](https://github.com/rust-lang/rust/blob/b03b3a7ec92682be2917540b679478d41c95a30c/tests/ui/resolve/resolve-conflict-extern-crate-vs-extern-crate.stderr), which lacked a filename for both the annotation and the suggestion, which seemed like a bug to me. After some investigation, I found that this is happening because the primary span is a dummy, so its filename doesn't get output, and its filename matches the one for the suggestion, so the suggestion's filename doesn't get output. To fix this issue, I made it so that the filename for a suggestion will get output if the primary span is a dummy.
2 parents 6988a8f + c8fac77 commit e24793c

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

compiler/rustc_errors/src/emitter.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2078,7 +2078,9 @@ impl HumanEmitter {
20782078
// file name, saving in verbosity, but if it *isn't* we do need it, otherwise we're
20792079
// telling users to make a change but not clarifying *where*.
20802080
let loc = sm.lookup_char_pos(parts[0].span.lo());
2081-
if loc.file.name != sm.span_to_filename(span) && loc.file.name.is_real() {
2081+
if (span.is_dummy() || loc.file.name != sm.span_to_filename(span))
2082+
&& loc.file.name.is_real()
2083+
{
20822084
// --> file.rs:line:col
20832085
// |
20842086
let arrow = self.file_start();

tests/ui/resolve/resolve-conflict-extern-crate-vs-extern-crate.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ error[E0259]: the name `std` is defined multiple times
22
|
33
= note: `std` must be defined only once in the type namespace of this module
44
help: you can use `as` to change the binding name of the import
5+
--> $DIR/resolve-conflict-extern-crate-vs-extern-crate.rs:1:17
56
|
67
LL | extern crate std as other_std;
78
| ++++++++++++

0 commit comments

Comments
 (0)