diff options
| author | SNCPlay42 <SNCPlay42@gmail.com> | 2020-07-22 20:38:44 +0100 |
|---|---|---|
| committer | SNCPlay42 <SNCPlay42@gmail.com> | 2020-07-22 23:52:49 +0100 |
| commit | b56f5b9df5a41fbf3c82310b5c3d901b0b0f78dc (patch) | |
| tree | abaa42934ae5167a379483a5c6fc038e37a23927 /src | |
| parent | 723ea909929498380615f56e652660229adcdfef (diff) | |
| download | rust-b56f5b9df5a41fbf3c82310b5c3d901b0b0f78dc.tar.gz rust-b56f5b9df5a41fbf3c82310b5c3d901b0b0f78dc.zip | |
clean up give_name_if_anonymous_region_appears_in_arguments
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_mir/borrow_check/diagnostics/region_name.rs | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/src/librustc_mir/borrow_check/diagnostics/region_name.rs b/src/librustc_mir/borrow_check/diagnostics/region_name.rs index 9e5851fd811..da86a0c3bb9 100644 --- a/src/librustc_mir/borrow_check/diagnostics/region_name.rs +++ b/src/librustc_mir/borrow_check/diagnostics/region_name.rs @@ -336,27 +336,18 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> { 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( |
