Skip to content

Commit

Permalink
fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicexplorer committed Oct 9, 2021
1 parent fd14b69 commit cf6a9f7
Showing 1 changed file with 28 additions and 35 deletions.
63 changes: 28 additions & 35 deletions src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<PathSegment, Colon2>::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,
Expand Down Expand Up @@ -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.
_ => (),
}
}

Expand All @@ -300,18 +294,17 @@ 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;
}
}

// 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);
}
Expand Down

0 comments on commit cf6a9f7

Please sign in to comment.