Skip to content

Commit 35f5b73

Browse files
committed
Auto merge of #124370 - ShE3py:substitution-part-offset, r=fee1-dead
Fix substitution parts having a shifted underline in some cases If two suggestions parts are side by side, the underline's offset: (WIP PR as an example, not yet pushed) ``` error: expected a pattern, found an expression --> ./main.rs:4:9 | 4 | 1 + 2 => 3 | ^^^^^ arbitrary expressions are not allowed in patterns | help: check the value in an arm guard | 4 | n if n == 1 + 2 => 3 | ~ +++++++++++++ ``` The emitter didn't take into account that the string had shrunk/grown if two substitution parts were side-by-side (surprisingly, there was only one case in the ui testsuite.) ``` help: check the value in an arm guard | 4 | n if n == 1 + 2 => 3 | ~ +++++++++++++ ``` `@rustbot` label +A-suggestion-diagnostics
2 parents 9ac33d9 + b52e4bd commit 35f5b73

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

compiler/rustc_errors/src/emitter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2019,7 +2019,7 @@ impl HumanEmitter {
20192019
let offset: isize = offsets
20202020
.iter()
20212021
.filter_map(
2022-
|(start, v)| if span_start_pos <= *start { None } else { Some(v) },
2022+
|(start, v)| if span_start_pos < *start { None } else { Some(v) },
20232023
)
20242024
.sum();
20252025
let underline_start = (span_start_pos + start) as isize + offset;
@@ -2028,7 +2028,7 @@ impl HumanEmitter {
20282028
let padding: usize = max_line_num_len + 3;
20292029
for p in underline_start..underline_end {
20302030
if let DisplaySuggestion::Underline = show_code_change {
2031-
// If this is a replacement, underline with `^`, if this is an addition
2031+
// If this is a replacement, underline with `~`, if this is an addition
20322032
// underline with `+`.
20332033
buffer.putc(
20342034
row_num,

tests/ui/parser/issues/issue-32505.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | foo(|_|)
99
help: you might have meant to open the body of the closure
1010
|
1111
LL | foo(|_| {})
12-
| ++
12+
| ++
1313

1414
error[E0425]: cannot find function `foo` in this scope
1515
--> $DIR/issue-32505.rs:2:5

0 commit comments

Comments
 (0)