diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 93b1e6b761520..aa36713834815 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -2412,7 +2412,7 @@ impl HumanEmitter { // too bad to begin with, so we side-step that issue here. for (i, line) in snippet.lines().enumerate() { let line = normalize_whitespace(line); - let row = row_num - 2 - (newlines - i - 1); + let row = (row_num - 2 - (newlines - i - 1)).max(2); // On the first line, we highlight between the start of the part // span, and the end of that line. // On the last line, we highlight between the start of the line, and diff --git a/tests/ui/argument-suggestions/wrong-highlight-span-extra-arguments-147070.rs b/tests/ui/argument-suggestions/wrong-highlight-span-extra-arguments-147070.rs new file mode 100644 index 0000000000000..65408fd028604 --- /dev/null +++ b/tests/ui/argument-suggestions/wrong-highlight-span-extra-arguments-147070.rs @@ -0,0 +1,30 @@ +//@ only-linux +//@ compile-flags: --error-format=human --color=always + +// The hightlight span should be correct. See #147070 +struct Thingie; + +impl Thingie { + pub(crate) fn new( + _a: String, + _b: String, + _c: String, + _d: String, + _e: String, + _f: String, + ) -> Self { + unimplemented!() + } +} + +fn main() { + let foo = Thingie::new( + String::from(""), + String::from(""), + String::from(""), + String::from(""), + String::from(""), + String::from(""), + String::from(""), + ); +} diff --git a/tests/ui/argument-suggestions/wrong-highlight-span-extra-arguments-147070.svg b/tests/ui/argument-suggestions/wrong-highlight-span-extra-arguments-147070.svg new file mode 100644 index 0000000000000..67f9436b6a527 --- /dev/null +++ b/tests/ui/argument-suggestions/wrong-highlight-span-extra-arguments-147070.svg @@ -0,0 +1,72 @@ + + + + + + + error[E0061]: this function takes 6 arguments but 7 arguments were supplied + + --> $DIR/wrong-highlight-span-extra-arguments-147070.rs:21:15 + + | + + LL | let foo = Thingie::new( + + | ^^^^^^^^^^^^ + + ... + + LL | String::from(""), + + | ---------------- unexpected argument #7 of type `String` + + | + + note: associated function defined here + + --> $DIR/wrong-highlight-span-extra-arguments-147070.rs:8:19 + + | + + LL | pub(crate) fn new( + + | ^^^ + + help: remove the extra argument + + | + + LL - String::from(""), + + | + + + + error: aborting due to 1 previous error + + + + For more information about this error, try `rustc --explain E0061`. + + + + + +