diff options
| author | bors <bors@rust-lang.org> | 2024-04-12 16:14:41 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-04-12 16:14:41 +0000 |
| commit | 322e92bdaee73946b8b78d1fb6d9c808ce1436e9 (patch) | |
| tree | 9913cdc400e9a27abfd3a96c1a27ee447123bccf /compiler/rustc_errors/src | |
| parent | bd71213cf0a765705e7d72a099151bd4eb465ccb (diff) | |
| parent | 4393eab9eaa5bcd0faa37bea4baf6c14daaff9d7 (diff) | |
| download | rust-322e92bdaee73946b8b78d1fb6d9c808ce1436e9.tar.gz rust-322e92bdaee73946b8b78d1fb6d9c808ce1436e9.zip | |
Auto merge of #123856 - matthiaskrgr:rollup-4v8rkfj, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #123204 (rustdoc: point at span in `include_str!`-ed md file) - #123223 (Fix invalid silencing of parsing error) - #123249 (do not add prolog for variadic naked functions) - #123825 (Call the panic hook for non-unwind panics in proc-macros) - #123833 (Update stdarch submodule) - #123841 (Improve diagnostic by suggesting to remove visibility qualifier) - #123849 (Update E0384.md) - #123852 (fix typo in library/std/src/lib.rs) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_errors/src')
| -rw-r--r-- | compiler/rustc_errors/src/emitter.rs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index bd8e78bda26..6ce3fa3535d 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -1513,7 +1513,9 @@ 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()) @@ -1553,7 +1555,10 @@ impl HumanEmitter { for line in &annotated_file.lines { max_line_len = max( max_line_len, - annotated_file.file.get_line(line.line_index - 1).map_or(0, |s| s.len()), + line.line_index + .checked_sub(1) + .and_then(|l| annotated_file.file.get_line(l)) + .map_or(0, |s| s.len()), ); for ann in &line.annotations { span_right_margin = max(span_right_margin, ann.start_col.display); |
