Skip to content

Commit 239e59b

Browse files
committed
Use if let to reduce some excessive indentation.
1 parent 1f50a2e commit 239e59b

File tree

1 file changed

+45
-53
lines changed

1 file changed

+45
-53
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

+45-53
Original file line numberDiff line numberDiff line change
@@ -1419,62 +1419,54 @@ fn deny_equality_constraints(
14191419
let mut err = errors::EqualityInWhere { span: predicate.span, assoc: None, assoc2: None };
14201420

14211421
// Given `<A as Foo>::Bar = RhsTy`, suggest `A: Foo<Bar = RhsTy>`.
1422-
if let TyKind::Path(Some(qself), full_path) = &predicate.lhs_ty.kind {
1423-
if let TyKind::Path(None, path) = &qself.ty.kind {
1424-
match &path.segments[..] {
1425-
[PathSegment { ident, args: None, .. }] => {
1426-
for param in &generics.params {
1427-
if param.ident == *ident {
1428-
let param = ident;
1429-
match &full_path.segments[qself.position..] {
1430-
[PathSegment { ident, args, .. }] => {
1431-
// Make a new `Path` from `foo::Bar` to `Foo<Bar = RhsTy>`.
1432-
let mut assoc_path = full_path.clone();
1433-
// Remove `Bar` from `Foo::Bar`.
1434-
assoc_path.segments.pop();
1435-
let len = assoc_path.segments.len() - 1;
1436-
let gen_args = args.as_deref().cloned();
1437-
// Build `<Bar = RhsTy>`.
1438-
let arg = AngleBracketedArg::Constraint(AssocConstraint {
1439-
id: rustc_ast::node_id::DUMMY_NODE_ID,
1440-
ident: *ident,
1441-
gen_args,
1442-
kind: AssocConstraintKind::Equality {
1443-
term: predicate.rhs_ty.clone().into(),
1444-
},
1445-
span: ident.span,
1446-
});
1447-
// Add `<Bar = RhsTy>` to `Foo`.
1448-
match &mut assoc_path.segments[len].args {
1449-
Some(args) => match args.deref_mut() {
1450-
GenericArgs::Parenthesized(_) => continue,
1451-
GenericArgs::AngleBracketed(args) => {
1452-
args.args.push(arg);
1453-
}
1454-
},
1455-
empty_args => {
1456-
*empty_args = Some(
1457-
AngleBracketedArgs {
1458-
span: ident.span,
1459-
args: thin_vec![arg],
1460-
}
1461-
.into(),
1462-
);
1463-
}
1464-
}
1465-
err.assoc = Some(errors::AssociatedSuggestion {
1466-
span: predicate.span,
1467-
ident: *ident,
1468-
param: *param,
1469-
path: pprust::path_to_string(&assoc_path),
1470-
})
1471-
}
1472-
_ => {}
1473-
};
1422+
if let TyKind::Path(Some(qself), full_path) = &predicate.lhs_ty.kind
1423+
&& let TyKind::Path(None, path) = &qself.ty.kind
1424+
&& let [PathSegment { ident, args: None, .. }] = &path.segments[..]
1425+
{
1426+
for param in &generics.params {
1427+
if param.ident == *ident
1428+
&& let [PathSegment { ident, args, .. }] = &full_path.segments[qself.position..]
1429+
{
1430+
// Make a new `Path` from `foo::Bar` to `Foo<Bar = RhsTy>`.
1431+
let mut assoc_path = full_path.clone();
1432+
// Remove `Bar` from `Foo::Bar`.
1433+
assoc_path.segments.pop();
1434+
let len = assoc_path.segments.len() - 1;
1435+
let gen_args = args.as_deref().cloned();
1436+
// Build `<Bar = RhsTy>`.
1437+
let arg = AngleBracketedArg::Constraint(AssocConstraint {
1438+
id: rustc_ast::node_id::DUMMY_NODE_ID,
1439+
ident: *ident,
1440+
gen_args,
1441+
kind: AssocConstraintKind::Equality {
1442+
term: predicate.rhs_ty.clone().into(),
1443+
},
1444+
span: ident.span,
1445+
});
1446+
// Add `<Bar = RhsTy>` to `Foo`.
1447+
match &mut assoc_path.segments[len].args {
1448+
Some(args) => match args.deref_mut() {
1449+
GenericArgs::Parenthesized(_) => continue,
1450+
GenericArgs::AngleBracketed(args) => {
1451+
args.args.push(arg);
14741452
}
1453+
},
1454+
empty_args => {
1455+
*empty_args = Some(
1456+
AngleBracketedArgs {
1457+
span: ident.span,
1458+
args: thin_vec![arg],
1459+
}
1460+
.into(),
1461+
);
14751462
}
14761463
}
1477-
_ => {}
1464+
err.assoc = Some(errors::AssociatedSuggestion {
1465+
span: predicate.span,
1466+
ident: *ident,
1467+
param: param.ident,
1468+
path: pprust::path_to_string(&assoc_path),
1469+
})
14781470
}
14791471
}
14801472
}

0 commit comments

Comments
 (0)