Skip to content

Commit 611191f

Browse files
committed
Report cycle error using 'deepest' obligation in the cycle
1 parent f2d9ee9 commit 611191f

File tree

9 files changed

+41
-20
lines changed

9 files changed

+41
-20
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
224224

225225
debug!("report_overflow_error_cycle: cycle={:?}", cycle);
226226

227-
self.report_overflow_error(&cycle[0], false);
227+
// The 'deepest' obligation is most likely to have a useful
228+
// cause 'backtrace'
229+
self.report_overflow_error(cycle.iter().max_by_key(|p| p.recursion_depth).unwrap(), false);
228230
}
229231

230232
fn report_selection_error(

src/test/incremental/const-generics/hash-tyvid-regression-1.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ where
99
use std::convert::TryFrom;
1010
<[T; N.get()]>::try_from(())
1111
//~^ error: the trait bound
12-
//~^^ error: mismatched types
12+
//~| error: the trait bound
13+
//~| error: mismatched types
1314
}
1415

1516
fn main() {}

src/test/ui/traits/cycle-cache-err-60010.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct Runtime<DB: Database> {
2525
}
2626
struct SalsaStorage {
2727
_parse: <ParseQuery as Query<RootDatabase>>::Data,
28-
//~^ ERROR overflow evaluating the requirement `RootDatabase: SourceDatabase`
28+
//~^ ERROR overflow
2929
}
3030

3131
impl Database for RootDatabase {

src/test/ui/traits/cycle-cache-err-60010.stderr

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
1-
error[E0275]: overflow evaluating the requirement `RootDatabase: SourceDatabase`
1+
error[E0275]: overflow evaluating the requirement `SalsaStorage: RefUnwindSafe`
22
--> $DIR/cycle-cache-err-60010.rs:27:13
33
|
44
LL | _parse: <ParseQuery as Query<RootDatabase>>::Data,
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7+
= note: required because it appears within the type `*const SalsaStorage`
8+
= note: required because it appears within the type `Unique<SalsaStorage>`
9+
= note: required because it appears within the type `Box<SalsaStorage>`
10+
note: required because it appears within the type `Runtime<RootDatabase>`
11+
--> $DIR/cycle-cache-err-60010.rs:23:8
12+
|
13+
LL | struct Runtime<DB: Database> {
14+
| ^^^^^^^
15+
note: required because it appears within the type `RootDatabase`
16+
--> $DIR/cycle-cache-err-60010.rs:20:8
17+
|
18+
LL | struct RootDatabase {
19+
| ^^^^^^^^^^^^
20+
note: required because of the requirements on the impl of `SourceDatabase` for `RootDatabase`
21+
--> $DIR/cycle-cache-err-60010.rs:44:9
22+
|
23+
LL | impl<T> SourceDatabase for T
24+
| ^^^^^^^^^^^^^^ ^
725
note: required because of the requirements on the impl of `Query<RootDatabase>` for `ParseQuery`
826
--> $DIR/cycle-cache-err-60010.rs:37:10
927
|

src/test/ui/traits/inductive-overflow/lifetime.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ impl<'a> Y for C<'a> {
1515
struct C<'a>(&'a ());
1616
struct X<T: Y>(T::P);
1717

18-
impl<T: NotAuto> NotAuto for Box<T> {}
19-
impl<T: Y> NotAuto for X<T> where T::P: NotAuto {} //~ NOTE: required
18+
impl<T: NotAuto> NotAuto for Box<T> {} //~ NOTE: required
19+
impl<T: Y> NotAuto for X<T> where T::P: NotAuto {}
2020
impl<'a> NotAuto for C<'a> {}
2121

2222
fn is_send<S: NotAuto>() {}
@@ -26,6 +26,6 @@ fn main() {
2626
// Should only be a few notes.
2727
is_send::<X<C<'static>>>();
2828
//~^ ERROR overflow evaluating
29-
//~| 2 redundant requirements hidden
29+
//~| 3 redundant requirements hidden
3030
//~| required because of
3131
}

src/test/ui/traits/inductive-overflow/lifetime.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
error[E0275]: overflow evaluating the requirement `Box<X<C<'_>>>: NotAuto`
1+
error[E0275]: overflow evaluating the requirement `X<C<'_>>: NotAuto`
22
--> $DIR/lifetime.rs:27:5
33
|
44
LL | is_send::<X<C<'static>>>();
55
| ^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
note: required because of the requirements on the impl of `NotAuto` for `X<C<'_>>`
8-
--> $DIR/lifetime.rs:19:12
7+
note: required because of the requirements on the impl of `NotAuto` for `Box<X<C<'_>>>`
8+
--> $DIR/lifetime.rs:18:18
99
|
10-
LL | impl<T: Y> NotAuto for X<T> where T::P: NotAuto {}
11-
| ^^^^^^^ ^^^^
12-
= note: 2 redundant requirements hidden
10+
LL | impl<T: NotAuto> NotAuto for Box<T> {}
11+
| ^^^^^^^ ^^^^^^
12+
= note: 3 redundant requirements hidden
1313
= note: required because of the requirements on the impl of `NotAuto` for `X<C<'static>>`
1414
note: required by a bound in `is_send`
1515
--> $DIR/lifetime.rs:22:15

src/test/ui/traits/inductive-overflow/simultaneous.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0275]: overflow evaluating the requirement `{integer}: Tweedledee`
1+
error[E0275]: overflow evaluating the requirement `{integer}: Tweedledum`
22
--> $DIR/simultaneous.rs:18:5
33
|
44
LL | is_ee(4);

src/test/ui/type-alias-impl-trait/auto-trait-leakage3.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ LL | type Foo = impl std::fmt::Debug;
55
| ^^^^^^^^^^^^^^^^^^^^
66
|
77
note: ...which requires type-checking `m::bar`...
8-
--> $DIR/auto-trait-leakage3.rs:14:5
8+
--> $DIR/auto-trait-leakage3.rs:15:9
99
|
10-
LL | pub fn bar() {
11-
| ^^^^^^^^^^^^
10+
LL | is_send(foo());
11+
| ^^^^^^^
1212
= note: ...which requires evaluating trait selection obligation `impl std::fmt::Debug: std::marker::Send`...
1313
= note: ...which again requires computing type of `m::Foo::{opaque#0}`, completing the cycle
1414
note: cycle used when checking item types in module `m`

src/test/ui/type-alias-impl-trait/inference-cycle.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ LL | type Foo = impl std::fmt::Debug;
55
| ^^^^^^^^^^^^^^^^^^^^
66
|
77
note: ...which requires type-checking `m::bar`...
8-
--> $DIR/inference-cycle.rs:14:5
8+
--> $DIR/inference-cycle.rs:15:9
99
|
10-
LL | pub fn bar() {
11-
| ^^^^^^^^^^^^
10+
LL | is_send(foo()); // Today: error
11+
| ^^^^^^^
1212
= note: ...which requires evaluating trait selection obligation `impl std::fmt::Debug: std::marker::Send`...
1313
= note: ...which again requires computing type of `m::Foo::{opaque#0}`, completing the cycle
1414
note: cycle used when checking item types in module `m`

0 commit comments

Comments
 (0)