Skip to content

Commit a7450b7

Browse files
committed
decouple highlight_if_we_cannot_match_hir_ty
1 parent b56f5b9 commit a7450b7

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/librustc_mir/borrow_check/diagnostics/region_name.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -336,13 +336,19 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
336336

337337
let arg_ty = self.regioncx.universal_regions().unnormalized_input_tys
338338
[implicit_inputs + argument_index];
339+
let (_, span) = self.regioncx.get_argument_name_and_span_for_region(
340+
&self.body,
341+
&self.local_names,
342+
argument_index,
343+
);
344+
339345
self.highlight_if_we_can_match_hir_ty_from_argument(fr, arg_ty, argument_index)
340346
.or_else(|| {
341347
// `highlight_if_we_cannot_match_hir_ty` needs to know the number we will give to
342348
// the anonymous region. If it succeeds, the `synthesize_region_name` call below
343349
// will increment the counter, "reserving" the number we just used.
344350
let counter = *self.next_region_name.try_borrow().unwrap();
345-
self.highlight_if_we_cannot_match_hir_ty(fr, arg_ty, counter)
351+
self.highlight_if_we_cannot_match_hir_ty(fr, arg_ty, span, counter)
346352
})
347353
.map(|highlight| RegionName {
348354
name: self.synthesize_region_name(),
@@ -385,26 +391,20 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
385391
fn highlight_if_we_cannot_match_hir_ty(
386392
&self,
387393
needle_fr: RegionVid,
388-
argument_ty: Ty<'tcx>,
394+
ty: Ty<'tcx>,
395+
span: Span,
389396
counter: usize,
390397
) -> Option<RegionNameHighlight> {
391398
let mut highlight = RegionHighlightMode::default();
392399
highlight.highlighting_region_vid(needle_fr, counter);
393-
let type_name = self.infcx.extract_type_name(&argument_ty, Some(highlight)).0;
400+
let type_name = self.infcx.extract_type_name(&ty, Some(highlight)).0;
394401

395402
debug!(
396403
"highlight_if_we_cannot_match_hir_ty: type_name={:?} needle_fr={:?}",
397404
type_name, needle_fr
398405
);
399406
if type_name.find(&format!("'{}", counter)).is_some() {
400407
// Only add a label if we can confirm that a region was labelled.
401-
let argument_index =
402-
self.regioncx.get_argument_index_for_region(self.infcx.tcx, needle_fr)?;
403-
let (_, span) = self.regioncx.get_argument_name_and_span_for_region(
404-
&self.body,
405-
&self.local_names,
406-
argument_index,
407-
);
408408

409409
Some(RegionNameHighlight::CannotMatchHirTy(span, type_name))
410410
} else {

0 commit comments

Comments
 (0)