summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs')
-rw-r--r--compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs43
1 files changed, 16 insertions, 27 deletions
diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs
index 3fe7c1598..4e13ec902 100644
--- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs
+++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs
@@ -1,8 +1,11 @@
//! Error Reporting for Anonymous Region Lifetime Errors
//! where one region is named and the other is anonymous.
-use crate::infer::error_reporting::nice_region_error::find_anon_type::find_anon_type;
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
-use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed};
+use crate::{
+ errors::ExplicitLifetimeRequired,
+ infer::error_reporting::nice_region_error::find_anon_type::find_anon_type,
+};
+use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed};
use rustc_middle::ty;
use rustc_span::symbol::kw;
@@ -86,31 +89,17 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
{
return None;
}
-
- let (error_var, span_label_var) = match param.pat.simple_ident() {
- Some(simple_ident) => (
- format!("the type of `{}`", simple_ident),
- format!("the type of `{}`", simple_ident),
- ),
- None => ("parameter type".to_owned(), "type".to_owned()),
+ let named = named.to_string();
+ let err = match param.pat.simple_ident() {
+ Some(simple_ident) => ExplicitLifetimeRequired::WithIdent {
+ span,
+ simple_ident,
+ named,
+ new_ty_span,
+ new_ty,
+ },
+ None => ExplicitLifetimeRequired::WithParamType { span, named, new_ty_span, new_ty },
};
-
- let mut diag = struct_span_err!(
- self.tcx().sess,
- span,
- E0621,
- "explicit lifetime required in {}",
- error_var
- );
-
- diag.span_label(span, format!("lifetime `{}` required", named));
- diag.span_suggestion(
- new_ty_span,
- &format!("add explicit lifetime `{}` to {}", named, span_label_var),
- new_ty,
- Applicability::Unspecified,
- );
-
- Some(diag)
+ Some(self.tcx().sess.parse_sess.create_err(err))
}
}