Use if let
to reduce some excessive indentation.
This commit is contained in:
parent
dcb72e705f
commit
c88954e9c1
@ -1442,62 +1442,54 @@ fn deny_equality_constraints(
|
|||||||
let mut err = errors::EqualityInWhere { span: predicate.span, assoc: None, assoc2: None };
|
let mut err = errors::EqualityInWhere { span: predicate.span, assoc: None, assoc2: None };
|
||||||
|
|
||||||
// Given `<A as Foo>::Bar = RhsTy`, suggest `A: Foo<Bar = RhsTy>`.
|
// Given `<A as Foo>::Bar = RhsTy`, suggest `A: Foo<Bar = RhsTy>`.
|
||||||
if let TyKind::Path(Some(qself), full_path) = &predicate.lhs_ty.kind {
|
if let TyKind::Path(Some(qself), full_path) = &predicate.lhs_ty.kind
|
||||||
if let TyKind::Path(None, path) = &qself.ty.kind {
|
&& let TyKind::Path(None, path) = &qself.ty.kind
|
||||||
match &path.segments[..] {
|
&& let [PathSegment { ident, args: None, .. }] = &path.segments[..]
|
||||||
[PathSegment { ident, args: None, .. }] => {
|
{
|
||||||
for param in &generics.params {
|
for param in &generics.params {
|
||||||
if param.ident == *ident {
|
if param.ident == *ident
|
||||||
let param = ident;
|
&& let [PathSegment { ident, args, .. }] = &full_path.segments[qself.position..]
|
||||||
match &full_path.segments[qself.position..] {
|
{
|
||||||
[PathSegment { ident, args, .. }] => {
|
// Make a new `Path` from `foo::Bar` to `Foo<Bar = RhsTy>`.
|
||||||
// Make a new `Path` from `foo::Bar` to `Foo<Bar = RhsTy>`.
|
let mut assoc_path = full_path.clone();
|
||||||
let mut assoc_path = full_path.clone();
|
// Remove `Bar` from `Foo::Bar`.
|
||||||
// Remove `Bar` from `Foo::Bar`.
|
assoc_path.segments.pop();
|
||||||
assoc_path.segments.pop();
|
let len = assoc_path.segments.len() - 1;
|
||||||
let len = assoc_path.segments.len() - 1;
|
let gen_args = args.as_deref().cloned();
|
||||||
let gen_args = args.as_deref().cloned();
|
// Build `<Bar = RhsTy>`.
|
||||||
// Build `<Bar = RhsTy>`.
|
let arg = AngleBracketedArg::Constraint(AssocConstraint {
|
||||||
let arg = AngleBracketedArg::Constraint(AssocConstraint {
|
id: rustc_ast::node_id::DUMMY_NODE_ID,
|
||||||
id: rustc_ast::node_id::DUMMY_NODE_ID,
|
ident: *ident,
|
||||||
ident: *ident,
|
gen_args,
|
||||||
gen_args,
|
kind: AssocConstraintKind::Equality {
|
||||||
kind: AssocConstraintKind::Equality {
|
term: predicate.rhs_ty.clone().into(),
|
||||||
term: predicate.rhs_ty.clone().into(),
|
},
|
||||||
},
|
span: ident.span,
|
||||||
span: ident.span,
|
});
|
||||||
});
|
// Add `<Bar = RhsTy>` to `Foo`.
|
||||||
// Add `<Bar = RhsTy>` to `Foo`.
|
match &mut assoc_path.segments[len].args {
|
||||||
match &mut assoc_path.segments[len].args {
|
Some(args) => match args.deref_mut() {
|
||||||
Some(args) => match args.deref_mut() {
|
GenericArgs::Parenthesized(_) => continue,
|
||||||
GenericArgs::Parenthesized(_) => continue,
|
GenericArgs::AngleBracketed(args) => {
|
||||||
GenericArgs::AngleBracketed(args) => {
|
args.args.push(arg);
|
||||||
args.args.push(arg);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
empty_args => {
|
|
||||||
*empty_args = Some(
|
|
||||||
AngleBracketedArgs {
|
|
||||||
span: ident.span,
|
|
||||||
args: thin_vec![arg],
|
|
||||||
}
|
|
||||||
.into(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
err.assoc = Some(errors::AssociatedSuggestion {
|
|
||||||
span: predicate.span,
|
|
||||||
ident: *ident,
|
|
||||||
param: *param,
|
|
||||||
path: pprust::path_to_string(&assoc_path),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
empty_args => {
|
||||||
|
*empty_args = Some(
|
||||||
|
AngleBracketedArgs {
|
||||||
|
span: ident.span,
|
||||||
|
args: thin_vec![arg],
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
err.assoc = Some(errors::AssociatedSuggestion {
|
||||||
|
span: predicate.span,
|
||||||
|
ident: *ident,
|
||||||
|
param: param.ident,
|
||||||
|
path: pprust::path_to_string(&assoc_path),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user