Improve errors for recursive type aliases

This commit is contained in:
Noah Lev 2021-07-20 18:06:39 -07:00
parent d3e2578c31
commit 2f48bfa88c
14 changed files with 38 additions and 23 deletions

View File

@ -116,7 +116,18 @@ rustc_queries! {
/// Records the type of every item.
query type_of(key: DefId) -> Ty<'tcx> {
desc { |tcx| "computing type of `{}`", tcx.def_path_str(key) }
desc { |tcx|
"{action} `{path}`",
action = {
use rustc_hir::def::DefKind;
match tcx.def_kind(key) {
DefKind::TyAlias => "expanding type alias",
DefKind::TraitAlias => "expanding trait alias",
_ => "computing type of",
}
},
path = tcx.def_path_str(key),
}
cache_on_disk_if { key.is_local() }
}

View File

@ -591,10 +591,14 @@ pub(crate) fn report_cycle<'a>(
err.span_note(span, &format!("...which requires {}...", query.description));
}
err.note(&format!(
"...which again requires {}, completing the cycle",
stack[0].query.description
));
if stack.len() == 1 {
err.note(&format!("...which immediately requires {} again", stack[0].query.description));
} else {
err.note(&format!(
"...which again requires {}, completing the cycle",
stack[0].query.description
));
}
if let Some((span, query)) = usage {
err.span_note(fix_span(span, &query), &format!("cycle used when {}", query.description));

View File

@ -4,7 +4,7 @@ error[E0391]: cycle detected when computing the super traits of `Baz` with assoc
LL | trait Baz: Foo + Bar<Self::Item> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: ...which again requires computing the super traits of `Baz` with associated type name `Item`, completing the cycle
= note: ...which immediately requires computing the super traits of `Baz` with associated type name `Item` again
note: cycle used when computing the super traits of `Baz`
--> $DIR/ambiguous-associated-type2.rs:7:1
|

View File

@ -14,7 +14,7 @@ error[E0391]: cycle detected when building specialization graph of trait `Trait`
LL | trait Trait<T> { type Assoc; }
| ^^^^^^^^^^^^^^
|
= note: ...which again requires building specialization graph of trait `Trait`, completing the cycle
= note: ...which immediately requires building specialization graph of trait `Trait` again
note: cycle used when coherence checking all impls of trait `Trait`
--> $DIR/coherence-inherited-assoc-ty-cycle-err.rs:9:1
|

View File

@ -4,7 +4,7 @@ error[E0391]: cycle detected when computing type of `Foo::X`
LL | trait Foo<X = Box<dyn Foo>> {
| ^^^
|
= note: ...which again requires computing type of `Foo::X`, completing the cycle
= note: ...which immediately requires computing type of `Foo::X` again
note: cycle used when collecting item types in top-level module
--> $DIR/cycle-trait-default-type-trait.rs:4:1
|
@ -17,7 +17,7 @@ error[E0391]: cycle detected when computing type of `Foo::X`
LL | trait Foo<X = Box<dyn Foo>> {
| ^^^
|
= note: ...which again requires computing type of `Foo::X`, completing the cycle
= note: ...which immediately requires computing type of `Foo::X` again
note: cycle used when collecting item types in top-level module
--> $DIR/cycle-trait-default-type-trait.rs:4:1
|

View File

@ -18,7 +18,7 @@ error[E0391]: cycle detected when computing drop-check constraints for `Take`
LL | struct Take(Take);
| ^^^^^^^^^^^^^^^^^^
|
= note: ...which again requires computing drop-check constraints for `Take`, completing the cycle
= note: ...which immediately requires computing drop-check constraints for `Take` again
= note: cycle used when computing dropck types for `Canonical { max_universe: U0, variables: [], value: ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: UserFacing }, value: Take } }`
error: aborting due to 2 previous errors

View File

@ -17,7 +17,7 @@ error[E0391]: cycle detected when computing drop-check constraints for `MList`
LL | enum MList { Cons(isize, MList), Nil }
| ^^^^^^^^^^
|
= note: ...which again requires computing drop-check constraints for `MList`, completing the cycle
= note: ...which immediately requires computing drop-check constraints for `MList` again
= note: cycle used when computing dropck types for `Canonical { max_universe: U0, variables: [], value: ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: UserFacing }, value: MList } }`
error: aborting due to 2 previous errors

View File

@ -1,10 +1,10 @@
error[E0391]: cycle detected when computing type of `X`
error[E0391]: cycle detected when expanding type alias `X`
--> $DIR/infinite-vec-type-recursion.rs:1:14
|
LL | type X = Vec<X>;
| ^
|
= note: ...which again requires computing type of `X`, completing the cycle
= note: ...which immediately requires expanding type alias `X` again
note: cycle used when collecting item types in top-level module
--> $DIR/infinite-vec-type-recursion.rs:1:1
|

View File

@ -6,7 +6,7 @@ LL | |
LL | | {}
| |__^
|
= note: ...which again requires computing the super traits of `T` with associated type name `Item`, completing the cycle
= note: ...which immediately requires computing the super traits of `T` with associated type name `Item` again
note: cycle used when computing the super traits of `T`
--> $DIR/issue-20772.rs:1:1
|

View File

@ -4,7 +4,7 @@ error[E0391]: cycle detected when computing the super traits of `Processor` with
LL | pub trait Processor: Subscriber<Input = Self::Input> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: ...which again requires computing the super traits of `Processor` with associated type name `Input`, completing the cycle
= note: ...which immediately requires computing the super traits of `Processor` with associated type name `Input` again
note: cycle used when computing the super traits of `Processor`
--> $DIR/issue-20825.rs:5:1
|

View File

@ -4,7 +4,7 @@ error[E0391]: cycle detected when computing the bounds for type parameter `T`
LL | fn foo<T: Trait<A = T::B>>() { }
| ^^^^
|
= note: ...which again requires computing the bounds for type parameter `T`, completing the cycle
= note: ...which immediately requires computing the bounds for type parameter `T` again
note: cycle used when computing explicit predicates of `foo`
--> $DIR/issue-21177.rs:6:21
|

View File

@ -4,7 +4,7 @@ error[E0391]: cycle detected when computing type of `Foo::T`
LL | pub struct Foo<T = Box<Trait<DefaultFoo>>>;
| ^^^^^^^^^^
|
note: ...which requires computing type of `DefaultFoo`...
note: ...which requires expanding type alias `DefaultFoo`...
--> $DIR/issue-34373.rs:8:19
|
LL | type DefaultFoo = Foo;

View File

@ -4,7 +4,7 @@ error[E0391]: cycle detected when computing type of `<impl at $DIR/issue-23305.r
LL | impl dyn ToNbt<Self> {}
| ^^^^
|
= note: ...which again requires computing type of `<impl at $DIR/issue-23305.rs:5:1: 5:24>`, completing the cycle
= note: ...which immediately requires computing type of `<impl at $DIR/issue-23305.rs:5:1: 5:24>` again
note: cycle used when collecting item types in top-level module
--> $DIR/issue-23305.rs:1:1
|

View File

@ -4,7 +4,7 @@ error[E0391]: cycle detected when computing type of `<impl at $DIR/resolve-self-
LL | impl Tr for Self {}
| ^^^^
|
= note: ...which again requires computing type of `<impl at $DIR/resolve-self-in-impl.rs:14:1: 14:20>`, completing the cycle
= note: ...which immediately requires computing type of `<impl at $DIR/resolve-self-in-impl.rs:14:1: 14:20>` again
note: cycle used when collecting item types in top-level module
--> $DIR/resolve-self-in-impl.rs:1:1
|
@ -23,7 +23,7 @@ error[E0391]: cycle detected when computing type of `<impl at $DIR/resolve-self-
LL | impl Tr for S<Self> {}
| ^^^^
|
= note: ...which again requires computing type of `<impl at $DIR/resolve-self-in-impl.rs:15:1: 15:23>`, completing the cycle
= note: ...which immediately requires computing type of `<impl at $DIR/resolve-self-in-impl.rs:15:1: 15:23>` again
note: cycle used when collecting item types in top-level module
--> $DIR/resolve-self-in-impl.rs:1:1
|
@ -42,7 +42,7 @@ error[E0391]: cycle detected when computing type of `<impl at $DIR/resolve-self-
LL | impl Self {}
| ^^^^
|
= note: ...which again requires computing type of `<impl at $DIR/resolve-self-in-impl.rs:16:1: 16:13>`, completing the cycle
= note: ...which immediately requires computing type of `<impl at $DIR/resolve-self-in-impl.rs:16:1: 16:13>` again
note: cycle used when collecting item types in top-level module
--> $DIR/resolve-self-in-impl.rs:1:1
|
@ -61,7 +61,7 @@ error[E0391]: cycle detected when computing type of `<impl at $DIR/resolve-self-
LL | impl S<Self> {}
| ^^^^
|
= note: ...which again requires computing type of `<impl at $DIR/resolve-self-in-impl.rs:17:1: 17:16>`, completing the cycle
= note: ...which immediately requires computing type of `<impl at $DIR/resolve-self-in-impl.rs:17:1: 17:16>` again
note: cycle used when collecting item types in top-level module
--> $DIR/resolve-self-in-impl.rs:1:1
|
@ -80,7 +80,7 @@ error[E0391]: cycle detected when computing trait implemented by `<impl at $DIR/
LL | impl Tr<Self::A> for S {}
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: ...which again requires computing trait implemented by `<impl at $DIR/resolve-self-in-impl.rs:18:1: 18:26>`, completing the cycle
= note: ...which immediately requires computing trait implemented by `<impl at $DIR/resolve-self-in-impl.rs:18:1: 18:26>` again
note: cycle used when collecting item types in top-level module
--> $DIR/resolve-self-in-impl.rs:1:1
|