Skip to content

Commit b56f5b9

Browse files
committed
clean up give_name_if_anonymous_region_appears_in_arguments
1 parent 723ea90 commit b56f5b9

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

src/librustc_mir/borrow_check/diagnostics/region_name.rs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -336,27 +336,18 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
336336

337337
let arg_ty = self.regioncx.universal_regions().unnormalized_input_tys
338338
[implicit_inputs + argument_index];
339-
if let Some(highlight) =
340-
self.highlight_if_we_can_match_hir_ty_from_argument(fr, arg_ty, argument_index)
341-
{
342-
return Some(RegionName {
343-
name: self.synthesize_region_name(),
344-
source: RegionNameSource::AnonRegionFromArgument(highlight),
345-
});
346-
}
347-
348-
let counter = *self.next_region_name.try_borrow().unwrap();
349-
if let Some(highlight) = self.highlight_if_we_cannot_match_hir_ty(fr, arg_ty, counter) {
350-
Some(RegionName {
351-
// This counter value will already have been used, so this function will increment
352-
// it so the next value will be used next and return the region name that would
353-
// have been used.
339+
self.highlight_if_we_can_match_hir_ty_from_argument(fr, arg_ty, argument_index)
340+
.or_else(|| {
341+
// `highlight_if_we_cannot_match_hir_ty` needs to know the number we will give to
342+
// the anonymous region. If it succeeds, the `synthesize_region_name` call below
343+
// will increment the counter, "reserving" the number we just used.
344+
let counter = *self.next_region_name.try_borrow().unwrap();
345+
self.highlight_if_we_cannot_match_hir_ty(fr, arg_ty, counter)
346+
})
347+
.map(|highlight| RegionName {
354348
name: self.synthesize_region_name(),
355349
source: RegionNameSource::AnonRegionFromArgument(highlight),
356350
})
357-
} else {
358-
None
359-
}
360351
}
361352

362353
fn highlight_if_we_can_match_hir_ty_from_argument(

0 commit comments

Comments
 (0)