Skip to content

Commit ec17d9e

Browse files
committed
fix: Sort annotations by line number in AnnotateSnippetEmitter
1 parent 1befb0b commit ec17d9e

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,14 @@ fn collect_annotations(
742742
}
743743
}
744744
}
745+
746+
// Sort annotations within each file by line number
747+
for (_, ann) in output.iter_mut() {
748+
ann.sort_by_key(|a| {
749+
let lo = sm.lookup_char_pos(a.span.lo());
750+
lo.line
751+
});
752+
}
745753
output
746754
}
747755

tests/ui/statics/check-values-constraints.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ LL | field2: SafeEnum::Variant4("str".to_string()),
3838
note: method `to_string` is not const because trait `ToString` is not const
3939
--> $SRC_DIR/alloc/src/string.rs:LL:COL
4040
|
41-
= note: this method is not const
41+
= note: this trait is not const
4242
::: $SRC_DIR/alloc/src/string.rs:LL:COL
4343
|
44-
= note: this trait is not const
44+
= note: this method is not const
4545
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
4646
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
4747

tests/ui/typeck/typeck_type_placeholder_item.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -686,12 +686,12 @@ LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x);
686686
|
687687
note: method `filter` is not const because trait `Iterator` is not const
688688
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
689-
::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
690689
|
691-
= note: this method is not const
690+
= note: this trait is not const
691+
::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
692692
::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
693693
|
694-
= note: this trait is not const
694+
= note: this method is not const
695695
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
696696

697697
error[E0015]: cannot call non-const method `<Filter<std::ops::Range<i32>, {closure@$DIR/typeck_type_placeholder_item.rs:240:29: 240:32}> as Iterator>::map::<i32, {closure@$DIR/typeck_type_placeholder_item.rs:240:49: 240:52}>` in constants
@@ -702,12 +702,12 @@ LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x);
702702
|
703703
note: method `map` is not const because trait `Iterator` is not const
704704
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
705-
::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
706705
|
707-
= note: this method is not const
706+
= note: this trait is not const
707+
::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
708708
::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
709709
|
710-
= note: this trait is not const
710+
= note: this method is not const
711711
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
712712

713713
error: aborting due to 83 previous errors

0 commit comments

Comments
 (0)