From 88584826c36749e041c56116496b54f1a5a7c909 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 6 Jun 2022 17:42:53 +0400 Subject: [PATCH 1/5] Fix a typo !(a & b) = !a | !b --- compiler/rustc_errors/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 83fe2a2df892f..de987ec45afea 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -1122,7 +1122,7 @@ impl HandlerInner { !this.emitted_diagnostics.insert(diagnostic_hash) }; - // Only emit the diagnostic if we've been asked to deduplicate and + // Only emit the diagnostic if we've been asked to deduplicate or // haven't already emitted an equivalent diagnostic. if !(self.flags.deduplicate_diagnostics && already_emitted(self)) { debug!(?diagnostic); From 0919316943f67bf84987675c3a89349e6b11e376 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 6 Jun 2022 18:04:42 +0400 Subject: [PATCH 2/5] Improve suggestions when its parts are far from each other Previously we only show at most 6 lines of suggestions and, if the suggestions are more than 6 lines apart, we've just showed ... at the end. This is probably fine, but quite confusing in my opinion. This commit is an attempt to show ... in places where there is nothing to suggest instead, for example: Before: ```text help: consider enclosing expression in a block | 3 ~ 'l: { match () { () => break 'l, 4 | 5 | 6 | 7 | 8 | ... ``` After: ```text help: consider enclosing expression in a block | 3 ~ 'l: { match () { () => break 'l, 4 | ... 31| 32~ } }; | ``` --- compiler/rustc_errors/src/emitter.rs | 167 ++++++++++++++++----------- 1 file changed, 99 insertions(+), 68 deletions(-) diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index e9e7065ec03cc..269d34ea4325d 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -656,11 +656,6 @@ impl Emitter for SilentEmitter { } } -/// Maximum number of lines we will print for a multiline suggestion; arbitrary. -/// -/// This should be replaced with a more involved mechanism to output multiline suggestions that -/// more closely mimics the regular diagnostic output, where irrelevant code lines are elided. -pub const MAX_SUGGESTION_HIGHLIGHT_LINES: usize = 6; /// Maximum number of suggestions to be shown /// /// Arbitrary, but taken from trait import suggestion limit @@ -1839,79 +1834,115 @@ impl EmitterWriter { } row_num += line_end - line_start; } - for (line_pos, (line, highlight_parts)) in - lines.by_ref().zip(highlights).take(MAX_SUGGESTION_HIGHLIGHT_LINES).enumerate() - { - // Print the span column to avoid confusion - buffer.puts( - row_num, - 0, - &self.maybe_anonymized(line_start + line_pos), - Style::LineNumber, - ); - if let DisplaySuggestion::Diff = show_code_change { - // Add the line number for both addition and removal to drive the point home. - // - // N - fn foo(bar: A) { - // N + fn foo(bar: impl T) { + let mut unhighlighted_lines = Vec::new(); + for (line_pos, (line, highlight_parts)) in lines.by_ref().zip(highlights).enumerate() { + debug!(%line_pos, %line, ?highlight_parts); + + let print_line = |line_pos: usize, + line: &str, + highlight_parts: &Vec, + buffer: &mut StyledBuffer, + row_num: &mut usize| { + // Print the span column to avoid confusion buffer.puts( - row_num - 1, + *row_num, 0, &self.maybe_anonymized(line_start + line_pos), Style::LineNumber, ); - buffer.puts(row_num - 1, max_line_num_len + 1, "- ", Style::Removal); - buffer.puts( - row_num - 1, - max_line_num_len + 3, - &normalize_whitespace( - &*file_lines - .file - .get_line(file_lines.lines[line_pos].line_index) - .unwrap(), - ), - Style::NoStyle, - ); - buffer.puts(row_num, max_line_num_len + 1, "+ ", Style::Addition); - } else if is_multiline { - match &highlight_parts[..] { - [SubstitutionHighlight { start: 0, end }] if *end == line.len() => { - buffer.puts(row_num, max_line_num_len + 1, "+ ", Style::Addition); - } - [] => { - draw_col_separator(&mut buffer, row_num, max_line_num_len + 1); - } - _ => { - buffer.puts(row_num, max_line_num_len + 1, "~ ", Style::Addition); + if let DisplaySuggestion::Diff = show_code_change { + // Add the line number for both addition and removal to drive the point home. + // + // N - fn foo(bar: A) { + // N + fn foo(bar: impl T) { + buffer.puts( + *row_num - 1, + 0, + &self.maybe_anonymized(line_start + line_pos), + Style::LineNumber, + ); + buffer.puts(*row_num - 1, max_line_num_len + 1, "- ", Style::Removal); + buffer.puts( + *row_num - 1, + max_line_num_len + 3, + &normalize_whitespace( + &*file_lines + .file + .get_line(file_lines.lines[line_pos].line_index) + .unwrap(), + ), + Style::NoStyle, + ); + buffer.puts(*row_num, max_line_num_len + 1, "+ ", Style::Addition); + } else if is_multiline { + match &highlight_parts[..] { + [SubstitutionHighlight { start: 0, end }] if *end == line.len() => { + buffer.puts(*row_num, max_line_num_len + 1, "+ ", Style::Addition); + } + [] => { + draw_col_separator(buffer, *row_num, max_line_num_len + 1); + } + _ => { + buffer.puts(*row_num, max_line_num_len + 1, "~ ", Style::Addition); + } } + } else { + draw_col_separator(buffer, *row_num, max_line_num_len + 1); } - } else { - draw_col_separator(&mut buffer, row_num, max_line_num_len + 1); - } - // print the suggestion - buffer.append(row_num, &normalize_whitespace(line), Style::NoStyle); + // print the suggestion + buffer.append(*row_num, &normalize_whitespace(line), Style::NoStyle); - // Colorize addition/replacements with green. - for &SubstitutionHighlight { start, end } in highlight_parts { - // Account for tabs when highlighting (#87972). - let tabs: usize = line - .chars() - .take(start) - .map(|ch| match ch { - '\t' => 3, - _ => 0, - }) - .sum(); - buffer.set_style_range( - row_num, - max_line_num_len + 3 + start + tabs, - max_line_num_len + 3 + end + tabs, - Style::Addition, - true, - ); + // Colorize addition/replacements with green. + for &SubstitutionHighlight { start, end } in highlight_parts { + // Account for tabs when highlighting (#87972). + let tabs: usize = line + .chars() + .take(start) + .map(|ch| match ch { + '\t' => 3, + _ => 0, + }) + .sum(); + buffer.set_style_range( + *row_num, + max_line_num_len + 3 + start + tabs, + max_line_num_len + 3 + end + tabs, + Style::Addition, + true, + ); + } + *row_num += 1; + }; + + if highlight_parts.is_empty() { + unhighlighted_lines.push((line_pos, line)); + continue; } - row_num += 1; + + match unhighlighted_lines.len() { + 0 => (), + // Since we show first line, "..." line and last line, + // There is no reason to hide if there are 3 or less lines + // (because then we just replace a line with ... which is + // not helpful) + n if n <= 3 => unhighlighted_lines.drain(..).for_each(|(p, l)| { + print_line(p, l, &Vec::new(), &mut buffer, &mut row_num) + }), + _ => { + unhighlighted_lines + .drain(..1) + .next() + .map(|(p, l)| print_line(p, l, &Vec::new(), &mut buffer, &mut row_num)); + buffer.puts(row_num, max_line_num_len - 1, "...", Style::LineNumber); + row_num += 1; + unhighlighted_lines + .pop() + .map(|(p, l)| print_line(p, l, &Vec::new(), &mut buffer, &mut row_num)); + } + } + + print_line(line_pos, line, highlight_parts, &mut buffer, &mut row_num) } // This offset and the ones below need to be signed to account for replacement code From 2311aca441a5699701ab5d2aa9b3e2bd635dbce3 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 6 Jun 2022 19:26:50 +0400 Subject: [PATCH 3/5] --bless ui --- src/test/ui/associated-consts/issue-93835.stderr | 7 +++---- .../migrations/auto_traits.stderr | 14 ++++++-------- .../migrations/multi_diagnostics.stderr | 7 +++---- src/test/ui/imports/issue-59764.stderr | 3 +-- src/test/ui/issues/issue-22644.stderr | 7 +++---- src/test/ui/let-else/let-else-if.stderr | 3 +-- .../parser/recover-labeled-non-block-expr.stderr | 7 +++---- src/test/ui/type/ascription/issue-34255-1.stderr | 3 +-- .../unboxed-closure-sugar-lifetime-elision.stderr | 7 +++---- 9 files changed, 24 insertions(+), 34 deletions(-) diff --git a/src/test/ui/associated-consts/issue-93835.stderr b/src/test/ui/associated-consts/issue-93835.stderr index 12df0e4381d15..0406a16a39732 100644 --- a/src/test/ui/associated-consts/issue-93835.stderr +++ b/src/test/ui/associated-consts/issue-93835.stderr @@ -19,11 +19,10 @@ help: you might have meant to write a `struct` literal | LL ~ fn e() { SomeStruct { LL | p:a> -LL | -LL | -LL | -LL | ... +LL | +LL ~ }} + | help: maybe you meant to write a path separator here | LL | p::a> diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.stderr b/src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.stderr index a8367766ae1cf..a3c43690f1f32 100644 --- a/src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.stderr +++ b/src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.stderr @@ -17,11 +17,10 @@ help: add a dummy let to cause `fptr` to be fully captured | LL ~ thread::spawn(move || { let _ = &fptr; unsafe { LL | -LL | -LL | -LL | -LL | *fptr.0 = 20; ... +LL | +LL ~ } }); + | error: changes to closure capture in Rust 2021 will affect which traits the closure implements --> $DIR/auto_traits.rs:42:19 @@ -39,12 +38,11 @@ LL | *fptr.0.0 = 20; help: add a dummy let to cause `fptr` to be fully captured | LL ~ thread::spawn(move || { let _ = &fptr; unsafe { -LL | -LL | -LL | -LL | LL | ... +LL | +LL ~ } }); + | error: changes to closure capture in Rust 2021 will affect drop order and which traits the closure implements --> $DIR/auto_traits.rs:67:13 diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.stderr b/src/test/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.stderr index 483eae6bb4b1f..fa6082cbb59b4 100644 --- a/src/test/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.stderr +++ b/src/test/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.stderr @@ -108,12 +108,11 @@ LL | *fptr2.0 = 20; help: add a dummy let to cause `fptr1`, `fptr2` to be fully captured | LL ~ thread::spawn(move || { let _ = (&fptr1, &fptr2); unsafe { -LL | -LL | -LL | -LL | LL | ... +LL | +LL ~ } }); + | error: aborting due to 5 previous errors diff --git a/src/test/ui/imports/issue-59764.stderr b/src/test/ui/imports/issue-59764.stderr index c2cfc0939d6b3..8d99d757c17d6 100644 --- a/src/test/ui/imports/issue-59764.stderr +++ b/src/test/ui/imports/issue-59764.stderr @@ -209,8 +209,7 @@ help: a macro with this name exists at the root of the crate | LL ~ issue_59764::{makro as foobar, LL | -LL | foobaz, -LL | + ... LL | LL ~ foo::{baz} | diff --git a/src/test/ui/issues/issue-22644.stderr b/src/test/ui/issues/issue-22644.stderr index 6bec98121b759..039ffbfd3d89f 100644 --- a/src/test/ui/issues/issue-22644.stderr +++ b/src/test/ui/issues/issue-22644.stderr @@ -89,12 +89,11 @@ LL | 5); help: try comparing the cast value | LL ~ println!("{}", (a -LL | -LL | -LL | as -LL | LL | ... +LL | +LL ~ usize) + | error: `<` is interpreted as a start of generic arguments for `usize`, not a shift --> $DIR/issue-22644.rs:32:31 diff --git a/src/test/ui/let-else/let-else-if.stderr b/src/test/ui/let-else/let-else-if.stderr index a0324565673da..746738bbd939b 100644 --- a/src/test/ui/let-else/let-else-if.stderr +++ b/src/test/ui/let-else/let-else-if.stderr @@ -8,8 +8,7 @@ help: try placing this code inside a block | LL ~ let Some(_) = Some(()) else { if true { LL | -LL | return; -LL | } else { + ... LL | return; LL ~ } }; | diff --git a/src/test/ui/parser/recover-labeled-non-block-expr.stderr b/src/test/ui/parser/recover-labeled-non-block-expr.stderr index 767389c48088a..d95c25fdea8b5 100644 --- a/src/test/ui/parser/recover-labeled-non-block-expr.stderr +++ b/src/test/ui/parser/recover-labeled-non-block-expr.stderr @@ -54,11 +54,10 @@ help: consider enclosing expression in a block | LL ~ let _i = 'label: { match x { LL | 0 => 42, -LL | 1 if false => break 'label 17, -LL | 1 => { -LL | if true { -LL | break 'label 13 ... +LL | _ => 1, +LL ~ } }; + | error: expected `while`, `for`, `loop` or `{` after a label --> $DIR/recover-labeled-non-block-expr.rs:26:24 diff --git a/src/test/ui/type/ascription/issue-34255-1.stderr b/src/test/ui/type/ascription/issue-34255-1.stderr index 43f0fbbc4e387..6819d14bb0106 100644 --- a/src/test/ui/type/ascription/issue-34255-1.stderr +++ b/src/test/ui/type/ascription/issue-34255-1.stderr @@ -8,8 +8,7 @@ help: you might have meant to write a `struct` literal | LL ~ pub fn new() -> Self { SomeStruct { LL | input_cells: Vec::new() -LL | -LL | + ... LL | LL ~ }} | diff --git a/src/test/ui/unboxed-closures/unboxed-closure-sugar-lifetime-elision.stderr b/src/test/ui/unboxed-closures/unboxed-closure-sugar-lifetime-elision.stderr index 64d14d0fc5fa4..d25452456bb21 100644 --- a/src/test/ui/unboxed-closures/unboxed-closure-sugar-lifetime-elision.stderr +++ b/src/test/ui/unboxed-closures/unboxed-closure-sugar-lifetime-elision.stderr @@ -9,11 +9,10 @@ help: consider introducing a named lifetime parameter | LL ~ fn main<'a>() { LL | eq::< dyn for<'a> Foo<(&'a isize,), Output=&'a isize>, -LL | dyn Foo(&isize) -> &isize >(); -LL | eq::< dyn for<'a> Foo<(&'a isize,), Output=(&'a isize, &'a isize)>, -LL | dyn Foo(&isize) -> (&isize, &isize) >(); -LL | ... +LL | +LL ~ let _: dyn Foo(&'a isize, &'a usize) -> &'a usize; + | error: aborting due to previous error From 122849bab1ba3a698e6a121dac0edc0765c087e8 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 13 Jun 2022 15:22:26 +0400 Subject: [PATCH 4/5] Try to clean up code... I'm not sure if I succeeded --- compiler/rustc_errors/src/emitter.rs | 243 +++++++++++++++++---------- 1 file changed, 150 insertions(+), 93 deletions(-) diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 269d34ea4325d..690ba14e69975 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -10,7 +10,7 @@ use Destination::*; use rustc_span::source_map::SourceMap; -use rustc_span::{SourceFile, Span}; +use rustc_span::{FileLines, SourceFile, Span}; use crate::snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, Style, StyledString}; use crate::styled_buffer::StyledBuffer; @@ -1756,12 +1756,6 @@ impl EmitterWriter { let has_deletion = parts.iter().any(|p| p.is_deletion()); let is_multiline = complete.lines().count() > 1; - enum DisplaySuggestion { - Underline, - Diff, - None, - } - if let Some(span) = span.primary_span() { // Compare the primary span of the diagnostic with the span of the suggestion // being emitted. If they belong to the same file, we don't *need* to show the @@ -1838,83 +1832,7 @@ impl EmitterWriter { for (line_pos, (line, highlight_parts)) in lines.by_ref().zip(highlights).enumerate() { debug!(%line_pos, %line, ?highlight_parts); - let print_line = |line_pos: usize, - line: &str, - highlight_parts: &Vec, - buffer: &mut StyledBuffer, - row_num: &mut usize| { - // Print the span column to avoid confusion - buffer.puts( - *row_num, - 0, - &self.maybe_anonymized(line_start + line_pos), - Style::LineNumber, - ); - if let DisplaySuggestion::Diff = show_code_change { - // Add the line number for both addition and removal to drive the point home. - // - // N - fn foo(bar: A) { - // N + fn foo(bar: impl T) { - buffer.puts( - *row_num - 1, - 0, - &self.maybe_anonymized(line_start + line_pos), - Style::LineNumber, - ); - buffer.puts(*row_num - 1, max_line_num_len + 1, "- ", Style::Removal); - buffer.puts( - *row_num - 1, - max_line_num_len + 3, - &normalize_whitespace( - &*file_lines - .file - .get_line(file_lines.lines[line_pos].line_index) - .unwrap(), - ), - Style::NoStyle, - ); - buffer.puts(*row_num, max_line_num_len + 1, "+ ", Style::Addition); - } else if is_multiline { - match &highlight_parts[..] { - [SubstitutionHighlight { start: 0, end }] if *end == line.len() => { - buffer.puts(*row_num, max_line_num_len + 1, "+ ", Style::Addition); - } - [] => { - draw_col_separator(buffer, *row_num, max_line_num_len + 1); - } - _ => { - buffer.puts(*row_num, max_line_num_len + 1, "~ ", Style::Addition); - } - } - } else { - draw_col_separator(buffer, *row_num, max_line_num_len + 1); - } - - // print the suggestion - buffer.append(*row_num, &normalize_whitespace(line), Style::NoStyle); - - // Colorize addition/replacements with green. - for &SubstitutionHighlight { start, end } in highlight_parts { - // Account for tabs when highlighting (#87972). - let tabs: usize = line - .chars() - .take(start) - .map(|ch| match ch { - '\t' => 3, - _ => 0, - }) - .sum(); - buffer.set_style_range( - *row_num, - max_line_num_len + 3 + start + tabs, - max_line_num_len + 3 + end + tabs, - Style::Addition, - true, - ); - } - *row_num += 1; - }; - + // Remember lines that are not highlighted to hide them if needed if highlight_parts.is_empty() { unhighlighted_lines.push((line_pos, line)); continue; @@ -1927,22 +1845,77 @@ impl EmitterWriter { // (because then we just replace a line with ... which is // not helpful) n if n <= 3 => unhighlighted_lines.drain(..).for_each(|(p, l)| { - print_line(p, l, &Vec::new(), &mut buffer, &mut row_num) + self.draw_code_line( + &mut buffer, + &mut row_num, + &Vec::new(), + p, + l, + line_start, + show_code_change, + max_line_num_len, + &file_lines, + is_multiline, + ) }), + // Print first unhighlighted line, "..." and last unhighlighted line, like so: + // + // LL | this line was highlighted + // LL | this line is just for context + // ... + // LL | this line is just for context + // LL | this line was highlighted _ => { - unhighlighted_lines - .drain(..1) - .next() - .map(|(p, l)| print_line(p, l, &Vec::new(), &mut buffer, &mut row_num)); + let last_line = unhighlighted_lines.pop(); + let first_line = unhighlighted_lines.drain(..).next(); + + first_line.map(|(p, l)| { + self.draw_code_line( + &mut buffer, + &mut row_num, + &Vec::new(), + p, + l, + line_start, + show_code_change, + max_line_num_len, + &file_lines, + is_multiline, + ) + }); + buffer.puts(row_num, max_line_num_len - 1, "...", Style::LineNumber); row_num += 1; - unhighlighted_lines - .pop() - .map(|(p, l)| print_line(p, l, &Vec::new(), &mut buffer, &mut row_num)); + + last_line.map(|(p, l)| { + self.draw_code_line( + &mut buffer, + &mut row_num, + &Vec::new(), + p, + l, + line_start, + show_code_change, + max_line_num_len, + &file_lines, + is_multiline, + ) + }); } } - print_line(line_pos, line, highlight_parts, &mut buffer, &mut row_num) + self.draw_code_line( + &mut buffer, + &mut row_num, + highlight_parts, + line_pos, + line, + line_start, + show_code_change, + max_line_num_len, + &file_lines, + is_multiline, + ) } // This offset and the ones below need to be signed to account for replacement code @@ -2127,6 +2100,90 @@ impl EmitterWriter { } } } + + fn draw_code_line( + &self, + buffer: &mut StyledBuffer, + row_num: &mut usize, + highlight_parts: &Vec, + line_pos: usize, + line: &str, + line_start: usize, + show_code_change: DisplaySuggestion, + max_line_num_len: usize, + file_lines: &FileLines, + is_multiline: bool, + ) { + // Print the span column to avoid confusion + buffer.puts(*row_num, 0, &self.maybe_anonymized(line_start + line_pos), Style::LineNumber); + if let DisplaySuggestion::Diff = show_code_change { + // Add the line number for both addition and removal to drive the point home. + // + // N - fn foo(bar: A) { + // N + fn foo(bar: impl T) { + buffer.puts( + *row_num - 1, + 0, + &self.maybe_anonymized(line_start + line_pos), + Style::LineNumber, + ); + buffer.puts(*row_num - 1, max_line_num_len + 1, "- ", Style::Removal); + buffer.puts( + *row_num - 1, + max_line_num_len + 3, + &normalize_whitespace( + &*file_lines.file.get_line(file_lines.lines[line_pos].line_index).unwrap(), + ), + Style::NoStyle, + ); + buffer.puts(*row_num, max_line_num_len + 1, "+ ", Style::Addition); + } else if is_multiline { + match &highlight_parts[..] { + [SubstitutionHighlight { start: 0, end }] if *end == line.len() => { + buffer.puts(*row_num, max_line_num_len + 1, "+ ", Style::Addition); + } + [] => { + draw_col_separator(buffer, *row_num, max_line_num_len + 1); + } + _ => { + buffer.puts(*row_num, max_line_num_len + 1, "~ ", Style::Addition); + } + } + } else { + draw_col_separator(buffer, *row_num, max_line_num_len + 1); + } + + // print the suggestion + buffer.append(*row_num, &normalize_whitespace(line), Style::NoStyle); + + // Colorize addition/replacements with green. + for &SubstitutionHighlight { start, end } in highlight_parts { + // Account for tabs when highlighting (#87972). + let tabs: usize = line + .chars() + .take(start) + .map(|ch| match ch { + '\t' => 3, + _ => 0, + }) + .sum(); + buffer.set_style_range( + *row_num, + max_line_num_len + 3 + start + tabs, + max_line_num_len + 3 + end + tabs, + Style::Addition, + true, + ); + } + *row_num += 1; + } +} + +#[derive(Clone, Copy)] +enum DisplaySuggestion { + Underline, + Diff, + None, } impl FileWithAnnotatedLines { From 1961d9e57e2a5d668a1a7028f786147291ba325b Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 13 Jun 2022 18:28:31 +0400 Subject: [PATCH 5/5] Add back MAX_SUGGESTION_HIGHLIGHT_LINES so clippy is happy & buildable --- compiler/rustc_errors/src/emitter.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 690ba14e69975..1329e3a0b959d 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -656,6 +656,11 @@ impl Emitter for SilentEmitter { } } +/// Maximum number of lines we will print for a multiline suggestion; arbitrary. +/// +/// This should be replaced with a more involved mechanism to output multiline suggestions that +/// more closely mimics the regular diagnostic output, where irrelevant code lines are elided. +pub const MAX_SUGGESTION_HIGHLIGHT_LINES: usize = 6; /// Maximum number of suggestions to be shown /// /// Arbitrary, but taken from trait import suggestion limit