Skip to content

Commit 0279cba

Browse files
authored
Rollup merge of rust-lang#149065 - Muscraft:annotate-snippets-regressions, r=davidtwco
Address annotate-snippets test differences When `annotate-snippets` became the default renderer on `nightly`, it came with a few rendering differences. I was not entirely happy with a few of the differences, and after talking with ``@davidtwco`` about them, I decided to address those that seemed like regressions. r? ``@davidtwco``
2 parents a2138ef + 83485b9 commit 0279cba

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ impl AnnotateSnippetEmitter {
213213
file_ann.swap(0, pos);
214214
}
215215

216+
let file_ann_len = file_ann.len();
216217
for (file_idx, (file, annotations)) in file_ann.into_iter().enumerate() {
217218
if should_show_source_code(&self.ignored_directories_in_source_blocks, sm, &file) {
218219
if let Some(snippet) = self.annotated_snippet(annotations, &file.name, sm) {
@@ -240,6 +241,7 @@ impl AnnotateSnippetEmitter {
240241
// ╰ warning: this was previously accepted
241242
if let Some(c) = children.first()
242243
&& (!c.span.has_primary_spans() && !c.span.has_span_labels())
244+
&& file_idx == file_ann_len - 1
243245
{
244246
group = group.element(Padding);
245247
}
@@ -631,7 +633,7 @@ impl AnnotateSnippetEmitter {
631633
report.push(std::mem::replace(&mut group, Group::with_level(level.clone())));
632634
}
633635

634-
if !line_tracker.contains(&lo.line) {
636+
if !line_tracker.contains(&lo.line) && (i == 0 || hi.line <= lo.line) {
635637
line_tracker.push(lo.line);
636638
// ╭▸ $SRC_DIR/core/src/option.rs:594:0 (<- It adds *this*)
637639
// ⸬ $SRC_DIR/core/src/option.rs:602:4
@@ -740,6 +742,14 @@ fn collect_annotations(
740742
}
741743
}
742744
}
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+
}
743753
output
744754
}
745755

tests/rustdoc-ui/doctest/main-alongside-macro-calls.fail.stdout

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ LL | println!();
1919
error: macro expansion ignores `{` and any tokens following
2020
--> $SRC_DIR/std/src/macros.rs:LL:COL
2121
|
22-
|
2322
::: $DIR/main-alongside-macro-calls.rs:30:1
2423
|
2524
LL | println!();
@@ -42,7 +41,6 @@ LL | println!();
4241
error: macro expansion ignores `{` and any tokens following
4342
--> $SRC_DIR/std/src/macros.rs:LL:COL
4443
|
45-
|
4644
::: $DIR/main-alongside-macro-calls.rs:34:1
4745
|
4846
LL | println!();

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: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -686,12 +686,11 @@ 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
692691
::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
693692
|
694-
= note: this trait is not const
693+
= note: this method is not const
695694
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
696695

697696
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 +701,11 @@ LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x);
702701
|
703702
note: method `map` is not const because trait `Iterator` is not const
704703
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
705-
::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
706704
|
707-
= note: this method is not const
705+
= note: this trait is not const
708706
::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
709707
|
710-
= note: this trait is not const
708+
= note: this method is not const
711709
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
712710

713711
error: aborting due to 83 previous errors

0 commit comments

Comments
 (0)