Skip to content

Commit 9e3889e

Browse files
committed
Refactor region naming for control of diagnostics.
Previously, region naming would always highlight the source of the region name it found. Now, region naming returns the name as part of a larger structure that encodes the source of the region naming such that a region name can be optionally added to the diagnostic.
1 parent 10af6a2 commit 9e3889e

File tree

2 files changed

+168
-125
lines changed

2 files changed

+168
-125
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
339339
);
340340

341341
let counter = &mut 1;
342-
let fr_name = self.give_region_a_name(
343-
infcx, mir, mir_def_id, fr, counter, &mut diag);
342+
let fr_name = self.give_region_a_name(infcx, mir, mir_def_id, fr, counter);
343+
fr_name.highlight_region_name(&mut diag);
344344
let outlived_fr_name = self.give_region_a_name(
345-
infcx, mir, mir_def_id, outlived_fr, counter, &mut diag);
345+
infcx, mir, mir_def_id, outlived_fr, counter);
346+
outlived_fr_name.highlight_region_name(&mut diag);
346347

347348
let mir_def_name = if infcx.tcx.is_closure(mir_def_id) { "closure" } else { "function" };
348349

@@ -430,10 +431,12 @@ impl<'tcx> RegionInferenceContext<'tcx> {
430431
// Otherwise, we should suggest adding a constraint on the return type.
431432
let span = infcx.tcx.def_span(*did);
432433
if let Ok(snippet) = infcx.tcx.sess.source_map().span_to_snippet(span) {
433-
let suggestable_fr_name = match fr_name {
434-
RegionName::Named(name) => format!("{}", name),
435-
RegionName::Synthesized(_) => "'_".to_string(),
434+
let suggestable_fr_name = if fr_name.was_named() {
435+
format!("{}", fr_name)
436+
} else {
437+
"'_".to_string()
436438
};
439+
437440
diag.span_suggestion_with_applicability(
438441
span,
439442
&format!(

0 commit comments

Comments
 (0)