Skip to main content

expand_simple_derive

Function expand_simple_derive 

Source
fn expand_simple_derive(
    db: &dyn SourceDatabase,
    invoc_span: Span,
    tt: &TopSubtree,
    trait_path: TopSubtree,
    allow_unions: bool,
    make_trait_body: impl FnOnce(&BasicAdtInfo) -> TopSubtree,
) -> ExpandResult<TopSubtree>
Expand description

Given that we are deriving a trait DerivedTrait for a type like:

struct Struct<'a, ..., 'z, A, B: DeclaredTrait, C, ..., Z> where C: WhereTrait {
    a: A,
    b: B::Item,
    b1: <B as DeclaredTrait>::Item,
    c1: <C as WhereTrait>::Item,
    c2: Option<<C as WhereTrait>::Item>,
    ...
}

create an impl like:

impl<'a, ..., 'z, A, B: DeclaredTrait, C, ... Z> where
    C:                       WhereTrait,
    A: DerivedTrait + B1 + ... + BN,
    B: DerivedTrait + B1 + ... + BN,
    C: DerivedTrait + B1 + ... + BN,
    B::Item:                 DerivedTrait + B1 + ... + BN,
    <C as WhereTrait>::Item: DerivedTrait + B1 + ... + BN,
    ...
{
    ...
}

where B1, …, BN are the bounds given by bounds_paths. Z is a phantom type, and therefore does not get bound by the derived trait.