mirror of
https://github.com/openharmony/third_party_rust_codespan.git
synced 2026-07-21 03:55:28 -04:00
Fix label ordering for ranges that are the same
Labels that cover the same range are now rendered in the order that they were specified in the diagnostic (as opposed to in reverse order). This means that this diagnostic:
```
┌─ same_range:1:7
│
1 │ ::S { }
│ - Expected '('
│ ^ Unexpected '{'
│
```
…will now be rendered as:
```
┌─ same_range:1:7
│
1 │ ::S { }
│ ^ Unexpected '{'
│ - Expected '('
│
```
Closes #231
This commit is contained in:
@@ -143,7 +143,10 @@ where
|
||||
// to piggyback off its lexicographic comparison implementation.
|
||||
(range.start, range.end).cmp(&(label_start, label_end))
|
||||
}) {
|
||||
Ok(index) | Err(index) => index,
|
||||
// If the ranges are the same, order the labels as they
|
||||
// originally were specified in the diagnostic.
|
||||
Ok(index) => index + 1,
|
||||
Err(index) => index,
|
||||
};
|
||||
|
||||
line.single_labels
|
||||
|
||||
@@ -7,8 +7,8 @@ expression: TEST_DATA.emit_color(&config)
|
||||
{fg:Blue}┌─{/} same_range:1:5
|
||||
{fg:Blue}│{/}
|
||||
{fg:Blue}1{/} {fg:Blue}│{/} ::S { }
|
||||
{fg:Blue}│{/} {fg:Blue}- Expected '('{/}
|
||||
{fg:Blue}│{/} {fg:Red}^ Unexpected '{'{/}
|
||||
{fg:Blue}│{/} {fg:Blue}- Expected '('{/}
|
||||
{fg:Blue}│{/}
|
||||
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ error: Unexpected token
|
||||
┌─ same_range:1:5
|
||||
│
|
||||
1 │ ::S { }
|
||||
│ - Expected '('
|
||||
│ ^ Unexpected '{'
|
||||
│ - Expected '('
|
||||
│
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user