casper-network / casper-network/datasize-rs

derive(DataSize) fails to compile on recursive data structures

Open
#9 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
19
Forks
13
PR merge metrics
No merged PRs in 30d

Description

enum example:

```rust
#[derive(DataSize)]
enum Expression {
Constant(u32),
Negation(Box),
// ...
}
```

Output on rustc 1.66.0-nightly (0ca356586 2022-10-06), almost the same as on 1.64.0:

```rust
error[E0275]: overflow evaluating the requirement `Expression: DataSize`
--> src/lib.rs:3:10
|
3 | #[derive(DataSize)]
| ^^^^^^^^
|
= note: required because of the requirements on the impl of `DataSize` for `Box`
= help: see issue #48214
= note: this error originates in the derive macro `DataSize` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0275`.
```

struct example:

```rust
use datasize::DataSize;

#[derive(DataSize)]
struct BinaryTree {
data: u32, // or something
left: Option>,
right: Option>,
}
```
```rust
error[E0391]: cycle detected when elaborating drops for `::IS_DYNAMIC`
--> src/lib.rs:3:10
|
3 | #[derive(DataSize)]
| ^^^^^^^^
|
note: ...which requires const-evaluating + checking ` as datasize::DataSize>::IS_DYNAMIC`...
--> /Users/simon/.cargo/registry/src/github.com-1ecc6299db9ec823/datasize-0.2.10/src/lib.rs:423:5
|
423 | const IS_DYNAMIC: bool = (T::IS_DYNAMIC || T::STATIC_HEAP_SIZE > 0);
| ^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires const-evaluating + checking ` as datasize::DataSize>::IS_DYNAMIC`...
--> /Users/simon/.cargo/registry/src/github.com-1ecc6299db9ec823/datasize-0.2.10/src/lib.rs:423:5
|
423 | const IS_DYNAMIC: bool = (T::IS_DYNAMIC || T::STATIC_HEAP_SIZE > 0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires const-evaluating + checking `datasize::std::>::IS_DYNAMIC`...
--> /Users/simon/.cargo/registry/src/github.com-1ecc6299db9ec823/datasize-0.2.10/src/std.rs:24:5
|
24 | const IS_DYNAMIC: bool = T::IS_DYNAMIC;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires const-evaluating + checking `::IS_DYNAMIC`...
--> src/lib.rs:3:10
|
3 | #[derive(DataSize)]
| ^^^^^^^^
note: ...which requires caching mir of `::IS_DYNAMIC` for CTFE...
--> src/lib.rs:3:10
|
3 | #[derive(DataSize)]
| ^^^^^^^^
= note: ...which again requires elaborating drops for `::IS_DYNAMIC`, completing the cycle
= note: cycle used when running analysis passes on this crate
= note: this error originates in the derive macro `DataSize` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0391`.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.