Skip to content

Commit 770c8d0

Browse files
authored
Rollup merge of #113871 - clubby789:derive-sugg-span, r=compiler-errors
Use the correct span for displaying the line following a derive sugge… `span` here is the main span of the diagnostic. In the linked issue's case, this belongs to `main.rs`. However, the line numbers (and line we are trying to display) are in `name.rs`, so using `span_to_lines` gives us the wrong `FileLines`. Use `parts[0].span` (the span of the suggestion) here like the rest of the code does to get the right file. Not sure if this needs a dedicated test because this fixes an existing error in the UI suite Fixes #113844
2 parents 53580da + 20a3b9a commit 770c8d0

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

compiler/rustc_errors/src/emitter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1982,7 +1982,7 @@ impl EmitterWriter {
19821982
// We special case `#[derive(_)]\n` and other attribute suggestions, because those
19831983
// are the ones where context is most useful.
19841984
let file_lines = sm
1985-
.span_to_lines(span.primary_span().unwrap().shrink_to_hi())
1985+
.span_to_lines(parts[0].span.shrink_to_hi())
19861986
.expect("span_to_lines failed when emitting suggestion");
19871987
let line_num = sm.lookup_char_pos(parts[0].span.lo()).line;
19881988
if let Some(line) = file_lines.file.get_line(line_num - 1) {

tests/ui/modules/issue-107649.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ help: consider annotating `Dummy` with `#[derive(Debug)]`
1111
--> $DIR/auxiliary/dummy_lib.rs:2:1
1212
|
1313
2 + #[derive(Debug)]
14-
3 | #[path = "auxiliary/dummy_lib.rs"]
14+
3 | pub struct Dummy;
1515
|
1616

1717
error: aborting due to previous error

0 commit comments

Comments
 (0)