diff --git a/compiler/rustc_driver_impl/src/highlighter.rs b/compiler/rustc_driver_impl/src/highlighter.rs index 70b73cc29b723..16b8f58bca1e6 100644 --- a/compiler/rustc_driver_impl/src/highlighter.rs +++ b/compiler/rustc_driver_impl/src/highlighter.rs @@ -106,7 +106,7 @@ impl Highlighter { // This heuristic test is to detect if the identifier is // a function call. If it is, then the function identifier is // colored differently. - if code[*len_accum..*len_accum + len + 1].ends_with('(') { + if code[*len_accum + len..].starts_with('(') { style = style.fg_color(Some(Color::Ansi(FUNCTION_COLOR))); } // The `derive` keyword is colored differently. diff --git a/tests/ui/explain/explanation-code-rendering-edge-case-regression.rs b/tests/ui/explain/explanation-code-rendering-edge-case-regression.rs new file mode 100644 index 0000000000000..0d12c71bb8736 --- /dev/null +++ b/tests/ui/explain/explanation-code-rendering-edge-case-regression.rs @@ -0,0 +1,3 @@ +//@ compile-flags: --explain E0602 --color always --error-format=human +//@ check-pass +// Ensure that we trigger the condition for #156326 without ICEing. diff --git a/tests/ui/explain/explanation-code-rendering-edge-case-regression.stdout b/tests/ui/explain/explanation-code-rendering-edge-case-regression.stdout new file mode 100644 index 0000000000000..962d129214349 --- /dev/null +++ b/tests/ui/explain/explanation-code-rendering-edge-case-regression.stdout @@ -0,0 +1,7 @@ +An unknown or invalid lint was used on the command line. + +Erroneous code example: + +rustc -D bogus rust_file.rs + +Maybe you just misspelled the lint name or the lint doesn't exist anymore. Either way, try to update/remove it in order to fix the error.