Skip to content

Commit abab49f

Browse files
committed
Abort after printing infinite type errors.
Currently, `Representability::from_cycle_error` prints an "infinite size" error and then returns `Representability::Infinite`, which lets analysis continue. This commit changes it so it just aborts after printing the error. This has two benefits. First, the error messages are better. The error messages we get after continuing are mostly bad -- we usually get another cycle error, e.g. about drop checking or layout, which is not much use to the user, and then abort after that. The only exception is `issue-105231.rs` where a "conflicting implementations" error is now omitted, but there are three other errors before that one so it's no great loss. Second, it allows some simplifications: see the next commit.
1 parent 8ddf4ef commit abab49f

15 files changed

Lines changed: 20 additions & 124 deletions

compiler/rustc_query_impl/src/from_cycle_error.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,10 @@ impl<'tcx> FromCycleError<'tcx> for Representability {
117117
representable_ids.insert(def_id);
118118
}
119119
}
120+
// We used to continue here, but the cycle error printed next is actually less useful than
121+
// the error produced by `recursive_type_error`.
120122
let guar = recursive_type_error(tcx, item_and_field_ids, &representable_ids);
121-
Representability::Infinite(guar)
123+
guar.raise_fatal();
122124
}
123125
}
124126

tests/ui/enum-discriminant/issue-72554.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::collections::BTreeSet;
33
#[derive(Hash)]
44
pub enum ElemDerived {
55
//~^ ERROR recursive type `ElemDerived` has infinite size
6-
//~| ERROR cycle detected
76
A(ElemDerived)
87
}
98

tests/ui/enum-discriminant/issue-72554.stderr

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ error[E0072]: recursive type `ElemDerived` has infinite size
33
|
44
LL | pub enum ElemDerived {
55
| ^^^^^^^^^^^^^^^^^^^^
6-
...
6+
LL |
77
LL | A(ElemDerived)
88
| ----------- recursive without indirection
99
|
@@ -12,21 +12,6 @@ help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
1212
LL | A(Box<ElemDerived>)
1313
| ++++ +
1414

15-
error[E0391]: cycle detected when computing drop-check constraints for `ElemDerived`
16-
--> $DIR/issue-72554.rs:4:1
17-
|
18-
LL | pub enum ElemDerived {
19-
| ^^^^^^^^^^^^^^^^^^^^
20-
|
21-
= note: ...which immediately requires computing drop-check constraints for `ElemDerived` again
22-
note: cycle used when computing drop-check constraints for `Elem`
23-
--> $DIR/issue-72554.rs:11:1
24-
|
25-
LL | pub enum Elem {
26-
| ^^^^^^^^^^^^^
27-
= 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-
29-
error: aborting due to 2 previous errors
15+
error: aborting due to 1 previous error
3016

31-
Some errors have detailed explanations: E0072, E0391.
32-
For more information about an error, try `rustc --explain E0072`.
17+
For more information about this error, try `rustc --explain E0072`.

tests/ui/infinite/infinite-struct.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
struct Take(Take);
22
//~^ ERROR has infinite size
3-
//~| ERROR cycle
4-
//~| ERROR reached the recursion limit finding the struct tail for `Take`
53

64
// check that we don't hang trying to find the tail of a recursive struct (#79437)
75
fn foo() -> Take {

tests/ui/infinite/infinite-struct.stderr

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LL | struct Take(Box<Take>);
1010
| ++++ +
1111

1212
error[E0072]: recursive type `Foo` has infinite size
13-
--> $DIR/infinite-struct.rs:12:1
13+
--> $DIR/infinite-struct.rs:10:1
1414
|
1515
LL | struct Foo {
1616
| ^^^^^^^^^^
@@ -22,25 +22,6 @@ help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
2222
LL | x: Bar<Box<Foo>>,
2323
| ++++ +
2424

25-
error: reached the recursion limit finding the struct tail for `Take`
26-
--> $DIR/infinite-struct.rs:1:1
27-
|
28-
LL | struct Take(Take);
29-
| ^^^^^^^^^^^
30-
|
31-
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]`
32-
33-
error[E0391]: cycle detected when computing when `Take` needs drop
34-
--> $DIR/infinite-struct.rs:1:1
35-
|
36-
LL | struct Take(Take);
37-
| ^^^^^^^^^^^
38-
|
39-
= note: ...which immediately requires computing when `Take` needs drop again
40-
= note: cycle used when computing whether `Take` needs drop
41-
= 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
42-
43-
error: aborting due to 4 previous errors
25+
error: aborting due to 2 previous errors
4426

45-
Some errors have detailed explanations: E0072, E0391.
46-
For more information about an error, try `rustc --explain E0072`.
27+
For more information about this error, try `rustc --explain E0072`.
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
enum MList { Cons(isize, MList), Nil }
22
//~^ ERROR recursive type `MList` has infinite size
3-
//~| ERROR cycle
43

54
fn main() { let a = MList::Cons(10, MList::Cons(11, MList::Nil)); }

tests/ui/infinite/infinite-tag-type-recursion.stderr

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,6 @@ help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
99
LL | enum MList { Cons(isize, Box<MList>), Nil }
1010
| ++++ +
1111

12-
error[E0391]: cycle detected when computing when `MList` needs drop
13-
--> $DIR/infinite-tag-type-recursion.rs:1:1
14-
|
15-
LL | enum MList { Cons(isize, MList), Nil }
16-
| ^^^^^^^^^^
17-
|
18-
= note: ...which immediately requires computing when `MList` needs drop again
19-
= note: cycle used when computing whether `MList` needs drop
20-
= 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
21-
22-
error: aborting due to 2 previous errors
12+
error: aborting due to 1 previous error
2313

24-
Some errors have detailed explanations: E0072, E0391.
25-
For more information about an error, try `rustc --explain E0072`.
14+
For more information about this error, try `rustc --explain E0072`.
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
struct A<T>(std::sync::OnceLock<Self>);
22
//~^ ERROR recursive type `A` has infinite size
3-
//~| ERROR cycle detected when computing layout of `A<()>`
43

54
static B: A<()> = todo!();
6-
//~^ ERROR cycle occurred during layout computation
75

86
fn main() {}

tests/ui/query-system/query-cycle-printing-issue-151226.stderr

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,6 @@ help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
99
LL | struct A<T>(Box<std::sync::OnceLock<Self>>);
1010
| ++++ +
1111

12-
error[E0391]: cycle detected when computing layout of `A<()>`
13-
|
14-
= note: ...which requires computing layout of `std::sync::once_lock::OnceLock<A<()>>`...
15-
= note: ...which requires computing layout of `core::cell::UnsafeCell<core::mem::maybe_uninit::MaybeUninit<A<()>>>`...
16-
= note: ...which requires computing layout of `core::mem::maybe_uninit::MaybeUninit<A<()>>`...
17-
= note: ...which requires computing layout of `core::mem::manually_drop::ManuallyDrop<A<()>>`...
18-
= note: ...which requires computing layout of `core::mem::maybe_dangling::MaybeDangling<A<()>>`...
19-
= note: ...which again requires computing layout of `A<()>`, completing the cycle
20-
note: cycle used when checking that `B` is well-formed
21-
--> $DIR/query-cycle-printing-issue-151226.rs:5:1
22-
|
23-
LL | static B: A<()> = todo!();
24-
| ^^^^^^^^^^^^^^^
25-
= 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
26-
27-
error[E0080]: a cycle occurred during layout computation
28-
--> $DIR/query-cycle-printing-issue-151226.rs:5:1
29-
|
30-
LL | static B: A<()> = todo!();
31-
| ^^^^^^^^^^^^^^^ evaluation of `B` failed here
32-
33-
error: aborting due to 3 previous errors
12+
error: aborting due to 1 previous error
3413

35-
Some errors have detailed explanations: E0072, E0080, E0391.
36-
For more information about an error, try `rustc --explain E0072`.
14+
For more information about this error, try `rustc --explain E0072`.

tests/ui/structs-enums/enum-rec/issue-17431-6.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::cell::UnsafeCell;
22

33
enum Foo { X(UnsafeCell<Option<Foo>>) }
44
//~^ ERROR recursive type `Foo` has infinite size
5-
//~| ERROR cycle detected
65

76
impl Foo { fn bar(self) {} }
87

0 commit comments

Comments
 (0)