Skip to content

Commit 172ecc3

Browse files
Rollup merge of rust-lang#157342 - estebank:cycle-error-verbose, r=tiif
Reduce verbosity of cycle errors when possible When pointing at each step of cycle errors, do not include the code snippet when the note points at the same place as the previous one (by setting the note's span to DUMMY_SP).
2 parents 06f5d3d + 2c7186a commit 172ecc3

71 files changed

Lines changed: 204 additions & 624 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_query_impl/src/error.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ pub(crate) struct Cycle {
7575
#[subdiagnostic]
7676
pub cycle_usage: Option<CycleUsage>,
7777
#[note(
78-
"see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information"
78+
"for more information, see <https://rustc-dev-guide.rust-lang.org/overview.html#queries> \
79+
and <https://rustc-dev-guide.rust-lang.org/query.html>"
7980
)]
8081
pub note_span: (),
8182
}

compiler/rustc_query_impl/src/job.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,16 +429,23 @@ pub(crate) fn create_cycle_error<'tcx>(
429429
StackCount::Multiple { stack_bottom: stack_bottom.clone() }
430430
};
431431

432+
let mut prev = span;
432433
for i in 1..frames.len() {
433434
let frame = &frames[i];
434435
let span = frame.tagged_key.catch_default_span(tcx, frames[(i + 1) % frames.len()].span);
435-
cycle_stack
436-
.push(crate::error::CycleStack { span, desc: frame.tagged_key.catch_description(tcx) });
436+
cycle_stack.push(crate::error::CycleStack {
437+
span: if span == prev { DUMMY_SP } else { span },
438+
desc: frame.tagged_key.catch_description(tcx),
439+
});
440+
prev = span;
437441
}
438442

439-
let cycle_usage = usage.as_ref().map(|usage| crate::error::CycleUsage {
440-
span: usage.tagged_key.catch_default_span(tcx, usage.span),
441-
usage: usage.tagged_key.catch_description(tcx),
443+
let cycle_usage = usage.as_ref().map(|usage| {
444+
let cycle_span = usage.tagged_key.catch_default_span(tcx, usage.span);
445+
crate::error::CycleUsage {
446+
span: if cycle_span != span { cycle_span } else { DUMMY_SP },
447+
usage: usage.tagged_key.catch_description(tcx),
448+
}
442449
});
443450

444451
let is_all_def_kind = |def_kind| {

src/tools/miri/tests/fail/layout_cycle.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ note: cycle used when const-evaluating + checking `core::mem::SizedTypePropertie
1515
|
1616
LL | const SIZE: usize = intrinsics::size_of::<Self>();
1717
| ^^^^^^^^^^^^^^^^^
18-
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
18+
= note: for more information, see <https://rustc-dev-guide.rust-lang.org/overview.html#queries> and <https://rustc-dev-guide.rust-lang.org/query.html>
1919

2020
error: aborting due to 1 previous error
2121

tests/rustdoc-ui/private-type-cycle-dyn-110629.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ note: cycle used when checking that `Bar` is well-formed
1313
|
1414
LL | type Bar<'a, 'b> = Box<dyn PartialEq<Bar<'a, 'b>>>;
1515
| ^^^^^^^^^^^^^^^^
16-
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
16+
= note: for more information, see <https://rustc-dev-guide.rust-lang.org/overview.html#queries> and <https://rustc-dev-guide.rust-lang.org/query.html>
1717

1818
error: aborting due to 1 previous error
1919

tests/ui/associated-consts/defaults-cyclic-fail.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ note: cycle used when optimizing promoted MIR for `main`
2525
|
2626
LL | assert_eq!(<() as Tr>::A, 0);
2727
| ^^^^^^^^^^^^^
28-
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
28+
= note: for more information, see <https://rustc-dev-guide.rust-lang.org/overview.html#queries> and <https://rustc-dev-guide.rust-lang.org/query.html>
2929

3030
error: aborting due to 1 previous error
3131

tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-impl.stderr

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,16 @@ error[E0391]: cycle detected when checking if `IMPL_REF_BAR` is a trivial const
44
LL | const IMPL_REF_BAR: u32 = GlobalImplRef::BAR;
55
| ^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
note: ...which requires building MIR for `IMPL_REF_BAR`...
8-
--> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:7:1
9-
|
10-
LL | const IMPL_REF_BAR: u32 = GlobalImplRef::BAR;
11-
| ^^^^^^^^^^^^^^^^^^^^^^^
7+
= note: ...which requires building MIR for `IMPL_REF_BAR`...
128
note: ...which requires checking if `<impl at $DIR/issue-24949-assoc-const-static-recursion-impl.rs:11:1: 11:19>::BAR` is a trivial const...
139
--> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:12:5
1410
|
1511
LL | const BAR: u32 = IMPL_REF_BAR;
1612
| ^^^^^^^^^^^^^^
17-
note: ...which requires building MIR for `<impl at $DIR/issue-24949-assoc-const-static-recursion-impl.rs:11:1: 11:19>::BAR`...
18-
--> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:12:5
19-
|
20-
LL | const BAR: u32 = IMPL_REF_BAR;
21-
| ^^^^^^^^^^^^^^
13+
= note: ...which requires building MIR for `<impl at $DIR/issue-24949-assoc-const-static-recursion-impl.rs:11:1: 11:19>::BAR`...
2214
= note: ...which again requires checking if `IMPL_REF_BAR` is a trivial const, completing the cycle
23-
note: cycle used when simplifying constant for the type system `IMPL_REF_BAR`
24-
--> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:7:1
25-
|
26-
LL | const IMPL_REF_BAR: u32 = GlobalImplRef::BAR;
27-
| ^^^^^^^^^^^^^^^^^^^^^^^
28-
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
15+
= note: cycle used when simplifying constant for the type system `IMPL_REF_BAR`
16+
= note: for more information, see <https://rustc-dev-guide.rust-lang.org/overview.html#queries> and <https://rustc-dev-guide.rust-lang.org/query.html>
2917

3018
error: aborting due to 1 previous error
3119

tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait-default.stderr

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,10 @@ note: ...which requires simplifying constant for the type system `FooDefault::BA
2424
|
2525
LL | const BAR: u32 = DEFAULT_REF_BAR;
2626
| ^^^^^^^^^^^^^^
27-
note: ...which requires const-evaluating + checking `FooDefault::BAR`...
28-
--> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:8:5
29-
|
30-
LL | const BAR: u32 = DEFAULT_REF_BAR;
31-
| ^^^^^^^^^^^^^^
27+
= note: ...which requires const-evaluating + checking `FooDefault::BAR`...
3228
= note: ...which again requires caching mir of `FooDefault::BAR` for CTFE, completing the cycle
33-
note: cycle used when const-evaluating + checking `FooDefault::BAR`
34-
--> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:8:5
35-
|
36-
LL | const BAR: u32 = DEFAULT_REF_BAR;
37-
| ^^^^^^^^^^^^^^
38-
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
29+
= note: cycle used when const-evaluating + checking `FooDefault::BAR`
30+
= note: for more information, see <https://rustc-dev-guide.rust-lang.org/overview.html#queries> and <https://rustc-dev-guide.rust-lang.org/query.html>
3931

4032
error: aborting due to 1 previous error
4133

tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait.stderr

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,16 @@ note: ...which requires simplifying constant for the type system `<impl at $DIR/
1414
|
1515
LL | const BAR: u32 = TRAIT_REF_BAR;
1616
| ^^^^^^^^^^^^^^
17-
note: ...which requires const-evaluating + checking `<impl at $DIR/issue-24949-assoc-const-static-recursion-trait.rs:11:1: 11:28>::BAR`...
18-
--> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:12:5
19-
|
20-
LL | const BAR: u32 = TRAIT_REF_BAR;
21-
| ^^^^^^^^^^^^^^
22-
note: ...which requires caching mir of `<impl at $DIR/issue-24949-assoc-const-static-recursion-trait.rs:11:1: 11:28>::BAR` for CTFE...
23-
--> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:12:5
24-
|
25-
LL | const BAR: u32 = TRAIT_REF_BAR;
26-
| ^^^^^^^^^^^^^^
17+
= note: ...which requires const-evaluating + checking `<impl at $DIR/issue-24949-assoc-const-static-recursion-trait.rs:11:1: 11:28>::BAR`...
18+
= note: ...which requires caching mir of `<impl at $DIR/issue-24949-assoc-const-static-recursion-trait.rs:11:1: 11:28>::BAR` for CTFE...
2719
note: ...which requires elaborating drops for `<impl at $DIR/issue-24949-assoc-const-static-recursion-trait.rs:11:1: 11:28>::BAR`...
2820
--> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:12:22
2921
|
3022
LL | const BAR: u32 = TRAIT_REF_BAR;
3123
| ^^^^^^^^^^^^^
3224
= note: ...which again requires simplifying constant for the type system `TRAIT_REF_BAR`, completing the cycle
33-
note: cycle used when simplifying constant for the type system `TRAIT_REF_BAR`
34-
--> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:7:1
35-
|
36-
LL | const TRAIT_REF_BAR: u32 = <GlobalTraitRef>::BAR;
37-
| ^^^^^^^^^^^^^^^^^^^^^^^^
38-
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
25+
= note: cycle used when simplifying constant for the type system `TRAIT_REF_BAR`
26+
= note: for more information, see <https://rustc-dev-guide.rust-lang.org/overview.html#queries> and <https://rustc-dev-guide.rust-lang.org/query.html>
3927

4028
error: aborting due to 1 previous error
4129

tests/ui/associated-type-bounds/ambiguous-associated-type2.stderr

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@ LL | trait Baz: Foo + Bar<Self::Item> {}
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: ...which immediately requires computing the super traits of `Baz` with associated type name `Item` again
8-
note: cycle used when computing the super predicates of `Baz`
9-
--> $DIR/ambiguous-associated-type2.rs:7:1
10-
|
11-
LL | trait Baz: Foo + Bar<Self::Item> {}
12-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13-
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
8+
= note: cycle used when computing the super predicates of `Baz`
9+
= note: for more information, see <https://rustc-dev-guide.rust-lang.org/overview.html#queries> and <https://rustc-dev-guide.rust-lang.org/query.html>
1410

1511
error: aborting due to 1 previous error
1612

tests/ui/associated-type-bounds/implied-bounds-cycle.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ note: cycle used when computing normalized predicates of `B`
1010
|
1111
LL | trait B: A<T: B> {}
1212
| ^^^^^^^^^^^^^^^^
13-
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
13+
= note: for more information, see <https://rustc-dev-guide.rust-lang.org/overview.html#queries> and <https://rustc-dev-guide.rust-lang.org/query.html>
1414

1515
error: aborting due to 1 previous error
1616

0 commit comments

Comments
 (0)