about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2023-11-16 16:55:25 +0000
committerEsteban Küber <esteban@kuber.com.ar>2023-11-20 23:44:37 +0000
commiteee4cc661677be3bf58db12ea1ee598e822762ff (patch)
tree12950b4b4a589e67d2d368b9a9e2b1f52020bcb1
parent02bea16c08d6c0202f7cb1658280bd7cf97560d0 (diff)
downloadrust-eee4cc661677be3bf58db12ea1ee598e822762ff.tar.gz
rust-eee4cc661677be3bf58db12ea1ee598e822762ff.zip
let-chain fmt
-rw-r--r--compiler/rustc_resolve/src/late/diagnostics.rs55
1 files changed, 24 insertions, 31 deletions
diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs
index 1ffe8a9a26e..bccce8699c5 100644
--- a/compiler/rustc_resolve/src/late/diagnostics.rs
+++ b/compiler/rustc_resolve/src/late/diagnostics.rs
@@ -2976,8 +2976,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
                             || lt.kind == MissingLifetimeKind::Underscore)
                     {
                         let pre = if lt.kind == MissingLifetimeKind::Ampersand
-                            && let Some((kind, _span)) =
-                                self.diagnostic_metadata.current_function
+                            && let Some((kind, _span)) = self.diagnostic_metadata.current_function
                             && let FnKind::Fn(_, _, sig, _, _, _) = kind
                             && !sig.decl.inputs.is_empty()
                             && let sugg = sig
@@ -3002,7 +3001,6 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
                                 .collect::<Vec<_>>()
                             && !sugg.is_empty()
                         {
-
                             let (the, s) = if sig.decl.inputs.len() == 1 {
                                 ("the", "")
                             } else {
@@ -3018,9 +3016,8 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
                             );
                             "...or alternatively, you might want"
                         } else if (lt.kind == MissingLifetimeKind::Ampersand
-                                || lt.kind == MissingLifetimeKind::Underscore)
-                            && let Some((kind, _span)) =
-                                self.diagnostic_metadata.current_function
+                            || lt.kind == MissingLifetimeKind::Underscore)
+                            && let Some((kind, _span)) = self.diagnostic_metadata.current_function
                             && let FnKind::Fn(_, _, sig, _, _, _) = kind
                             && let ast::FnRetTy::Ty(ret_ty) = &sig.decl.output
                             && !sig.decl.inputs.is_empty()
@@ -3041,26 +3038,25 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
                             // So we look at every ref in the trait bound. If there's any, we
                             // suggest
                             // fn g<'a>(mut x: impl Iterator<Item = &'a ()>) -> Option<&'a ()>
-                            let mut lt_finder = LifetimeFinder {
-                                lifetime: lt.span,
-                                found: None,
-                                seen: vec![],
-                            };
+                            let mut lt_finder =
+                                LifetimeFinder { lifetime: lt.span, found: None, seen: vec![] };
                             for bound in arg_refs {
                                 if let ast::GenericBound::Trait(trait_ref, _) = bound {
                                     lt_finder.visit_trait_ref(&trait_ref.trait_ref);
                                 }
                             }
                             lt_finder.visit_ty(ret_ty);
-                            let spans_suggs: Vec<_> = lt_finder.seen.iter().filter_map(|ty| {
-                                match &ty.kind {
+                            let spans_suggs: Vec<_> = lt_finder
+                                .seen
+                                .iter()
+                                .filter_map(|ty| match &ty.kind {
                                     TyKind::Ref(_, mut_ty) => {
                                         let span = ty.span.with_hi(mut_ty.ty.span.lo());
                                         Some((span, "&'a ".to_string()))
                                     }
-                                    _ => None
-                                }
-                            }).collect();
+                                    _ => None,
+                                })
+                                .collect();
                             self.suggest_introducing_lifetime(
                                 err,
                                 None,
@@ -3081,20 +3077,16 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
                         };
                         let mut owned_sugg = lt.kind == MissingLifetimeKind::Ampersand;
                         let mut sugg = vec![(lt.span, String::new())];
-                        if let Some((kind, _span)) =
-                            self.diagnostic_metadata.current_function
+                        if let Some((kind, _span)) = self.diagnostic_metadata.current_function
                             && let FnKind::Fn(_, _, sig, _, _, _) = kind
                             && let ast::FnRetTy::Ty(ty) = &sig.decl.output
                         {
-                            let mut lt_finder = LifetimeFinder {
-                                lifetime: lt.span,
-                                found: None,
-                                seen: vec![],
-                            };
+                            let mut lt_finder =
+                                LifetimeFinder { lifetime: lt.span, found: None, seen: vec![] };
                             lt_finder.visit_ty(&ty);
 
-                            if let [Ty { span, kind: TyKind::Ref(_, mut_ty), ..}]
-                                = &lt_finder.seen[..]
+                            if let [Ty { span, kind: TyKind::Ref(_, mut_ty), .. }] =
+                                &lt_finder.seen[..]
                             {
                                 // We might have a situation like
                                 // fn g(mut x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()>
@@ -3109,9 +3101,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
                                     // Check if the path being borrowed is likely to be owned.
                                     let path: Vec<_> = Segment::from_path(path);
                                     match self.resolve_path(&path, Some(TypeNS), None) {
-                                        PathResult::Module(
-                                            ModuleOrUniformRoot::Module(module),
-                                        ) => {
+                                        PathResult::Module(ModuleOrUniformRoot::Module(module)) => {
                                             match module.res() {
                                                 Some(Res::PrimTy(PrimTy::Str)) => {
                                                     // Don't suggest `-> str`, suggest `-> String`.
@@ -3131,7 +3121,8 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
                                                     | DefKind::TyParam,
                                                     _,
                                                 )) => {}
-                                                _ => { // Do not suggest in all other cases.
+                                                _ => {
+                                                    // Do not suggest in all other cases.
                                                     owned_sugg = false;
                                                 }
                                             }
@@ -3156,12 +3147,14 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
                                                     | DefKind::TyParam,
                                                     _,
                                                 ) => {}
-                                                _ => { // Do not suggest in all other cases.
+                                                _ => {
+                                                    // Do not suggest in all other cases.
                                                     owned_sugg = false;
                                                 }
                                             }
                                         }
-                                        _ => { // Do not suggest in all other cases.
+                                        _ => {
+                                            // Do not suggest in all other cases.
                                             owned_sugg = false;
                                         }
                                     }