diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2024-06-21 19:22:59 +0000 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2024-08-06 04:08:10 +0000 |
| commit | 1bbaf6eb2f08a4f3d5c442560909f7109b66bf95 (patch) | |
| tree | 2dd53dd2e56b252ea6bd4134124b14190a0ad519 /compiler/rustc_errors/src | |
| parent | e57f3090aec33cdbf66063c866afaa5e1e78b9bb (diff) | |
| download | rust-1bbaf6eb2f08a4f3d5c442560909f7109b66bf95.tar.gz rust-1bbaf6eb2f08a4f3d5c442560909f7109b66bf95.zip | |
On short error format, append primary span label to message
The `error-format=short` output only displays the path, error code and main error message all in the same line. We now add the primary span label as well after the error message, to provide more context.
Diffstat (limited to 'compiler/rustc_errors/src')
| -rw-r--r-- | compiler/rustc_errors/src/emitter.rs | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 8963b009c31..c22375795e5 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -1346,10 +1346,11 @@ impl HumanEmitter { buffer.append(0, ": ", header_style); label_width += 2; } + let mut line = 0; for (text, _) in msgs.iter() { let text = self.translate_message(text, args).map_err(Report::new).unwrap(); // Account for newlines to align output to its label. - for (line, text) in normalize_whitespace(&text).lines().enumerate() { + for text in normalize_whitespace(&text).lines() { buffer.append( line, &format!( @@ -1359,6 +1360,25 @@ impl HumanEmitter { ), header_style, ); + line += 1; + } + } + if self.short_message { + let labels = msp + .span_labels() + .into_iter() + .filter_map(|label| match label.label { + Some(msg) if label.is_primary => { + let text = self.translate_message(&msg, args).ok()?; + if !text.trim().is_empty() { Some(text.to_string()) } else { None } + } + _ => None, + }) + .collect::<Vec<_>>() + .join(", "); + if !labels.is_empty() { + buffer.append(line, ": ", Style::NoStyle); + buffer.append(line, &labels, Style::NoStyle); } } } |
