Skip to content

Commit ea613f3

Browse files
committed
Buffer and migrate nice region errors
1 parent 168c14a commit ea613f3

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

src/librustc/infer/error_reporting/nice_region_error/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use crate::infer::InferCtxt;
22
use crate::infer::lexical_region_resolve::RegionResolutionError;
33
use crate::infer::lexical_region_resolve::RegionResolutionError::*;
4-
use syntax::source_map::Span;
54
use crate::ty::{self, TyCtxt};
65
use crate::util::common::ErrorReported;
6+
use errors::DiagnosticBuilder;
7+
use syntax::source_map::Span;
78

89
mod different_lifetimes;
910
mod find_anon_type;
@@ -59,7 +60,7 @@ impl<'cx, 'gcx, 'tcx> NiceRegionError<'cx, 'gcx, 'tcx> {
5960
self.infcx.tcx
6061
}
6162

62-
pub fn try_report_from_nll(&self) -> Option<ErrorReported> {
63+
pub fn try_report_from_nll(&self) -> Option<DiagnosticBuilder<'cx>> {
6364
// Due to the improved diagnostics returned by the MIR borrow checker, only a subset of
6465
// the nice region errors are required when running under the MIR borrow checker.
6566
self.try_report_named_anon_conflict()
@@ -68,6 +69,7 @@ impl<'cx, 'gcx, 'tcx> NiceRegionError<'cx, 'gcx, 'tcx> {
6869

6970
pub fn try_report(&self) -> Option<ErrorReported> {
7071
self.try_report_from_nll()
72+
.map(|mut diag| { diag.emit(); ErrorReported })
7173
.or_else(|| self.try_report_anon_anon_conflict())
7274
.or_else(|| self.try_report_outlives_closure())
7375
.or_else(|| self.try_report_static_impl_trait())

src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
//! where one region is named and the other is anonymous.
33
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
44
use crate::ty;
5-
use crate::util::common::ErrorReported;
6-
use errors::Applicability;
5+
use errors::{Applicability, DiagnosticBuilder};
76

87
impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
98
/// When given a `ConcreteFailure` for a function with arguments containing a named region and
109
/// an anonymous region, emit an descriptive diagnostic error.
11-
pub(super) fn try_report_named_anon_conflict(&self) -> Option<ErrorReported> {
10+
pub(super) fn try_report_named_anon_conflict(&self) -> Option<DiagnosticBuilder<'a>> {
1211
let (span, sub, sup) = self.get_regions();
1312

1413
debug!(
@@ -96,21 +95,23 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
9695
("parameter type".to_owned(), "type".to_owned())
9796
};
9897

99-
struct_span_err!(
98+
let mut diag = struct_span_err!(
10099
self.tcx().sess,
101100
span,
102101
E0621,
103102
"explicit lifetime required in {}",
104103
error_var
105-
).span_suggestion(
106-
new_ty_span,
107-
&format!("add explicit lifetime `{}` to {}", named, span_label_var),
108-
new_ty.to_string(),
109-
Applicability::Unspecified,
110-
)
111-
.span_label(span, format!("lifetime `{}` required", named))
112-
.emit();
113-
return Some(ErrorReported);
104+
);
105+
106+
diag.span_suggestion(
107+
new_ty_span,
108+
&format!("add explicit lifetime `{}` to {}", named, span_label_var),
109+
new_ty.to_string(),
110+
Applicability::Unspecified,
111+
)
112+
.span_label(span, format!("lifetime `{}` required", named));
113+
114+
Some(diag)
114115
}
115116

116117
// This method returns whether the given Region is Named

src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ use crate::traits::{ObligationCause, ObligationCauseCode};
88
use crate::ty;
99
use crate::ty::error::ExpectedFound;
1010
use crate::ty::subst::Substs;
11-
use crate::util::common::ErrorReported;
1211
use crate::util::ppaux::RegionHighlightMode;
1312

1413
impl NiceRegionError<'me, 'gcx, 'tcx> {
1514
/// When given a `ConcreteFailure` for a function with arguments containing a named region and
1615
/// an anonymous region, emit a descriptive diagnostic error.
17-
pub(super) fn try_report_placeholder_conflict(&self) -> Option<ErrorReported> {
16+
pub(super) fn try_report_placeholder_conflict(&self) -> Option<DiagnosticBuilder<'me>> {
1817
match &self.error {
1918
///////////////////////////////////////////////////////////////////////////
2019
// NB. The ordering of cases in this match is very
@@ -178,7 +177,7 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
178177
trait_def_id: DefId,
179178
expected_substs: &'tcx Substs<'tcx>,
180179
actual_substs: &'tcx Substs<'tcx>,
181-
) -> ErrorReported {
180+
) -> DiagnosticBuilder<'me> {
182181
debug!(
183182
"try_report_placeholders_trait(\
184183
vid={:?}, \
@@ -295,8 +294,7 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
295294
any_self_ty_has_vid,
296295
);
297296

298-
err.emit();
299-
ErrorReported
297+
err
300298
}
301299

302300
/// Add notes with details about the expected and actual trait refs, with attention to cases

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
244244
if let (Some(f), Some(o)) = (self.to_error_region(fr), self.to_error_region(outlived_fr)) {
245245
let tables = infcx.tcx.typeck_tables_of(mir_def_id);
246246
let nice = NiceRegionError::new_from_span(infcx, span, o, f, Some(tables));
247-
if let Some(_error_reported) = nice.try_report_from_nll() {
247+
if let Some(diag) = nice.try_report_from_nll() {
248+
diag.buffer(errors_buffer);
248249
return;
249250
}
250251
}

0 commit comments

Comments
 (0)