Why does “fail to skip private type” apply only to structures, not enums?

Consider the following code

struct Node {
    elem: i32,
    next: List,
}

pub enum List {
    Empty,
    More(Box<Node>),
}

This will make the compiler complain:

error[E0446]: private type `Node` in public interface
 --> src/main.rs:8:10
  |
8 |     More(Box<Node>),
  |          ^^^^^^^^^^ can't leak private type

But this code will not result in an error, even if it Linkis private:

pub struct List {
    head: Link,
}

enum Link {
    Empty,
    More(Box<Node>),
}

struct Node {
    elem: i32,
    next: Link,
}

What is the reason for this mismatch? Why does private enumeration not cause an error while the private structure is being executed?

+4
source share
1 answer

List . , More . More , Node . , , , , , , , .

List . head . , , Link , head .

+9

Source: https://habr.com/ru/post/1687273/


All Articles