Skip to content

Commit eee4cc6

Browse files
committed
let-chain fmt
1 parent 02bea16 commit eee4cc6

File tree

1 file changed

+24
-31
lines changed

1 file changed

+24
-31
lines changed

compiler/rustc_resolve/src/late/diagnostics.rs

+24-31
Original file line numberDiff line numberDiff line change
@@ -2976,8 +2976,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
29762976
|| lt.kind == MissingLifetimeKind::Underscore)
29772977
{
29782978
let pre = if lt.kind == MissingLifetimeKind::Ampersand
2979-
&& let Some((kind, _span)) =
2980-
self.diagnostic_metadata.current_function
2979+
&& let Some((kind, _span)) = self.diagnostic_metadata.current_function
29812980
&& let FnKind::Fn(_, _, sig, _, _, _) = kind
29822981
&& !sig.decl.inputs.is_empty()
29832982
&& let sugg = sig
@@ -3002,7 +3001,6 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
30023001
.collect::<Vec<_>>()
30033002
&& !sugg.is_empty()
30043003
{
3005-
30063004
let (the, s) = if sig.decl.inputs.len() == 1 {
30073005
("the", "")
30083006
} else {
@@ -3018,9 +3016,8 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
30183016
);
30193017
"...or alternatively, you might want"
30203018
} else if (lt.kind == MissingLifetimeKind::Ampersand
3021-
|| lt.kind == MissingLifetimeKind::Underscore)
3022-
&& let Some((kind, _span)) =
3023-
self.diagnostic_metadata.current_function
3019+
|| lt.kind == MissingLifetimeKind::Underscore)
3020+
&& let Some((kind, _span)) = self.diagnostic_metadata.current_function
30243021
&& let FnKind::Fn(_, _, sig, _, _, _) = kind
30253022
&& let ast::FnRetTy::Ty(ret_ty) = &sig.decl.output
30263023
&& !sig.decl.inputs.is_empty()
@@ -3041,26 +3038,25 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
30413038
// So we look at every ref in the trait bound. If there's any, we
30423039
// suggest
30433040
// fn g<'a>(mut x: impl Iterator<Item = &'a ()>) -> Option<&'a ()>
3044-
let mut lt_finder = LifetimeFinder {
3045-
lifetime: lt.span,
3046-
found: None,
3047-
seen: vec![],
3048-
};
3041+
let mut lt_finder =
3042+
LifetimeFinder { lifetime: lt.span, found: None, seen: vec![] };
30493043
for bound in arg_refs {
30503044
if let ast::GenericBound::Trait(trait_ref, _) = bound {
30513045
lt_finder.visit_trait_ref(&trait_ref.trait_ref);
30523046
}
30533047
}
30543048
lt_finder.visit_ty(ret_ty);
3055-
let spans_suggs: Vec<_> = lt_finder.seen.iter().filter_map(|ty| {
3056-
match &ty.kind {
3049+
let spans_suggs: Vec<_> = lt_finder
3050+
.seen
3051+
.iter()
3052+
.filter_map(|ty| match &ty.kind {
30573053
TyKind::Ref(_, mut_ty) => {
30583054
let span = ty.span.with_hi(mut_ty.ty.span.lo());
30593055
Some((span, "&'a ".to_string()))
30603056
}
3061-
_ => None
3062-
}
3063-
}).collect();
3057+
_ => None,
3058+
})
3059+
.collect();
30643060
self.suggest_introducing_lifetime(
30653061
err,
30663062
None,
@@ -3081,20 +3077,16 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
30813077
};
30823078
let mut owned_sugg = lt.kind == MissingLifetimeKind::Ampersand;
30833079
let mut sugg = vec![(lt.span, String::new())];
3084-
if let Some((kind, _span)) =
3085-
self.diagnostic_metadata.current_function
3080+
if let Some((kind, _span)) = self.diagnostic_metadata.current_function
30863081
&& let FnKind::Fn(_, _, sig, _, _, _) = kind
30873082
&& let ast::FnRetTy::Ty(ty) = &sig.decl.output
30883083
{
3089-
let mut lt_finder = LifetimeFinder {
3090-
lifetime: lt.span,
3091-
found: None,
3092-
seen: vec![],
3093-
};
3084+
let mut lt_finder =
3085+
LifetimeFinder { lifetime: lt.span, found: None, seen: vec![] };
30943086
lt_finder.visit_ty(&ty);
30953087

3096-
if let [Ty { span, kind: TyKind::Ref(_, mut_ty), ..}]
3097-
= &lt_finder.seen[..]
3088+
if let [Ty { span, kind: TyKind::Ref(_, mut_ty), .. }] =
3089+
&lt_finder.seen[..]
30983090
{
30993091
// We might have a situation like
31003092
// fn g(mut x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()>
@@ -3109,9 +3101,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
31093101
// Check if the path being borrowed is likely to be owned.
31103102
let path: Vec<_> = Segment::from_path(path);
31113103
match self.resolve_path(&path, Some(TypeNS), None) {
3112-
PathResult::Module(
3113-
ModuleOrUniformRoot::Module(module),
3114-
) => {
3104+
PathResult::Module(ModuleOrUniformRoot::Module(module)) => {
31153105
match module.res() {
31163106
Some(Res::PrimTy(PrimTy::Str)) => {
31173107
// Don't suggest `-> str`, suggest `-> String`.
@@ -3131,7 +3121,8 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
31313121
| DefKind::TyParam,
31323122
_,
31333123
)) => {}
3134-
_ => { // Do not suggest in all other cases.
3124+
_ => {
3125+
// Do not suggest in all other cases.
31353126
owned_sugg = false;
31363127
}
31373128
}
@@ -3156,12 +3147,14 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
31563147
| DefKind::TyParam,
31573148
_,
31583149
) => {}
3159-
_ => { // Do not suggest in all other cases.
3150+
_ => {
3151+
// Do not suggest in all other cases.
31603152
owned_sugg = false;
31613153
}
31623154
}
31633155
}
3164-
_ => { // Do not suggest in all other cases.
3156+
_ => {
3157+
// Do not suggest in all other cases.
31653158
owned_sugg = false;
31663159
}
31673160
}

0 commit comments

Comments
 (0)