Buffer and migrate nice region errors
This commit is contained in:
parent
168c14a1a5
commit
ea613f30d9
4 changed files with 23 additions and 21 deletions
|
@ -1,9 +1,10 @@
|
||||||
use crate::infer::InferCtxt;
|
use crate::infer::InferCtxt;
|
||||||
use crate::infer::lexical_region_resolve::RegionResolutionError;
|
use crate::infer::lexical_region_resolve::RegionResolutionError;
|
||||||
use crate::infer::lexical_region_resolve::RegionResolutionError::*;
|
use crate::infer::lexical_region_resolve::RegionResolutionError::*;
|
||||||
use syntax::source_map::Span;
|
|
||||||
use crate::ty::{self, TyCtxt};
|
use crate::ty::{self, TyCtxt};
|
||||||
use crate::util::common::ErrorReported;
|
use crate::util::common::ErrorReported;
|
||||||
|
use errors::DiagnosticBuilder;
|
||||||
|
use syntax::source_map::Span;
|
||||||
|
|
||||||
mod different_lifetimes;
|
mod different_lifetimes;
|
||||||
mod find_anon_type;
|
mod find_anon_type;
|
||||||
|
@ -59,7 +60,7 @@ impl<'cx, 'gcx, 'tcx> NiceRegionError<'cx, 'gcx, 'tcx> {
|
||||||
self.infcx.tcx
|
self.infcx.tcx
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn try_report_from_nll(&self) -> Option<ErrorReported> {
|
pub fn try_report_from_nll(&self) -> Option<DiagnosticBuilder<'cx>> {
|
||||||
// Due to the improved diagnostics returned by the MIR borrow checker, only a subset of
|
// 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.
|
// the nice region errors are required when running under the MIR borrow checker.
|
||||||
self.try_report_named_anon_conflict()
|
self.try_report_named_anon_conflict()
|
||||||
|
@ -68,6 +69,7 @@ impl<'cx, 'gcx, 'tcx> NiceRegionError<'cx, 'gcx, 'tcx> {
|
||||||
|
|
||||||
pub fn try_report(&self) -> Option<ErrorReported> {
|
pub fn try_report(&self) -> Option<ErrorReported> {
|
||||||
self.try_report_from_nll()
|
self.try_report_from_nll()
|
||||||
|
.map(|mut diag| { diag.emit(); ErrorReported })
|
||||||
.or_else(|| self.try_report_anon_anon_conflict())
|
.or_else(|| self.try_report_anon_anon_conflict())
|
||||||
.or_else(|| self.try_report_outlives_closure())
|
.or_else(|| self.try_report_outlives_closure())
|
||||||
.or_else(|| self.try_report_static_impl_trait())
|
.or_else(|| self.try_report_static_impl_trait())
|
||||||
|
|
|
@ -2,13 +2,12 @@
|
||||||
//! where one region is named and the other is anonymous.
|
//! where one region is named and the other is anonymous.
|
||||||
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
|
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
|
||||||
use crate::ty;
|
use crate::ty;
|
||||||
use crate::util::common::ErrorReported;
|
use errors::{Applicability, DiagnosticBuilder};
|
||||||
use errors::Applicability;
|
|
||||||
|
|
||||||
impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
|
impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
|
||||||
/// When given a `ConcreteFailure` for a function with arguments containing a named region and
|
/// When given a `ConcreteFailure` for a function with arguments containing a named region and
|
||||||
/// an anonymous region, emit an descriptive diagnostic error.
|
/// an anonymous region, emit an descriptive diagnostic error.
|
||||||
pub(super) fn try_report_named_anon_conflict(&self) -> Option<ErrorReported> {
|
pub(super) fn try_report_named_anon_conflict(&self) -> Option<DiagnosticBuilder<'a>> {
|
||||||
let (span, sub, sup) = self.get_regions();
|
let (span, sub, sup) = self.get_regions();
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
|
@ -96,21 +95,23 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
|
||||||
("parameter type".to_owned(), "type".to_owned())
|
("parameter type".to_owned(), "type".to_owned())
|
||||||
};
|
};
|
||||||
|
|
||||||
struct_span_err!(
|
let mut diag = struct_span_err!(
|
||||||
self.tcx().sess,
|
self.tcx().sess,
|
||||||
span,
|
span,
|
||||||
E0621,
|
E0621,
|
||||||
"explicit lifetime required in {}",
|
"explicit lifetime required in {}",
|
||||||
error_var
|
error_var
|
||||||
).span_suggestion(
|
);
|
||||||
new_ty_span,
|
|
||||||
&format!("add explicit lifetime `{}` to {}", named, span_label_var),
|
diag.span_suggestion(
|
||||||
new_ty.to_string(),
|
new_ty_span,
|
||||||
Applicability::Unspecified,
|
&format!("add explicit lifetime `{}` to {}", named, span_label_var),
|
||||||
)
|
new_ty.to_string(),
|
||||||
.span_label(span, format!("lifetime `{}` required", named))
|
Applicability::Unspecified,
|
||||||
.emit();
|
)
|
||||||
return Some(ErrorReported);
|
.span_label(span, format!("lifetime `{}` required", named));
|
||||||
|
|
||||||
|
Some(diag)
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method returns whether the given Region is Named
|
// This method returns whether the given Region is Named
|
||||||
|
|
|
@ -8,13 +8,12 @@ use crate::traits::{ObligationCause, ObligationCauseCode};
|
||||||
use crate::ty;
|
use crate::ty;
|
||||||
use crate::ty::error::ExpectedFound;
|
use crate::ty::error::ExpectedFound;
|
||||||
use crate::ty::subst::Substs;
|
use crate::ty::subst::Substs;
|
||||||
use crate::util::common::ErrorReported;
|
|
||||||
use crate::util::ppaux::RegionHighlightMode;
|
use crate::util::ppaux::RegionHighlightMode;
|
||||||
|
|
||||||
impl NiceRegionError<'me, 'gcx, 'tcx> {
|
impl NiceRegionError<'me, 'gcx, 'tcx> {
|
||||||
/// When given a `ConcreteFailure` for a function with arguments containing a named region and
|
/// When given a `ConcreteFailure` for a function with arguments containing a named region and
|
||||||
/// an anonymous region, emit a descriptive diagnostic error.
|
/// an anonymous region, emit a descriptive diagnostic error.
|
||||||
pub(super) fn try_report_placeholder_conflict(&self) -> Option<ErrorReported> {
|
pub(super) fn try_report_placeholder_conflict(&self) -> Option<DiagnosticBuilder<'me>> {
|
||||||
match &self.error {
|
match &self.error {
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// NB. The ordering of cases in this match is very
|
// NB. The ordering of cases in this match is very
|
||||||
|
@ -178,7 +177,7 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
|
||||||
trait_def_id: DefId,
|
trait_def_id: DefId,
|
||||||
expected_substs: &'tcx Substs<'tcx>,
|
expected_substs: &'tcx Substs<'tcx>,
|
||||||
actual_substs: &'tcx Substs<'tcx>,
|
actual_substs: &'tcx Substs<'tcx>,
|
||||||
) -> ErrorReported {
|
) -> DiagnosticBuilder<'me> {
|
||||||
debug!(
|
debug!(
|
||||||
"try_report_placeholders_trait(\
|
"try_report_placeholders_trait(\
|
||||||
vid={:?}, \
|
vid={:?}, \
|
||||||
|
@ -295,8 +294,7 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
|
||||||
any_self_ty_has_vid,
|
any_self_ty_has_vid,
|
||||||
);
|
);
|
||||||
|
|
||||||
err.emit();
|
err
|
||||||
ErrorReported
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add notes with details about the expected and actual trait refs, with attention to cases
|
/// Add notes with details about the expected and actual trait refs, with attention to cases
|
||||||
|
|
|
@ -244,7 +244,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
if let (Some(f), Some(o)) = (self.to_error_region(fr), self.to_error_region(outlived_fr)) {
|
if let (Some(f), Some(o)) = (self.to_error_region(fr), self.to_error_region(outlived_fr)) {
|
||||||
let tables = infcx.tcx.typeck_tables_of(mir_def_id);
|
let tables = infcx.tcx.typeck_tables_of(mir_def_id);
|
||||||
let nice = NiceRegionError::new_from_span(infcx, span, o, f, Some(tables));
|
let nice = NiceRegionError::new_from_span(infcx, span, o, f, Some(tables));
|
||||||
if let Some(_error_reported) = nice.try_report_from_nll() {
|
if let Some(diag) = nice.try_report_from_nll() {
|
||||||
|
diag.buffer(errors_buffer);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue