Skip to content

Commit

Permalink
diagnostics: fix crash on completely empty included file
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle committed Mar 30, 2024
1 parent 1b73c7d commit a21216f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/emitter.rs
Expand Up @@ -1513,7 +1513,7 @@ impl HumanEmitter {
for line_idx in 0..annotated_file.lines.len() {
let file = annotated_file.file.clone();
let line = &annotated_file.lines[line_idx];
if let Some(source_string) = file.get_line(line.line_index - 1) {
if let Some(source_string) = line.line_index.checked_sub(1).and_then(|l| file.get_line(l)) {
let leading_whitespace = source_string
.chars()
.take_while(|c| c.is_whitespace())
Expand Down
7 changes: 5 additions & 2 deletions tests/ui/include-macros/mismatched-types.stderr
@@ -1,8 +1,11 @@
error[E0308]: mismatched types
--> $DIR/mismatched-types.rs:2:20
--> $DIR/file.txt:0:1
|
|
::: $DIR/mismatched-types.rs:2:12
|
LL | let b: &[u8] = include_str!("file.txt");
| ----- ^^^^^^^^^^^^^^^^^^^^^^^^ expected `&[u8]`, found `&str`
| ----- ------------------------ in this macro invocation
| |
| expected due to this
|
Expand Down

0 comments on commit a21216f

Please sign in to comment.