while lifetimes.0.iter().any(|name| name.starts_with(&**lifetime_name)) {
lifetime_name.push('_');
}
}
/// Like `insert_lifetime`, but also generates a bound of the form /// `OriginalType<A, B>: 'lifetime`. Used when generating the definition /// of a projection type pub(crate) fn insert_lifetime_and_bound(
generics: &mut Generics,
lifetime: Lifetime,
orig_generics: &Generics,
orig_ident: &Ident,
) -> WherePredicate {
insert_lifetime(generics, lifetime.clone());
let orig_type: Type = parse_quote!(#orig_ident#orig_generics); letmut punct = Punctuated::new();
punct.push(TypeParamBound::Lifetime(lifetime));
/// Inserts a `lifetime` at position `0` of `generics.params`. pub(crate) fn insert_lifetime(generics: &mut Generics, lifetime: Lifetime) {
generics.lt_token.get_or_insert_with(<Token![<]>::default);
generics.gt_token.get_or_insert_with(<Token![>]>::default);
generics.params.insert(0, LifetimeParam::new(lifetime).into());
}
/// Determines the visibility of the projected types and projection methods. /// /// If given visibility is `pub`, returned visibility is `pub(crate)`. /// Otherwise, returned visibility is the same as given visibility. pub(crate) fn determine_visibility(vis: &Visibility) -> Visibility { iflet Visibility::Public(token) = vis {
parse_quote_spanned!(token.span => pub(crate))
} else {
vis.clone()
}
}
pub(crate) fn respan<T>(node: &T, span: Span) -> T where
T: ToTokens + Parse,
{ let tokens = node.to_token_stream(); let respanned = respan_tokens(tokens, span);
syn::parse2(respanned).unwrap()
}
fn visit_path_mut(&mutself, path: &mut Path) { if path.segments.len() == 1 { // Replace `self`, but not `self::function`.
prepend_underscore_to_self(&mut path.segments[0].ident);
} for segment in &mut path.segments { self.visit_path_arguments_mut(&mut segment.arguments);
}
}
fn visit_item_mut(&mutself, item: &mut Item) { match item { // Visit `macro_rules!` because locally defined macros can refer to `self`.
Item::Macro(item) if item.mac.path.is_ident("macro_rules") => { self.visit_macro_mut(&mut item.mac);
} // Otherwise, do not recurse into nested items.
_ => {}
}
}
fn visit_macro_mut(&mutself, mac: &mutMacro) { // We can't tell in general whether `self` inside a macro invocation // refers to the self in the argument list or a different self // introduced within the macro. Heuristic: if the macro input contains // `fn`, then `self` is more likely to refer to something other than the // outer function's self argument. if !contains_fn(mac.tokens.clone()) { self.visit_token_stream(&mut mac.tokens);
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.