2019-02-05 18:20:45 +01:00
|
|
|
use crate::infer::lexical_region_resolve::RegionResolutionError;
|
|
|
|
use crate::infer::lexical_region_resolve::RegionResolutionError::*;
|
2019-12-22 23:42:04 +01:00
|
|
|
use crate::infer::InferCtxt;
|
2019-02-05 18:20:45 +01:00
|
|
|
use crate::ty::{self, TyCtxt};
|
|
|
|
use crate::util::common::ErrorReported;
|
2020-01-09 11:18:47 +01:00
|
|
|
use rustc_errors::DiagnosticBuilder;
|
2020-01-01 19:25:28 +01:00
|
|
|
use rustc_span::source_map::Span;
|
2017-12-12 14:31:38 +01:00
|
|
|
|
2017-12-12 13:52:25 +01:00
|
|
|
mod different_lifetimes;
|
2017-12-12 14:39:20 +01:00
|
|
|
mod find_anon_type;
|
2017-12-12 13:52:25 +01:00
|
|
|
mod named_anon_conflict;
|
2018-01-15 19:55:10 +01:00
|
|
|
mod outlives_closure;
|
2019-12-22 23:42:04 +01:00
|
|
|
mod placeholder_error;
|
2018-06-08 08:07:46 +02:00
|
|
|
mod static_impl_trait;
|
2019-10-03 20:41:27 +02:00
|
|
|
mod trait_impl_difference;
|
2017-12-12 14:39:20 +01:00
|
|
|
mod util;
|
2017-12-12 14:31:38 +01:00
|
|
|
|
2019-06-13 23:48:52 +02:00
|
|
|
impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
2017-12-12 14:31:38 +01:00
|
|
|
pub fn try_report_nice_region_error(&self, error: &RegionResolutionError<'tcx>) -> bool {
|
2018-01-15 19:55:10 +01:00
|
|
|
match *error {
|
|
|
|
ConcreteFailure(..) | SubSupConflict(..) => {}
|
2019-12-22 23:42:04 +01:00
|
|
|
_ => return false, // inapplicable
|
2018-01-15 19:55:10 +01:00
|
|
|
}
|
2017-12-12 14:31:38 +01:00
|
|
|
|
|
|
|
if let Some(tables) = self.in_progress_tables {
|
|
|
|
let tables = tables.borrow();
|
2019-01-25 18:22:44 +01:00
|
|
|
NiceRegionError::new(self, error.clone(), Some(&tables)).try_report().is_some()
|
2017-12-12 14:31:38 +01:00
|
|
|
} else {
|
2019-01-25 18:22:44 +01:00
|
|
|
NiceRegionError::new(self, error.clone(), None).try_report().is_some()
|
2017-12-12 14:31:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-14 18:39:39 +02:00
|
|
|
pub struct NiceRegionError<'cx, 'tcx> {
|
2019-06-13 23:48:52 +02:00
|
|
|
infcx: &'cx InferCtxt<'cx, 'tcx>,
|
2018-01-15 19:55:10 +01:00
|
|
|
error: Option<RegionResolutionError<'tcx>>,
|
|
|
|
regions: Option<(Span, ty::Region<'tcx>, ty::Region<'tcx>)>,
|
2017-12-12 14:31:38 +01:00
|
|
|
tables: Option<&'cx ty::TypeckTables<'tcx>>,
|
|
|
|
}
|
|
|
|
|
2019-06-13 23:48:52 +02:00
|
|
|
impl<'cx, 'tcx> NiceRegionError<'cx, 'tcx> {
|
2017-12-12 14:31:38 +01:00
|
|
|
pub fn new(
|
2019-06-13 23:48:52 +02:00
|
|
|
infcx: &'cx InferCtxt<'cx, 'tcx>,
|
2018-01-15 19:55:10 +01:00
|
|
|
error: RegionResolutionError<'tcx>,
|
|
|
|
tables: Option<&'cx ty::TypeckTables<'tcx>>,
|
|
|
|
) -> Self {
|
2019-01-25 18:22:44 +01:00
|
|
|
Self { infcx, error: Some(error), regions: None, tables }
|
2018-01-15 19:55:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn new_from_span(
|
2019-06-13 23:48:52 +02:00
|
|
|
infcx: &'cx InferCtxt<'cx, 'tcx>,
|
2017-12-12 14:31:38 +01:00
|
|
|
span: Span,
|
|
|
|
sub: ty::Region<'tcx>,
|
|
|
|
sup: ty::Region<'tcx>,
|
|
|
|
tables: Option<&'cx ty::TypeckTables<'tcx>>,
|
|
|
|
) -> Self {
|
2019-01-25 18:22:44 +01:00
|
|
|
Self { infcx, error: None, regions: Some((span, sub, sup)), tables }
|
|
|
|
}
|
|
|
|
|
2019-06-13 23:48:52 +02:00
|
|
|
fn tcx(&self) -> TyCtxt<'tcx> {
|
2019-01-25 18:22:44 +01:00
|
|
|
self.infcx.tcx
|
2017-12-12 14:31:38 +01:00
|
|
|
}
|
|
|
|
|
2019-02-06 14:11:09 +01:00
|
|
|
pub fn try_report_from_nll(&self) -> Option<DiagnosticBuilder<'cx>> {
|
2018-08-06 18:33:05 +02:00
|
|
|
// Due to the improved diagnostics returned by the MIR borrow checker, only a subset of
|
|
|
|
// the nice region errors are required when running under the MIR borrow checker.
|
2019-12-22 23:42:04 +01:00
|
|
|
self.try_report_named_anon_conflict().or_else(|| self.try_report_placeholder_conflict())
|
2018-08-06 18:33:05 +02:00
|
|
|
}
|
|
|
|
|
2017-12-12 14:39:20 +01:00
|
|
|
pub fn try_report(&self) -> Option<ErrorReported> {
|
2018-11-17 14:18:37 +01:00
|
|
|
self.try_report_from_nll()
|
2019-12-22 23:42:04 +01:00
|
|
|
.map(|mut diag| {
|
|
|
|
diag.emit();
|
|
|
|
ErrorReported
|
|
|
|
})
|
2017-12-12 15:05:54 +01:00
|
|
|
.or_else(|| self.try_report_anon_anon_conflict())
|
2018-01-15 19:55:10 +01:00
|
|
|
.or_else(|| self.try_report_outlives_closure())
|
2018-06-08 08:07:46 +02:00
|
|
|
.or_else(|| self.try_report_static_impl_trait())
|
2019-10-03 20:41:27 +02:00
|
|
|
.or_else(|| self.try_report_impl_not_conforming_to_trait())
|
2018-01-15 19:55:10 +01:00
|
|
|
}
|
|
|
|
|
2019-10-23 19:28:27 +02:00
|
|
|
pub fn regions(&self) -> (Span, ty::Region<'tcx>, ty::Region<'tcx>) {
|
2018-01-15 19:55:10 +01:00
|
|
|
match (&self.error, self.regions) {
|
2018-11-17 14:18:37 +01:00
|
|
|
(Some(ConcreteFailure(origin, sub, sup)), None) => (origin.span(), sub, sup),
|
|
|
|
(Some(SubSupConflict(_, _, origin, sub, _, sup)), None) => (origin.span(), sub, sup),
|
2018-01-15 19:55:10 +01:00
|
|
|
(None, Some((span, sub, sup))) => (span, sub, sup),
|
|
|
|
(Some(_), Some(_)) => panic!("incorrectly built NiceRegionError"),
|
|
|
|
_ => panic!("trying to report on an incorrect lifetime failure"),
|
|
|
|
}
|
2017-12-12 14:31:38 +01:00
|
|
|
}
|
|
|
|
}
|