• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use syn::{GenericArgument, Lifetime, PathArguments, Type};
2 
populate_static_lifetimes(ty: &mut Type)3 pub(crate) fn populate_static_lifetimes(ty: &mut Type) {
4     match ty {
5         #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
6         Type::Array(ty) => populate_static_lifetimes(&mut ty.elem),
7         Type::Group(ty) => populate_static_lifetimes(&mut ty.elem),
8         Type::Paren(ty) => populate_static_lifetimes(&mut ty.elem),
9         Type::Path(ty) => {
10             if let Some(qself) = &mut ty.qself {
11                 populate_static_lifetimes(&mut qself.ty);
12             }
13             for segment in &mut ty.path.segments {
14                 if let PathArguments::AngleBracketed(segment) = &mut segment.arguments {
15                     for arg in &mut segment.args {
16                         if let GenericArgument::Type(arg) = arg {
17                             populate_static_lifetimes(arg);
18                         }
19                     }
20                 }
21             }
22         }
23         Type::Ptr(ty) => populate_static_lifetimes(&mut ty.elem),
24         Type::Reference(ty) => {
25             if ty.lifetime.is_none() {
26                 ty.lifetime = Some(Lifetime::new("'static", ty.and_token.span));
27             }
28             populate_static_lifetimes(&mut ty.elem);
29         }
30         Type::Slice(ty) => populate_static_lifetimes(&mut ty.elem),
31         Type::Tuple(ty) => ty.elems.iter_mut().for_each(populate_static_lifetimes),
32         Type::ImplTrait(_)
33         | Type::Infer(_)
34         | Type::Macro(_)
35         | Type::Never(_)
36         | Type::TraitObject(_)
37         | Type::BareFn(_)
38         | Type::Verbatim(_) => {}
39 
40         _ => unimplemented!("unknown Type"),
41     }
42 }
43