nikomatsakis / babysteps

Babysteps blog
https://smallcultfollowing.com/babysteps/
31 stars 22 forks source link

Inconsistent struct field names in "Implied bounds and perfect derive" #7

Open ericseppanen opened 2 years ago

ericseppanen commented 2 years ago

List has fields data and next, but in the impl Clone it says value and next.

#[derive(Clone)]
struct List<T> {
    data: Rc<T>,
    next: Option<Rc<List<T>>>,
}

impl<T> Deref for List<T> {
    type Target = T;

    fn deref(&self) -> &T { &self.data }
}

Currently, derive is going to generate an impl that requires T: Clone, like this…


impl<T> Clone for List<T> 
where
    T: Clone,
{
    fn clone(&self) {
        List {
            value: self.value.clone(),
            next: self.next.clone(),
        }
    }
}
nikomatsakis commented 2 years ago

Thanks