diff options
| author | bors <bors@rust-lang.org> | 2024-04-16 06:41:11 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-04-16 06:41:11 +0000 |
| commit | 88d1a1c6fdf6e607606876cdab672eebdf6a3c71 (patch) | |
| tree | 438ae4e11b312666a2c073fff0184ec42aa7274f /compiler/rustc_errors/src | |
| parent | 2f08c2c96501990caab0e47a095d76ffd6a31f16 (diff) | |
| parent | 3d3a584e4d88a572d68d7996122cda69a38dcf2e (diff) | |
| download | rust-88d1a1c6fdf6e607606876cdab672eebdf6a3c71.tar.gz rust-88d1a1c6fdf6e607606876cdab672eebdf6a3c71.zip | |
Auto merge of #3469 - rust-lang:rustup-2024-04-16, r=RalfJung
Automatic Rustup
Diffstat (limited to 'compiler/rustc_errors/src')
| -rw-r--r-- | compiler/rustc_errors/src/diagnostic_impls.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/emitter.rs | 9 |
2 files changed, 8 insertions, 2 deletions
diff --git a/compiler/rustc_errors/src/diagnostic_impls.rs b/compiler/rustc_errors/src/diagnostic_impls.rs index f90190797ae..6c0551848d6 100644 --- a/compiler/rustc_errors/src/diagnostic_impls.rs +++ b/compiler/rustc_errors/src/diagnostic_impls.rs @@ -46,6 +46,7 @@ impl<'a, T: Clone + IntoDiagArg> IntoDiagArg for &'a T { } } +#[macro_export] macro_rules! into_diag_arg_using_display { ($( $ty:ty ),+ $(,)?) => { $( 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); |
