Skip to content

Commit 75911b6

Browse files
committed
feat: Annotate empty files
1 parent 18ce4fb commit 75911b6

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

compiler/rustc_errors/src/emitter.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -763,13 +763,7 @@ impl HumanEmitter {
763763
// | vertical divider between the column number and the code
764764
// column number
765765

766-
if line.line_index == 0 {
767-
return Vec::new();
768-
}
769-
770-
let Some(source_string) = file.get_line(line.line_index - 1) else {
771-
return Vec::new();
772-
};
766+
let source_string = file.get_line(line.line_index - 1).unwrap_or_default();
773767
trace!(?source_string);
774768

775769
let line_offset = buffer.num_lines();
@@ -1687,7 +1681,6 @@ impl HumanEmitter {
16871681
}
16881682
continue;
16891683
}
1690-
16911684
// print out the span location and spacer before we print the annotated source
16921685
// to do this, we need to know if this span will be primary
16931686
let is_primary = primary_lo.file.name == annotated_file.file.name;
@@ -1697,13 +1690,17 @@ impl HumanEmitter {
16971690
// remember where we are in the output buffer for easy reference
16981691
let buffer_msg_line_offset = buffer.num_lines();
16991692

1693+
let mut line = sm.doctest_offset_line(&loc.file.name, loc.line);
1694+
if line == 0 {
1695+
line += 1;
1696+
}
17001697
buffer.prepend(buffer_msg_line_offset, self.file_start(), Style::LineNumber);
17011698
buffer.append(
17021699
buffer_msg_line_offset,
17031700
&format!(
17041701
"{}:{}:{}",
17051702
sm.filename_for_diagnostics(&loc.file.name),
1706-
sm.doctest_offset_line(&loc.file.name, loc.line),
1703+
line,
17071704
loc.col.0 + 1,
17081705
),
17091706
Style::LineAndColumn,

tests/ui/include-macros/mismatched-types.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
error[E0308]: mismatched types
2-
--> $DIR/file.txt:0:1
2+
--> $DIR/file.txt:1:1
33
|
4+
LL |
5+
| ^ expected `&[u8]`, found `&str`
46
|
57
::: $DIR/mismatched-types.rs:2:12
68
|

0 commit comments

Comments
 (0)