1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use syn::{GenericArgument, Lifetime, PathArguments, Type};

pub(crate) fn populate_static_lifetimes(ty: &mut Type) {
    match ty {
        #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
        Type::Array(ty) => populate_static_lifetimes(&mut ty.elem),
        Type::Group(ty) => populate_static_lifetimes(&mut ty.elem),
        Type::Paren(ty) => populate_static_lifetimes(&mut ty.elem),
        Type::Path(ty) => {
            if let Some(qself) = &mut ty.qself {
                populate_static_lifetimes(&mut qself.ty);
            }
            for segment in &mut ty.path.segments {
                if let PathArguments::AngleBracketed(segment) = &mut segment.arguments {
                    for arg in &mut segment.args {
                        if let GenericArgument::Type(arg) = arg {
                            populate_static_lifetimes(arg);
                        }
                    }
                }
            }
        }
        Type::Ptr(ty) => populate_static_lifetimes(&mut ty.elem),
        Type::Reference(ty) => {
            if ty.lifetime.is_none() {
                ty.lifetime = Some(Lifetime::new("'static", ty.and_token.span));
            }
            populate_static_lifetimes(&mut ty.elem);
        }
        Type::Slice(ty) => populate_static_lifetimes(&mut ty.elem),
        Type::Tuple(ty) => ty.elems.iter_mut().for_each(populate_static_lifetimes),
        Type::ImplTrait(_)
        | Type::Infer(_)
        | Type::Macro(_)
        | Type::Never(_)
        | Type::TraitObject(_)
        | Type::BareFn(_)
        | Type::Verbatim(_) => {}

        _ => unimplemented!("unknown Type"),
    }
}