fn contains_generic(generics: &Generics, ty: &Type) -> bool {
    match ty {
        Type::Array(TypeArray { elem, .. }) => contains_generic(generics, &elem),
        Type::BareFn(TypeBareFn { inputs, output, .. }) => {
            for arg in inputs {
                if contains_generic(&generics, &arg.ty) {
                    return true;
                }
            }

            match output {
                ReturnType::Default => false,
                ReturnType::Type(_, ty) => contains_generic(generics, ty),
            }
        }
        Type::Group(TypeGroup { elem, .. }) => contains_generic(generics, elem),
        Type::ImplTrait(TypeImplTrait { bounds, .. }) => bounds
            .iter()
            .any(|b| param_bound_contains_generic(generics, b)),
        Type::Infer(_) => false,
        Type::Macro(_) => true,
        Type::Never(_) => false,
        Type::Paren(TypeParen { elem, .. }) => contains_generic(generics, elem),
        Type::Path(TypePath { path, .. }) => path_contains_generic(generics, path),
        Type::Ptr(TypePtr { elem, .. }) => contains_generic(generics, elem),
        Type::Reference(TypeReference { elem, .. }) => contains_generic(generics, elem),
        Type::Slice(TypeSlice { elem, .. }) => contains_generic(generics, elem),
        Type::TraitObject(TypeTraitObject { bounds, .. }) => bounds
            .iter()
            .any(|b| param_bound_contains_generic(generics, b)),
        Type::Tuple(TypeTuple { elems, .. }) => {
            elems.iter().any(|ty| contains_generic(generics, ty))
        }
        // Nothing we can do here, err on the side of too many `where` clauses.
        Type::Verbatim(_) => true,
        // TODO: This may be problematic, double check if we did not miss anything.
        _ => true,
    }
}
/// Returns whether any of the `generics` show up in `ty`.
///
/// Used to determine whether or not a specific type needs to be listed in where clauses because it
/// contains generic types. Note that the function is not entirely accurate and may produce false
/// postives in some cases.
Returns whether any of the `generics` show up in `ty`.
Used to determine whether or not a specific type needs to be listed in where clauses because it
contains generic types. Note that the function is not entirely accurate and may produce false
postives in some cases.
Returns whether any of the ` generics ` show up in ` ty ` . Used to determine whether or not a specific type needs to be listed in where clauses because it contains generic types . Note that the function is not entirely accurate and may produce false postives in some cases .
fn contains_generic(generics: &Generics, ty: &Type) -> bool {
    match ty {
        Type::Array(TypeArray { elem, .. }) => contains_generic(generics, &elem),
        Type::BareFn(TypeBareFn { inputs, output, .. }) => {
            for arg in inputs {
                if contains_generic(&generics, &arg.ty) {
                    return true;
                }
            }
            match output {
                ReturnType::Default => false,
                ReturnType::Type(_, ty) => contains_generic(generics, ty),
            }
        }
        Type::Group(TypeGroup { elem, .. }) => contains_generic(generics, elem),
        Type::ImplTrait(TypeImplTrait { bounds, .. }) => bounds
            .iter()
            .any(|b| param_bound_contains_generic(generics, b)),
        Type::Infer(_) => false,
        Type::Macro(_) => true,
        Type::Never(_) => false,
        Type::Paren(TypeParen { elem, .. }) => contains_generic(generics, elem),
        Type::Path(TypePath { path, .. }) => path_contains_generic(generics, path),
        Type::Ptr(TypePtr { elem, .. }) => contains_generic(generics, elem),
        Type::Reference(TypeReference { elem, .. }) => contains_generic(generics, elem),
        Type::Slice(TypeSlice { elem, .. }) => contains_generic(generics, elem),
        Type::TraitObject(TypeTraitObject { bounds, .. }) => bounds
            .iter()
            .any(|b| param_bound_contains_generic(generics, b)),
        Type::Tuple(TypeTuple { elems, .. }) => {
            elems.iter().any(|ty| contains_generic(generics, ty))
        }
        // Nothing we can do here, err on the side of too many `where` clauses.
        Type::Verbatim(_) => true,
        // TODO: This may be problematic, double check if we did not miss anything.
        _ => true,
    }
}
fn contains_generic ( generics : & Generics , ty : & Type ) -> bool { match ty { Type :: Array ( TypeArray { elem , .. } ) => contains_generic ( generics , & elem ) , Type :: BareFn ( TypeBareFn { inputs , output , .. } ) => { for arg in inputs { if contains_generic ( & generics , & arg . ty ) { return true ; } } match output { ReturnType :: Default => false , ReturnType :: Type ( _ , ty ) => contains_generic ( generics , ty ) , } } Type :: Group ( TypeGroup { elem , .. } ) => contains_generic ( generics , elem ) , Type :: ImplTrait ( TypeImplTrait { bounds , .. } ) => bounds . iter ( ) . any ( | b | param_bound_contains_generic ( generics , b ) ) , Type :: Infer ( _ ) => false , Type :: Macro ( _ ) => true , Type :: Never ( _ ) => false , Type :: Paren ( TypeParen { elem , .. } ) => contains_generic ( generics , elem ) , Type :: Path ( TypePath { path , .. } ) => path_contains_generic ( generics , path ) , Type :: Ptr ( TypePtr { elem , .. } ) => contains_generic ( generics , elem ) , Type :: Reference ( TypeReference { elem , .. } ) => contains_generic ( generics , elem ) , Type :: Slice ( TypeSlice { elem , .. } ) => contains_generic ( generics , elem ) , Type :: TraitObject ( TypeTraitObject { bounds , .. } ) => bounds . iter ( ) . any ( | b | param_bound_contains_generic ( generics , b ) ) , Type :: Tuple ( TypeTuple { elems , .. } ) => { elems . iter ( ) . any ( | ty | contains_generic ( generics , ty ) ) } // Nothing we can do here, err on the side of too many `where` clauses. Type :: Verbatim ( _ ) => true , // TODO: This may be problematic, double check if we did not miss anything. _ => true , } }
Returns whether any of the `generics` show up in `ty`.
Returns whether any of the ` generics ` show up in ` ty ` .
generics
&Generics
ty
&Type