]> git.lizzy.rs Git - rust.git/commitdiff
clean up give_name_if_anonymous_region_appears_in_arguments
authorSNCPlay42 <SNCPlay42@gmail.com>
Wed, 22 Jul 2020 19:38:44 +0000 (20:38 +0100)
committerSNCPlay42 <SNCPlay42@gmail.com>
Wed, 22 Jul 2020 22:52:49 +0000 (23:52 +0100)
src/librustc_mir/borrow_check/diagnostics/region_name.rs

index 9e5851fd81165033861601362a919328efb4b1e3..da86a0c3bb9d56dd03aa8d0956147059c9148718 100644 (file)
@@ -336,27 +336,18 @@ fn give_name_if_anonymous_region_appears_in_arguments(
 
         let arg_ty = self.regioncx.universal_regions().unnormalized_input_tys
             [implicit_inputs + argument_index];
-        if let Some(highlight) =
-            self.highlight_if_we_can_match_hir_ty_from_argument(fr, arg_ty, argument_index)
-        {
-            return Some(RegionName {
-                name: self.synthesize_region_name(),
-                source: RegionNameSource::AnonRegionFromArgument(highlight),
-            });
-        }
-
-        let counter = *self.next_region_name.try_borrow().unwrap();
-        if let Some(highlight) = self.highlight_if_we_cannot_match_hir_ty(fr, arg_ty, counter) {
-            Some(RegionName {
-                // This counter value will already have been used, so this function will increment
-                // it so the next value will be used next and return the region name that would
-                // have been used.
+        self.highlight_if_we_can_match_hir_ty_from_argument(fr, arg_ty, argument_index)
+            .or_else(|| {
+                // `highlight_if_we_cannot_match_hir_ty` needs to know the number we will give to
+                // the anonymous region. If it succeeds, the `synthesize_region_name` call below
+                // will increment the counter, "reserving" the number we just used.
+                let counter = *self.next_region_name.try_borrow().unwrap();
+                self.highlight_if_we_cannot_match_hir_ty(fr, arg_ty, counter)
+            })
+            .map(|highlight| RegionName {
                 name: self.synthesize_region_name(),
                 source: RegionNameSource::AnonRegionFromArgument(highlight),
             })
-        } else {
-            None
-        }
     }
 
     fn highlight_if_we_can_match_hir_ty_from_argument(