Skip to content

Commit a804868

Browse files
committed
Get rid of RegionErrorNamingContext
1 parent 234b930 commit a804868

File tree

8 files changed

+88
-171
lines changed

8 files changed

+88
-171
lines changed

src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use rustc_span::symbol::Symbol;
1616
use rustc_span::Span;
1717

1818
use crate::borrow_check::{
19-
borrow_set::BorrowData, diagnostics::RegionErrorNamingCtx, nll::ConstraintDescription,
20-
region_infer::Cause, MirBorrowckCtxt, WriteKind,
19+
borrow_set::BorrowData, nll::ConstraintDescription, region_infer::Cause, MirBorrowckCtxt,
20+
WriteKind,
2121
};
2222

2323
use super::{find_use, RegionName, UseSpans};
@@ -267,8 +267,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
267267
|r| self.regioncx.provides_universal_region(r, borrow_region, outlived_region),
268268
);
269269

270-
let mut renctx = RegionErrorNamingCtx::new();
271-
let outlived_fr_name = self.give_region_a_name(&mut renctx, outlived_region);
270+
let outlived_fr_name = self.give_region_a_name(outlived_region);
272271

273272
(category, from_closure, span, outlived_fr_name)
274273
}

src/librustc_mir/borrow_check/diagnostics/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ mod region_errors;
3232
crate use mutability_errors::AccessKind;
3333
crate use outlives_suggestion::OutlivesSuggestionBuilder;
3434
crate use region_errors::{ErrorConstraintInfo, RegionErrorKind, RegionErrors};
35-
crate use region_name::{RegionErrorNamingCtx, RegionName, RegionNameSource};
35+
crate use region_name::{RegionName, RegionNameSource};
3636

3737
pub(super) struct IncludingDowncast(pub(super) bool);
3838

src/librustc_mir/borrow_check/diagnostics/outlives_suggestion.rs

+8-17
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use smallvec::SmallVec;
1212

1313
use crate::borrow_check::MirBorrowckCtxt;
1414

15-
use super::{ErrorConstraintInfo, RegionErrorNamingCtx, RegionName, RegionNameSource};
15+
use super::{ErrorConstraintInfo, RegionName, RegionNameSource};
1616

1717
/// The different things we could suggest.
1818
enum SuggestedConstraint {
@@ -77,17 +77,15 @@ impl OutlivesSuggestionBuilder {
7777
fn region_vid_to_name(
7878
&self,
7979
mbcx: &MirBorrowckCtxt<'_, '_>,
80-
renctx: &mut RegionErrorNamingCtx,
8180
region: RegionVid,
8281
) -> Option<RegionName> {
83-
mbcx.give_region_a_name(renctx, region).filter(Self::region_name_is_suggestable)
82+
mbcx.give_region_a_name(region).filter(Self::region_name_is_suggestable)
8483
}
8584

8685
/// Compiles a list of all suggestions to be printed in the final big suggestion.
8786
fn compile_all_suggestions(
8887
&self,
8988
mbcx: &MirBorrowckCtxt<'_, '_>,
90-
renctx: &mut RegionErrorNamingCtx,
9189
) -> SmallVec<[SuggestedConstraint; 2]> {
9290
let mut suggested = SmallVec::new();
9391

@@ -96,7 +94,7 @@ impl OutlivesSuggestionBuilder {
9694
let mut unified_already = FxHashSet::default();
9795

9896
for (fr, outlived) in &self.constraints_to_add {
99-
let fr_name = if let Some(fr_name) = self.region_vid_to_name(mbcx, renctx, *fr) {
97+
let fr_name = if let Some(fr_name) = self.region_vid_to_name(mbcx, *fr) {
10098
fr_name
10199
} else {
102100
continue;
@@ -105,9 +103,7 @@ impl OutlivesSuggestionBuilder {
105103
let outlived = outlived
106104
.iter()
107105
// if there is a `None`, we will just omit that constraint
108-
.filter_map(|fr| {
109-
self.region_vid_to_name(mbcx, renctx, *fr).map(|rname| (fr, rname))
110-
})
106+
.filter_map(|fr| self.region_vid_to_name(mbcx, *fr).map(|rname| (fr, rname)))
111107
.collect::<Vec<_>>();
112108

113109
// No suggestable outlived lifetimes.
@@ -171,12 +167,11 @@ impl OutlivesSuggestionBuilder {
171167
&mut self,
172168
mbcx: &MirBorrowckCtxt<'_, '_>,
173169
errci: &ErrorConstraintInfo,
174-
renctx: &mut RegionErrorNamingCtx,
175170
diag: &mut DiagnosticBuilder<'_>,
176171
) {
177172
// Emit an intermediate note.
178-
let fr_name = self.region_vid_to_name(mbcx, renctx, errci.fr);
179-
let outlived_fr_name = self.region_vid_to_name(mbcx, renctx, errci.outlived_fr);
173+
let fr_name = self.region_vid_to_name(mbcx, errci.fr);
174+
let outlived_fr_name = self.region_vid_to_name(mbcx, errci.outlived_fr);
180175

181176
if let (Some(fr_name), Some(outlived_fr_name)) = (fr_name, outlived_fr_name) {
182177
if let RegionNameSource::Static = outlived_fr_name.source {
@@ -192,11 +187,7 @@ impl OutlivesSuggestionBuilder {
192187

193188
/// If there is a suggestion to emit, add a diagnostic to the buffer. This is the final
194189
/// suggestion including all collected constraints.
195-
crate fn add_suggestion(
196-
&self,
197-
mbcx: &mut MirBorrowckCtxt<'_, '_>,
198-
renctx: &mut RegionErrorNamingCtx,
199-
) {
190+
crate fn add_suggestion(&self, mbcx: &mut MirBorrowckCtxt<'_, '_>) {
200191
// No constraints to add? Done.
201192
if self.constraints_to_add.is_empty() {
202193
debug!("No constraints to suggest.");
@@ -213,7 +204,7 @@ impl OutlivesSuggestionBuilder {
213204
}
214205

215206
// Get all suggestable constraints.
216-
let suggested = self.compile_all_suggestions(mbcx, renctx);
207+
let suggested = self.compile_all_suggestions(mbcx);
217208

218209
// If there are no suggestable constraints...
219210
if suggested.is_empty() {

src/librustc_mir/borrow_check/diagnostics/region_errors.rs

+18-33
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::borrow_check::{
1919
MirBorrowckCtxt,
2020
};
2121

22-
use super::{OutlivesSuggestionBuilder, RegionErrorNamingCtx, RegionName, RegionNameSource};
22+
use super::{OutlivesSuggestionBuilder, RegionName, RegionNameSource};
2323

2424
impl ConstraintDescription for ConstraintCategory {
2525
fn description(&self) -> &'static str {
@@ -152,8 +152,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
152152
// Iterate through all the errors, producing a diagnostic for each one. The diagnostics are
153153
// buffered in the `MirBorrowckCtxt`.
154154

155-
// TODO(mark-i-m): Would be great to get rid of the naming context.
156-
let mut region_naming = RegionErrorNamingCtx::new();
157155
let mut outlives_suggestion = OutlivesSuggestionBuilder::default();
158156

159157
for nll_error in nll_errors.into_iter() {
@@ -243,7 +241,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
243241
fr_origin,
244242
shorter_fr,
245243
&mut outlives_suggestion,
246-
&mut region_naming,
247244
);
248245
} else {
249246
// We only report the first error, so as not to overwhelm the user. See
@@ -262,7 +259,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
262259
}
263260

264261
// Emit one outlives suggestions for each MIR def we borrowck
265-
outlives_suggestion.add_suggestion(self, &mut region_naming);
262+
outlives_suggestion.add_suggestion(self);
266263
}
267264

268265
/// Report an error because the universal region `fr` was required to outlive
@@ -279,7 +276,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
279276
fr_origin: NLLRegionVariableOrigin,
280277
outlived_fr: RegionVid,
281278
outlives_suggestion: &mut OutlivesSuggestionBuilder,
282-
renctx: &mut RegionErrorNamingCtx,
283279
) {
284280
debug!("report_error(fr={:?}, outlived_fr={:?})", fr, outlived_fr);
285281

@@ -320,21 +316,21 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
320316

321317
let diag = match (category, fr_is_local, outlived_fr_is_local) {
322318
(ConstraintCategory::Return, true, false) if self.is_closure_fn_mut(fr) => {
323-
self.report_fnmut_error(&errci, renctx)
319+
self.report_fnmut_error(&errci)
324320
}
325321
(ConstraintCategory::Assignment, true, false)
326322
| (ConstraintCategory::CallArgument, true, false) => {
327-
let mut db = self.report_escaping_data_error(&errci, renctx);
323+
let mut db = self.report_escaping_data_error(&errci);
328324

329-
outlives_suggestion.intermediate_suggestion(self, &errci, renctx, &mut db);
325+
outlives_suggestion.intermediate_suggestion(self, &errci, &mut db);
330326
outlives_suggestion.collect_constraint(fr, outlived_fr);
331327

332328
db
333329
}
334330
_ => {
335-
let mut db = self.report_general_error(&errci, renctx);
331+
let mut db = self.report_general_error(&errci);
336332

337-
outlives_suggestion.intermediate_suggestion(self, &errci, renctx, &mut db);
333+
outlives_suggestion.intermediate_suggestion(self, &errci, &mut db);
338334
outlives_suggestion.collect_constraint(fr, outlived_fr);
339335

340336
db
@@ -360,11 +356,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
360356
/// executing...
361357
/// = note: ...therefore, returned references to captured variables will escape the closure
362358
/// ```
363-
fn report_fnmut_error(
364-
&self,
365-
errci: &ErrorConstraintInfo,
366-
renctx: &mut RegionErrorNamingCtx,
367-
) -> DiagnosticBuilder<'tcx> {
359+
fn report_fnmut_error(&self, errci: &ErrorConstraintInfo) -> DiagnosticBuilder<'tcx> {
368360
let ErrorConstraintInfo { outlived_fr, span, .. } = errci;
369361

370362
let mut diag = self
@@ -386,7 +378,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
386378

387379
diag.span_label(*span, message);
388380

389-
match self.give_region_a_name(renctx, *outlived_fr).unwrap().source {
381+
match self.give_region_a_name(*outlived_fr).unwrap().source {
390382
RegionNameSource::NamedEarlyBoundRegion(fr_span)
391383
| RegionNameSource::NamedFreeRegion(fr_span)
392384
| RegionNameSource::SynthesizedFreeEnvRegion(fr_span, _)
@@ -421,11 +413,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
421413
/// LL | ref_obj(x)
422414
/// | ^^^^^^^^^^ `x` escapes the function body here
423415
/// ```
424-
fn report_escaping_data_error(
425-
&self,
426-
errci: &ErrorConstraintInfo,
427-
renctx: &mut RegionErrorNamingCtx,
428-
) -> DiagnosticBuilder<'tcx> {
416+
fn report_escaping_data_error(&self, errci: &ErrorConstraintInfo) -> DiagnosticBuilder<'tcx> {
429417
let ErrorConstraintInfo { span, category, .. } = errci;
430418

431419
let fr_name_and_span = self.regioncx.get_var_name_and_span_for_region(
@@ -456,10 +444,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
456444
|| (*category == ConstraintCategory::Assignment && escapes_from == "function")
457445
|| escapes_from == "const"
458446
{
459-
return self.report_general_error(
460-
&ErrorConstraintInfo { fr_is_local: true, outlived_fr_is_local: false, ..*errci },
461-
renctx,
462-
);
447+
return self.report_general_error(&ErrorConstraintInfo {
448+
fr_is_local: true,
449+
outlived_fr_is_local: false,
450+
..*errci
451+
});
463452
}
464453

465454
let mut diag =
@@ -505,11 +494,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
505494
/// | ^^^^^^^^^^^^^^ function was supposed to return data with lifetime `'a` but it
506495
/// | is returning data with lifetime `'b`
507496
/// ```
508-
fn report_general_error(
509-
&self,
510-
errci: &ErrorConstraintInfo,
511-
renctx: &mut RegionErrorNamingCtx,
512-
) -> DiagnosticBuilder<'tcx> {
497+
fn report_general_error(&self, errci: &ErrorConstraintInfo) -> DiagnosticBuilder<'tcx> {
513498
let ErrorConstraintInfo {
514499
fr,
515500
fr_is_local,
@@ -526,9 +511,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
526511
let mir_def_name =
527512
if self.infcx.tcx.is_closure(self.mir_def_id) { "closure" } else { "function" };
528513

529-
let fr_name = self.give_region_a_name(renctx, *fr).unwrap();
514+
let fr_name = self.give_region_a_name(*fr).unwrap();
530515
fr_name.highlight_region_name(&mut diag);
531-
let outlived_fr_name = self.give_region_a_name(renctx, *outlived_fr).unwrap();
516+
let outlived_fr_name = self.give_region_a_name(*outlived_fr).unwrap();
532517
outlived_fr_name.highlight_region_name(&mut diag);
533518

534519
match (category, outlived_fr_is_local, fr_is_local) {

0 commit comments

Comments
 (0)