nikis05 / derive-visitor

MIT License
20 stars 6 forks source link

Impl `Drive` on `&T`? #21

Open Nadrieril opened 1 month ago

Nadrieril commented 1 month ago

I was trying something like:

#[derive(Drive)]
struct MyType { ... }
let x: Option<&MyType> = ...;
x.drive(..)

However this does not work because:

429 |                         body.drive(&mut graph);
    |                              ^^^^^ method cannot be called on `Option<&Body>` due to unsatisfied trait bounds
   --> /rustc/65ea825f4021eaf77f1b25139969712d65b435a4/library/core/src/option.rs:563:1
    |
    = note: doesn't satisfy `std::option::Option<&gast::Body>: Drive`
    |
    = note: the following trait bounds were not satisfied:
            `&'a &gast::Body: derive_visitor::DerefAndDrive`
            which is required by `std::option::Option<&gast::Body>: Drive`

Here's my question: why not implement &T: Drive for all T: Drive and remove DerefAndDrive? Is there a specific reason for this approach?