Skip to content

Commit

Permalink
Report cycle error using 'deepest' obligation in the cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron1011 committed Sep 2, 2021
1 parent f2d9ee9 commit 611191f
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {

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

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

fn report_selection_error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ where
use std::convert::TryFrom;
<[T; N.get()]>::try_from(())
//~^ error: the trait bound
//~^^ error: mismatched types
//~| error: the trait bound
//~| error: mismatched types
}

fn main() {}
2 changes: 1 addition & 1 deletion src/test/ui/traits/cycle-cache-err-60010.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct Runtime<DB: Database> {
}
struct SalsaStorage {
_parse: <ParseQuery as Query<RootDatabase>>::Data,
//~^ ERROR overflow evaluating the requirement `RootDatabase: SourceDatabase`
//~^ ERROR overflow
}

impl Database for RootDatabase {
Expand Down
20 changes: 19 additions & 1 deletion src/test/ui/traits/cycle-cache-err-60010.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
error[E0275]: overflow evaluating the requirement `RootDatabase: SourceDatabase`
error[E0275]: overflow evaluating the requirement `SalsaStorage: RefUnwindSafe`
--> $DIR/cycle-cache-err-60010.rs:27:13
|
LL | _parse: <ParseQuery as Query<RootDatabase>>::Data,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: required because it appears within the type `*const SalsaStorage`
= note: required because it appears within the type `Unique<SalsaStorage>`
= note: required because it appears within the type `Box<SalsaStorage>`
note: required because it appears within the type `Runtime<RootDatabase>`
--> $DIR/cycle-cache-err-60010.rs:23:8
|
LL | struct Runtime<DB: Database> {
| ^^^^^^^
note: required because it appears within the type `RootDatabase`
--> $DIR/cycle-cache-err-60010.rs:20:8
|
LL | struct RootDatabase {
| ^^^^^^^^^^^^
note: required because of the requirements on the impl of `SourceDatabase` for `RootDatabase`
--> $DIR/cycle-cache-err-60010.rs:44:9
|
LL | impl<T> SourceDatabase for T
| ^^^^^^^^^^^^^^ ^
note: required because of the requirements on the impl of `Query<RootDatabase>` for `ParseQuery`
--> $DIR/cycle-cache-err-60010.rs:37:10
|
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/traits/inductive-overflow/lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ impl<'a> Y for C<'a> {
struct C<'a>(&'a ());
struct X<T: Y>(T::P);

impl<T: NotAuto> NotAuto for Box<T> {}
impl<T: Y> NotAuto for X<T> where T::P: NotAuto {} //~ NOTE: required
impl<T: NotAuto> NotAuto for Box<T> {} //~ NOTE: required
impl<T: Y> NotAuto for X<T> where T::P: NotAuto {}
impl<'a> NotAuto for C<'a> {}

fn is_send<S: NotAuto>() {}
Expand All @@ -26,6 +26,6 @@ fn main() {
// Should only be a few notes.
is_send::<X<C<'static>>>();
//~^ ERROR overflow evaluating
//~| 2 redundant requirements hidden
//~| 3 redundant requirements hidden
//~| required because of
}
12 changes: 6 additions & 6 deletions src/test/ui/traits/inductive-overflow/lifetime.stderr
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
error[E0275]: overflow evaluating the requirement `Box<X<C<'_>>>: NotAuto`
error[E0275]: overflow evaluating the requirement `X<C<'_>>: NotAuto`
--> $DIR/lifetime.rs:27:5
|
LL | is_send::<X<C<'static>>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
note: required because of the requirements on the impl of `NotAuto` for `X<C<'_>>`
--> $DIR/lifetime.rs:19:12
note: required because of the requirements on the impl of `NotAuto` for `Box<X<C<'_>>>`
--> $DIR/lifetime.rs:18:18
|
LL | impl<T: Y> NotAuto for X<T> where T::P: NotAuto {}
| ^^^^^^^ ^^^^
= note: 2 redundant requirements hidden
LL | impl<T: NotAuto> NotAuto for Box<T> {}
| ^^^^^^^ ^^^^^^
= note: 3 redundant requirements hidden
= note: required because of the requirements on the impl of `NotAuto` for `X<C<'static>>`
note: required by a bound in `is_send`
--> $DIR/lifetime.rs:22:15
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/traits/inductive-overflow/simultaneous.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0275]: overflow evaluating the requirement `{integer}: Tweedledee`
error[E0275]: overflow evaluating the requirement `{integer}: Tweedledum`
--> $DIR/simultaneous.rs:18:5
|
LL | is_ee(4);
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/type-alias-impl-trait/auto-trait-leakage3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ LL | type Foo = impl std::fmt::Debug;
| ^^^^^^^^^^^^^^^^^^^^
|
note: ...which requires type-checking `m::bar`...
--> $DIR/auto-trait-leakage3.rs:14:5
--> $DIR/auto-trait-leakage3.rs:15:9
|
LL | pub fn bar() {
| ^^^^^^^^^^^^
LL | is_send(foo());
| ^^^^^^^
= note: ...which requires evaluating trait selection obligation `impl std::fmt::Debug: std::marker::Send`...
= note: ...which again requires computing type of `m::Foo::{opaque#0}`, completing the cycle
note: cycle used when checking item types in module `m`
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/type-alias-impl-trait/inference-cycle.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ LL | type Foo = impl std::fmt::Debug;
| ^^^^^^^^^^^^^^^^^^^^
|
note: ...which requires type-checking `m::bar`...
--> $DIR/inference-cycle.rs:14:5
--> $DIR/inference-cycle.rs:15:9
|
LL | pub fn bar() {
| ^^^^^^^^^^^^
LL | is_send(foo()); // Today: error
| ^^^^^^^
= note: ...which requires evaluating trait selection obligation `impl std::fmt::Debug: std::marker::Send`...
= note: ...which again requires computing type of `m::Foo::{opaque#0}`, completing the cycle
note: cycle used when checking item types in module `m`
Expand Down

0 comments on commit 611191f

Please sign in to comment.