Skip to content

Commit fe52882

Browse files
committed
docs: add long error explanation for error E0320
1 parent 63b3bac commit fe52882

6 files changed

+32
-1
lines changed

compiler/rustc_error_codes/src/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ E0311: include_str!("./error_codes/E0311.md"),
163163
E0312: include_str!("./error_codes/E0312.md"),
164164
E0316: include_str!("./error_codes/E0316.md"),
165165
E0317: include_str!("./error_codes/E0317.md"),
166+
E0320: include_str!("./error_codes/E0320.md"),
166167
E0321: include_str!("./error_codes/E0321.md"),
167168
E0322: include_str!("./error_codes/E0322.md"),
168169
E0323: include_str!("./error_codes/E0323.md"),
@@ -575,7 +576,6 @@ E0791: include_str!("./error_codes/E0791.md"),
575576
// E0314, // closure outlives stack frame
576577
// E0315, // cannot invoke closure outside of its lifetime
577578
// E0319, // trait impls for defaulted traits allowed just for structs/enums
578-
E0320, // recursive overflow during dropck
579579
// E0372, // coherence not object safe
580580
E0377, // the trait `CoerceUnsized` may only be implemented for a coercion
581581
// between structures with the same definition
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Recursion limit reached while creating drop-check rules.
2+
3+
Example of erroneous code:
4+
5+
```compile_fail,E0320
6+
enum A<T> {
7+
B,
8+
C(T, Box<A<(T, T)>>)
9+
}
10+
11+
fn foo<T>() {
12+
A::<T>::B; // error: overflow while adding drop-check rules for A<T>
13+
}
14+
```
15+
16+
The Rust compiler must be able to reason about how a type is [`Drop`]ped, and
17+
by extension the types of its fields, to be able to generate the glue to
18+
properly drop a value. The code example above shows a type where this inference
19+
is impossible because it is recursive. Note that this is *not* the same as
20+
[E0072](E0072.html), where a type has an infinite size; the type here has a
21+
finite size but any attempt to `Drop` it would recurse infinitely. For more
22+
information, read [the `Drop` docs](../std/ops/trait.Drop.html).
23+
24+
It is not possible to define a type with recursive drop-check rules. All such
25+
recursion must be removed.
26+
27+
[`Drop`]: ../std/ops/trait.Drop.html

src/test/ui/dropck/dropck_no_diverge_on_nonregular_1.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ LL | let ft =
88

99
error: aborting due to previous error
1010

11+
For more information about this error, try `rustc --explain E0320`.

src/test/ui/dropck/dropck_no_diverge_on_nonregular_2.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ LL | let ft =
88

99
error: aborting due to previous error
1010

11+
For more information about this error, try `rustc --explain E0320`.

src/test/ui/dropck/dropck_no_diverge_on_nonregular_3.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ LL | Some(Wrapper::Simple::<u32>);
1616

1717
error: aborting due to 2 previous errors
1818

19+
For more information about this error, try `rustc --explain E0320`.

src/test/ui/recursion/issue-38591-non-regular-dropck-recursion.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ LL | fn f(x: S<u32>) {}
88

99
error: aborting due to previous error
1010

11+
For more information about this error, try `rustc --explain E0320`.

0 commit comments

Comments
 (0)