diff --git a/src/expand.rs b/src/expand.rs index fdb07f4..1115d15 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -150,7 +150,7 @@ enum UseGlobalPrefix { /// Create a path with segments composed of [Idents] *without* any [PathArguments]. fn join_paths(name_segments: &[&str], use_global_prefix: UseGlobalPrefix) -> Path { let mut segments = Punctuated::::new(); - assert!(name_segments.len() >= 1); + assert!(!name_segments.is_empty()); segments.push_value(PathSegment { ident: Ident::new(name_segments[0], Span::call_site()), arguments: PathArguments::None, @@ -246,38 +246,32 @@ fn extract_trait_constraints_from_source( // Add trait bounds from `where` clauses, which may be type parameters or types containing // those parameters. for predicate in where_clause.predicates.iter() { - match predicate { - WherePredicate::Type(ref pred_ty) => { - let ident = match &pred_ty.bounded_ty { - Type::Path(TypePath { path, qself: None }) => match path.get_ident() { - None => continue, - Some(ident) => ident, - }, - _ => continue, - }; - // We ignore any type constraints that aren't direct references to type - // parameters of the current enum of struct definition. No types can be - // constrained in a `where` clause unless they are a type parameter or a generic - // type instantiated with one of the type parameters, so by only allowing single - // identifiers, we can be sure that the constrained type is a type parameter - // that is contained in `param_constraint_mapping`. - if let Some((_, ref mut known_bounds)) = param_constraint_mapping - .iter_mut() - .find(|(id, _)| *id == ident) - { - for bound in pred_ty.bounds.iter() { - match bound { - TypeParamBound::Trait(ref bound) => { - known_bounds.push(bound.clone()); - } - // We only care about trait bounds here. - _ => (), - } + // We only care about type and not lifetime constraints here. + if let WherePredicate::Type(ref pred_ty) = predicate { + let ident = match &pred_ty.bounded_ty { + Type::Path(TypePath { path, qself: None }) => match path.get_ident() { + None => continue, + Some(ident) => ident, + }, + _ => continue, + }; + // We ignore any type constraints that aren't direct references to type + // parameters of the current enum of struct definition. No types can be + // constrained in a `where` clause unless they are a type parameter or a generic + // type instantiated with one of the type parameters, so by only allowing single + // identifiers, we can be sure that the constrained type is a type parameter + // that is contained in `param_constraint_mapping`. + if let Some((_, ref mut known_bounds)) = param_constraint_mapping + .iter_mut() + .find(|(id, _)| *id == ident) + { + for bound in pred_ty.bounds.iter() { + // We only care about trait bounds here. + if let TypeParamBound::Trait(ref bound) = bound { + known_bounds.push(bound.clone()); } } } - // We only care about type and not lifetime constraints here. - _ => (), } } @@ -300,10 +294,9 @@ fn ensure_display_in_where_clause_for_type(where_clause: &mut WhereClause, ident // Do a complicated destructuring in order to check if the type being constrained in this // `where` clause is the type we're looking for, so we can use the mutable reference to // `pred_ty` if so. - let matches_desired_type = match &pred_ty.bounded_ty { - Type::Path(TypePath { path, .. }) if Some(&ident) == path.get_ident() => true, - _ => false, - }; + let matches_desired_type = matches!( + &pred_ty.bounded_ty, + Type::Path(TypePath { path, .. }) if Some(&ident) == path.get_ident()); if matches_desired_type { add_display_constraint_to_type_predicate(pred_ty); return; @@ -311,7 +304,7 @@ fn ensure_display_in_where_clause_for_type(where_clause: &mut WhereClause, ident } // If there is no `where` predicate for the current type param, we will construct one. - let mut new_type_predicate = new_empty_where_type_predicate(ident.clone()); + let mut new_type_predicate = new_empty_where_type_predicate(ident); add_display_constraint_to_type_predicate(&mut new_type_predicate); append_where_clause_type_predicate(where_clause, new_type_predicate); }