Skip to content

Commit 11b8e16

Browse files
authored
Rollup merge of #66684 - mark-i-m:error-reporting-cleanup, r=davidtwco
Drive-by cleanup in region naming
2 parents b6dc227 + 135c8b9 commit 11b8e16

File tree

1 file changed

+21
-22
lines changed
  • src/librustc_mir/borrow_check/nll/region_infer/error_reporting

1 file changed

+21
-22
lines changed

src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs

+21-22
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,30 @@ impl RegionErrorNamingCtx {
7777
}
7878
}
7979

80+
/// Get the name of `region` if it has previously been named.
8081
crate fn get(&self, region: &RegionVid) -> Option<&RegionName> {
8182
self.renctx.get(region)
8283
}
8384

85+
/// Give `region` the name `name`.
8486
crate fn insert(&mut self, region: RegionVid, name: RegionName) {
8587
self.renctx.insert(region, name);
8688
}
89+
90+
/// Creates a synthetic region named `'N`, where `N` is the next value of the counter. Then,
91+
/// increment the counter.
92+
///
93+
/// The name is not memoized. A separate call to `insert` should be made later. (Currently,
94+
/// this happens at the end of `give_region_a_name`).
95+
crate fn synthesize_region_name(&mut self) -> Symbol {
96+
let c = self.counter;
97+
self.counter += 1;
98+
99+
Symbol::intern(&format!("'{:?}", c))
100+
}
87101
}
88102

89103
impl RegionName {
90-
#[allow(dead_code)]
91104
crate fn was_named(&self) -> bool {
92105
match self.source {
93106
RegionNameSource::NamedEarlyBoundRegion(..) |
@@ -103,12 +116,6 @@ impl RegionName {
103116
}
104117
}
105118

106-
#[allow(dead_code)]
107-
crate fn was_synthesized(&self) -> bool {
108-
!self.was_named()
109-
}
110-
111-
#[allow(dead_code)]
112119
crate fn name(&self) -> Symbol {
113120
self.name
114121
}
@@ -298,7 +305,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
298305
} else {
299306
bug!("Closure is not defined by a closure expr");
300307
};
301-
let region_name = self.synthesize_region_name(renctx);
308+
let region_name = renctx.synthesize_region_name();
302309

303310
let closure_kind_ty = substs.as_closure().kind_ty(def_id, tcx);
304311
let note = match closure_kind_ty.to_opt_closure_kind() {
@@ -478,7 +485,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
478485
// This counter value will already have been used, so this function will increment
479486
// it so the next value will be used next and return the region name that would
480487
// have been used.
481-
name: self.synthesize_region_name(renctx),
488+
name: renctx.synthesize_region_name(),
482489
source: RegionNameSource::CannotMatchHirTy(span, type_name),
483490
})
484491
} else {
@@ -533,7 +540,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
533540
hir::TyKind::Rptr(_lifetime, referent_hir_ty),
534541
) => {
535542
if region.to_region_vid() == needle_fr {
536-
let region_name = self.synthesize_region_name(renctx);
543+
let region_name = renctx.synthesize_region_name();
537544

538545
// Just grab the first character, the `&`.
539546
let source_map = tcx.sess.source_map();
@@ -621,7 +628,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
621628
| hir::LifetimeName::Error
622629
| hir::LifetimeName::Static
623630
| hir::LifetimeName::Underscore => {
624-
let region_name = self.synthesize_region_name(renctx);
631+
let region_name = renctx.synthesize_region_name();
625632
let ampersand_span = lifetime.span;
626633
Some(RegionName {
627634
name: region_name,
@@ -713,7 +720,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
713720
let upvar_index = self.get_upvar_index_for_region(tcx, fr)?;
714721
let (upvar_name, upvar_span) =
715722
self.get_upvar_name_and_span_for_region(tcx, upvars, upvar_index);
716-
let region_name = self.synthesize_region_name(renctx);
723+
let region_name = renctx.synthesize_region_name();
717724

718725
Some(RegionName {
719726
name: region_name,
@@ -776,7 +783,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
776783
// This counter value will already have been used, so this function will increment it
777784
// so the next value will be used next and return the region name that would have been
778785
// used.
779-
name: self.synthesize_region_name(renctx),
786+
name: renctx.synthesize_region_name(),
780787
source: RegionNameSource::AnonRegionFromOutput(
781788
return_span,
782789
mir_description.to_string(),
@@ -831,16 +838,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
831838
);
832839

833840
Some(RegionName {
834-
name: self.synthesize_region_name(renctx),
841+
name: renctx.synthesize_region_name(),
835842
source: RegionNameSource::AnonRegionFromYieldTy(yield_span, type_name),
836843
})
837844
}
838-
839-
/// Creates a synthetic region named `'1`, incrementing the counter.
840-
fn synthesize_region_name(&self, renctx: &mut RegionErrorNamingCtx) -> Symbol {
841-
let c = renctx.counter;
842-
renctx.counter += 1;
843-
844-
Symbol::intern(&format!("'{:?}", c))
845-
}
846845
}

0 commit comments

Comments
 (0)