Correct bounds processing for field types
- Dominant language
- Rust
- Stars
- 3.4k
- Forks
- 374
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 2
Description
The `derive(HeapSize)` example [recursively calls `heap_size_of_children` on fields](https://github.com/dtolnay/syn/blob/master/examples/heapsize/heapsize_derive/src/lib.rs#L64), but without adding the correct bound to the fields (`f.ty: HeapSize`).
Instead, [trait bounds are added to generic parameters](https://github.com/dtolnay/syn/blob/master/examples/heapsize/heapsize_derive/src/lib.rs#L39).
Why? I guess this is just not possible with macros yet, but these generic bounds are incorrect and confusing. Consider:
```rust
#[derive(HeapSize)]
struct MyStruct<'a, X: 'a> {
a: u32, // whoops, u32 does not support HeapSize and we did not check that
_b: &'a X, // who cares what X is; it doesn't affect us
}
```
I'm primarily asking because I'm trying to do something similar and can't see a correct way of implementing bounds. For generic parameters we should add something like `#(field.ty.path): #bound` to the `where` clauses; for non-generic parameters we have three options: (a) do the same (even though non generic), (b) check directly and fail if not met, (c) add meta-data specifying the constraint to the token stream.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.