-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add basic support for non static lifetimes
- Loading branch information
Showing
4 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use syn::{parse_quote, GenericArgument, PathArguments, Type}; | ||
|
||
pub(crate) fn type_lifetimes_to_static(ty: &mut Type) { | ||
match ty { | ||
Type::Array(array) => type_lifetimes_to_static(array.elem.as_mut()), | ||
Type::Group(group) => type_lifetimes_to_static(&mut group.elem), | ||
Type::ImplTrait(_) => {} | ||
Type::Path(path) => { | ||
for segment in &mut path.path.segments { | ||
match &mut segment.arguments { | ||
PathArguments::None => (), | ||
PathArguments::AngleBracketed(angle_bracketed) => { | ||
for arg in &mut angle_bracketed.args { | ||
match arg { | ||
GenericArgument::Lifetime(lifetime) => { | ||
*lifetime = parse_quote!('static); | ||
} | ||
GenericArgument::Type(ty) => type_lifetimes_to_static(ty), | ||
_ => (), | ||
} | ||
} | ||
} | ||
PathArguments::Parenthesized(parenthesized) => { | ||
for input in &mut parenthesized.inputs { | ||
type_lifetimes_to_static(input) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
Type::Ptr(ptr) => type_lifetimes_to_static(&mut ptr.elem), | ||
Type::Reference(reference) => reference.lifetime = Some(parse_quote!('static)), | ||
Type::Slice(slice) => type_lifetimes_to_static(&mut slice.elem), | ||
Type::Tuple(tuple) => { | ||
for elem in &mut tuple.elems { | ||
type_lifetimes_to_static(elem) | ||
} | ||
} | ||
_ => (), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters