Skip to content

Commit 6cc318b

Browse files
committed
Clean up error handling FIXMEs
1 parent 2fd67ac commit 6cc318b

File tree

2 files changed

+27
-54
lines changed

2 files changed

+27
-54
lines changed

compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

+8-46
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use rustc_traits::{type_op_ascribe_user_type_with_span, type_op_prove_predicate_
2424
use tracing::{debug, instrument};
2525

2626
use crate::MirBorrowckCtxt;
27-
use crate::region_infer::values::RegionElement;
2827
use crate::session_diagnostics::{
2928
HigherRankedErrorCause, HigherRankedLifetimeError, HigherRankedSubtypeError,
3029
};
@@ -54,26 +53,11 @@ impl<'tcx> UniverseInfo<'tcx> {
5453
&self,
5554
mbcx: &mut MirBorrowckCtxt<'_, '_, 'tcx>,
5655
placeholder: ty::PlaceholderRegion,
57-
error_element: RegionElement,
5856
cause: ObligationCause<'tcx>,
57+
error_element: Option<ty::PlaceholderRegion>,
5958
) {
6059
if let UniverseInfo::TypeOp(ref type_op_info) = *self {
61-
type_op_info.report_erroneous_element(mbcx, placeholder, error_element, cause);
62-
} else {
63-
self.report_generic_error(mbcx, cause);
64-
}
65-
}
66-
67-
/// Report an error where a placeholder erroneously outlives another.
68-
pub(crate) fn report_placeholder_mismatch(
69-
&self,
70-
mbcx: &mut MirBorrowckCtxt<'_, '_, 'tcx>,
71-
placeholder_a: ty::PlaceholderRegion,
72-
cause: ObligationCause<'tcx>,
73-
placeholder_b: ty::PlaceholderRegion,
74-
) {
75-
if let UniverseInfo::TypeOp(ref type_op_info) = *self {
76-
type_op_info.report_placeholder_mismatch(mbcx, placeholder_a, cause, placeholder_b);
60+
type_op_info.report_erroneous_element(mbcx, placeholder, cause, error_element);
7761
} else {
7862
self.report_generic_error(mbcx, cause);
7963
}
@@ -173,28 +157,6 @@ pub(crate) trait TypeOpInfo<'tcx> {
173157
error_region: Option<ty::Region<'tcx>>,
174158
) -> Option<Diag<'infcx>>;
175159

176-
#[instrument(level = "debug", skip(self, mbcx))]
177-
fn report_placeholder_mismatch(
178-
&self,
179-
mbcx: &mut MirBorrowckCtxt<'_, '_, 'tcx>,
180-
placeholder_a: ty::PlaceholderRegion,
181-
cause: ObligationCause<'tcx>,
182-
placeholder_b: ty::PlaceholderRegion,
183-
) {
184-
let tcx = mbcx.infcx.tcx;
185-
186-
let placeholder_a = self.region_with_adjusted_universe(placeholder_a, tcx);
187-
let placeholder_b = self.region_with_adjusted_universe(placeholder_b, tcx);
188-
189-
debug!(?placeholder_a, ?placeholder_b);
190-
191-
let span = cause.span;
192-
// FIXME: see note in `report_erroneous_element()` below!
193-
let nice_error = self.nice_error(mbcx, cause, placeholder_a, Some(placeholder_b));
194-
debug!(?nice_error);
195-
mbcx.buffer_error(nice_error.unwrap_or_else(|| self.fallback_error(tcx, span)));
196-
}
197-
198160
/// Turn a placeholder region into a Region with its universe adjusted by
199161
/// the base universe.
200162
fn region_with_adjusted_universe(
@@ -217,13 +179,16 @@ pub(crate) trait TypeOpInfo<'tcx> {
217179
)
218180
}
219181

182+
/// Report an error where an erroneous element reaches `placeholder`.
183+
/// The erroneous element is either another placeholder that we provide,
184+
/// or we figure out what happened later.
220185
#[instrument(level = "debug", skip(self, mbcx))]
221186
fn report_erroneous_element(
222187
&self,
223188
mbcx: &mut MirBorrowckCtxt<'_, '_, 'tcx>,
224189
placeholder: ty::PlaceholderRegion,
225-
error_element: RegionElement,
226190
cause: ObligationCause<'tcx>,
191+
error_element: Option<ty::PlaceholderRegion>,
227192
) {
228193
let tcx = mbcx.infcx.tcx;
229194

@@ -234,15 +199,12 @@ pub(crate) trait TypeOpInfo<'tcx> {
234199
// In fact, this function throws away a lot of interesting information that would
235200
// probably allow bypassing lots of logic downstream for a much simpler flow.
236201
let placeholder_region = self.region_with_adjusted_universe(placeholder, tcx);
202+
let error_element = error_element.map(|e| self.region_with_adjusted_universe(e, tcx));
237203

238204
debug!(?placeholder_region);
239205

240206
let span = cause.span;
241-
// FIXME: it's not good that we have one variant that always sends None,
242-
// and one variant with always sends Some. We should break out these code
243-
// paths -- but the downstream code is complicated and that's not straight-
244-
// forward.
245-
let nice_error = self.nice_error(mbcx, cause, placeholder_region, None);
207+
let nice_error = self.nice_error(mbcx, cause, placeholder_region, error_element);
246208

247209
debug!(?nice_error);
248210
mbcx.buffer_error(nice_error.unwrap_or_else(|| self.fallback_error(tcx, span)));

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+19-8
Original file line numberDiff line numberDiff line change
@@ -422,11 +422,16 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
422422
error_vid,
423423
);
424424

425-
let universe = placeholder.universe;
426-
let universe_info = self.regioncx.universe_info(universe);
427-
428-
// FIXME(amandasystems) -- these methods should have better names, and also probably not be this generic.
429-
universe_info.report_erroneous_element(self, placeholder, error_element, cause);
425+
// FIXME these methods should have better names, and also probably not be this generic.
426+
// FIXME note that we *throw away* the error element here! We probably want to
427+
// thread it through the computation further down and use it, but there currently isn't
428+
// anything there to receive it.
429+
self.regioncx.universe_info(placeholder.universe).report_erroneous_element(
430+
self,
431+
placeholder,
432+
cause,
433+
None,
434+
);
430435
}
431436

432437
RegionErrorKind::PlaceholderMismatch { rvid_a, rvid_b, origin_a, origin_b } => {
@@ -440,9 +445,15 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
440445
rvid_b,
441446
);
442447

443-
self.regioncx
444-
.universe_info(origin_a.universe)
445-
.report_placeholder_mismatch(self, origin_a, cause, origin_b);
448+
// FIXME We may be able to shorten the code path here, and immediately
449+
// report a `RegionResolutionError::UpperBoundUniverseConflict`, but
450+
// that's left for a future refactoring.
451+
self.regioncx.universe_info(origin_a.universe).report_erroneous_element(
452+
self,
453+
origin_a,
454+
cause,
455+
Some(origin_b),
456+
);
446457
}
447458

448459
RegionErrorKind::RegionError { fr_origin, longer_fr, shorter_fr, is_reported } => {

0 commit comments

Comments
 (0)