fn path_contains_generic(generics: &Generics, path: &Path) -> bool {
    let mut candidates = HashSet::new();

    for segment in &path.segments {
        candidates.insert(segment.ident.clone());

        match &segment.arguments {
            PathArguments::None => {}
            PathArguments::AngleBracketed(AngleBracketedGenericArguments { ref args, .. }) => {
                for arg in args {
                    match arg {
                        syn::GenericArgument::Lifetime(_) => {
                            // Ignore lifetime args.
                        }
                        syn::GenericArgument::Type(ty) => {
                            // Simply recurse and check directly.
                            if contains_generic(generics, ty) {
                                return true;
                            }
                        }
                        syn::GenericArgument::Binding(Binding {
                            // We can ignore the ident here, as it is local.
                            ty,
                            ..
                        }) => {
                            // Again, exit early with `true` if we find a match.
                            if contains_generic(generics, ty) {
                                return true;
                            }
                        }
                        syn::GenericArgument::Constraint(_) => {
                            // Additional constraints are fine?
                        }
                        syn::GenericArgument::Const(_) => {
                            // Constants do not require `DataSize` impls.
                        }
                    }
                }
            }
            syn::PathArguments::Parenthesized(ParenthesizedGenericArguments {
                inputs,
                output,
                ..
            }) => {
                if inputs.iter().any(|ty| contains_generic(generics, ty)) {
                    return true;
                }

                match output {
                    ReturnType::Default => {}
                    ReturnType::Type(_, ref ty) => {
                        if contains_generic(generics, ty) {
                            return true;
                        }
                    }
                }
            }
        }
    }

    let generic_idents: HashSet<_> = generics
        .params
        .iter()
        .filter_map(|gen| match gen {
            syn::GenericParam::Type(TypeParam { ident, .. }) => Some(ident.clone()),
            syn::GenericParam::Lifetime(_) => None,
            syn::GenericParam::Const(_) => None,
        })
        .collect();

    // If we find at least one generic in all of the types, we return `true` here.
    candidates.intersection(&generic_idents).next().is_some()
}
/// Returns whether any of the `generics` show up in a given path.
///
/// May yield false positives.
Returns whether any of the `generics` show up in a given path.
May yield false positives.
Returns whether any of the ` generics ` show up in a given path . May yield false positives .
fn path_contains_generic(generics: &Generics, path: &Path) -> bool {
    let mut candidates = HashSet::new();
    for segment in &path.segments {
        candidates.insert(segment.ident.clone());
        match &segment.arguments {
            PathArguments::None => {}
            PathArguments::AngleBracketed(AngleBracketedGenericArguments { ref args, .. }) => {
                for arg in args {
                    match arg {
                        syn::GenericArgument::Lifetime(_) => {
                            // Ignore lifetime args.
                        }
                        syn::GenericArgument::Type(ty) => {
                            // Simply recurse and check directly.
                            if contains_generic(generics, ty) {
                                return true;
                            }
                        }
                        syn::GenericArgument::Binding(Binding {
                            // We can ignore the ident here, as it is local.
                            ty,
                            ..
                        }) => {
                            // Again, exit early with `true` if we find a match.
                            if contains_generic(generics, ty) {
                                return true;
                            }
                        }
                        syn::GenericArgument::Constraint(_) => {
                            // Additional constraints are fine?
                        }
                        syn::GenericArgument::Const(_) => {
                            // Constants do not require `DataSize` impls.
                        }
                    }
                }
            }
            syn::PathArguments::Parenthesized(ParenthesizedGenericArguments {
                inputs,
                output,
                ..
            }) => {
                if inputs.iter().any(|ty| contains_generic(generics, ty)) {
                    return true;
                }
                match output {
                    ReturnType::Default => {}
                    ReturnType::Type(_, ref ty) => {
                        if contains_generic(generics, ty) {
                            return true;
                        }
                    }
                }
            }
        }
    }
    let generic_idents: HashSet<_> = generics
        .params
        .iter()
        .filter_map(|gen| match gen {
            syn::GenericParam::Type(TypeParam { ident, .. }) => Some(ident.clone()),
            syn::GenericParam::Lifetime(_) => None,
            syn::GenericParam::Const(_) => None,
        })
        .collect();
    // If we find at least one generic in all of the types, we return `true` here.
    candidates.intersection(&generic_idents).next().is_some()
}
fn path_contains_generic ( generics : & Generics , path : & Path ) -> bool { let mut candidates = HashSet :: new ( ) ; for segment in & path . segments { candidates . insert ( segment . ident . clone ( ) ) ; match & segment . arguments { PathArguments :: None => { } PathArguments :: AngleBracketed ( AngleBracketedGenericArguments { ref args , .. } ) => { for arg in args { match arg { syn :: GenericArgument :: Lifetime ( _ ) => { // Ignore lifetime args. } syn :: GenericArgument :: Type ( ty ) => { // Simply recurse and check directly. if contains_generic ( generics , ty ) { return true ; } } syn :: GenericArgument :: Binding ( Binding { // We can ignore the ident here, as it is local. ty , .. } ) => { // Again, exit early with `true` if we find a match. if contains_generic ( generics , ty ) { return true ; } } syn :: GenericArgument :: Constraint ( _ ) => { // Additional constraints are fine? } syn :: GenericArgument :: Const ( _ ) => { // Constants do not require `DataSize` impls. } } } } syn :: PathArguments :: Parenthesized ( ParenthesizedGenericArguments { inputs , output , .. } ) => { if inputs . iter ( ) . any ( | ty | contains_generic ( generics , ty ) ) { return true ; } match output { ReturnType :: Default => { } ReturnType :: Type ( _ , ref ty ) => { if contains_generic ( generics , ty ) { return true ; } } } } } } let generic_idents : HashSet < _ > = generics . params . iter ( ) . filter_map ( | gen | match gen { syn :: GenericParam :: Type ( TypeParam { ident , .. } ) => Some ( ident . clone ( ) ) , syn :: GenericParam :: Lifetime ( _ ) => None , syn :: GenericParam :: Const ( _ ) => None , } ) . collect ( ) ; // If we find at least one generic in all of the types, we return `true` here. candidates . intersection ( & generic_idents ) . next ( ) . is_some ( ) }
Returns whether any of the `generics` show up in a given path.
Returns whether any of the ` generics ` show up in a given path .
generics
&Generics
path
&Path