Skip to content

Commit d5215f5

Browse files
committed
sized-cycle-note
1 parent abf037a commit d5215f5

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
struct Baz { q: Option<Foo> }
2-
//~^ ERROR recursive types `Baz` and `Foo` have infinite size
3-
struct Foo { q: Option<Baz> }
1+
//! Check for compilation errors when recursive types are defined in a way
2+
//! that leads to an infinite size.
43
5-
impl Foo { fn bar(&self) {} }
4+
struct Baz {
5+
//~^ ERROR recursive types `Baz` and `Foo` have infinite size
6+
q: Option<Foo>,
7+
}
8+
struct Foo {
9+
q: Option<Baz>,
10+
}
11+
12+
impl Foo {
13+
fn bar(&self) {}
14+
}
615

716
fn main() {}

tests/ui/sized/recursive-type-infinite-size.stderr

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
error[E0072]: recursive types `Baz` and `Foo` have infinite size
2-
--> $DIR/sized-cycle-note.rs:1:1
2+
--> $DIR/recursive-type-infinite-size.rs:4:1
33
|
4-
LL | struct Baz { q: Option<Foo> }
5-
| ^^^^^^^^^^ --- recursive without indirection
4+
LL | struct Baz {
5+
| ^^^^^^^^^^
66
LL |
7-
LL | struct Foo { q: Option<Baz> }
8-
| ^^^^^^^^^^ --- recursive without indirection
7+
LL | q: Option<Foo>,
8+
| --- recursive without indirection
9+
LL | }
10+
LL | struct Foo {
11+
| ^^^^^^^^^^
12+
LL | q: Option<Baz>,
13+
| --- recursive without indirection
914
|
1015
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
1116
|
12-
LL ~ struct Baz { q: Option<Box<Foo>> }
13-
LL |
14-
LL ~ struct Foo { q: Option<Box<Baz>> }
17+
LL ~ q: Option<Box<Foo>>,
18+
LL | }
19+
LL | struct Foo {
20+
LL ~ q: Option<Box<Baz>>,
1521
|
1622

1723
error: aborting due to 1 previous error

0 commit comments

Comments
 (0)