Add a generic map over a graphic's leaves, reaching every depth

This commit is contained in:
Dennis Kobert
2026-09-14 01:25:04 +02:00
parent 344d21768f
commit fd640459a2
4 changed files with 284 additions and 1 deletions

View File

@@ -181,10 +181,26 @@ fn element_of(ty: &Type, generics: &[Ident]) -> Element {
}
match bare_ident(ty) {
Some(ident) if generics.contains(ident) => Element::Generic(ident.clone()),
_ => Element::Concrete(ty.clone()),
_ => match projected_generic(ty, generics) {
Some(ident) => Element::Generic(ident),
None => Element::Concrete(ty.clone()),
},
}
}
/// The carried generic an associated type is projected off, as in `V::Mapped<'a>`.
/// Such an output is that generic's element re-stated at another lifetime, so it
/// rides as the carried element rather than as a freshly written one.
fn projected_generic(ty: &Type, generics: &[Ident]) -> Option<Ident> {
let Type::Path(path) = ty else { return None };
if path.qself.is_some() || path.path.segments.len() < 2 {
return None;
}
let head = &path.path.segments.first()?.ident;
generics.contains(head).then(|| head.clone())
}
pub(crate) fn strip_ilist(ty: &Type) -> (Type, u8) {
let mut element = ty.clone();
let mut depth = 0;