|
1 | 1 | //! Error Reporting for Anonymous Region Lifetime Errors |
2 | 2 | //! where one region is named and the other is anonymous. |
3 | | -use crate::infer::error_reporting::nice_region_error::find_anon_type::find_anon_type; |
4 | 3 | use crate::infer::error_reporting::nice_region_error::NiceRegionError; |
5 | | -use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed}; |
| 4 | +use crate::{ |
| 5 | + errors::ExplicitLifetimeRequired, |
| 6 | + infer::error_reporting::nice_region_error::find_anon_type::find_anon_type, |
| 7 | +}; |
| 8 | +use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed}; |
6 | 9 | use rustc_middle::ty; |
7 | 10 | use rustc_span::symbol::kw; |
8 | 11 |
|
@@ -87,30 +90,17 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { |
87 | 90 | return None; |
88 | 91 | } |
89 | 92 |
|
90 | | - let (error_var, span_label_var) = match param.pat.simple_ident() { |
91 | | - Some(simple_ident) => ( |
92 | | - format!("the type of `{}`", simple_ident), |
93 | | - format!("the type of `{}`", simple_ident), |
94 | | - ), |
95 | | - None => ("parameter type".to_owned(), "type".to_owned()), |
| 93 | + let simple_ident = param.pat.simple_ident(); |
| 94 | + let (ident_kind, simple_ident) = match simple_ident { |
| 95 | + Some(ident) => ("ident", ident.to_string()), |
| 96 | + None => ("param_type", String::new()), |
96 | 97 | }; |
97 | 98 |
|
98 | | - let mut diag = struct_span_err!( |
99 | | - self.tcx().sess, |
100 | | - span, |
101 | | - E0621, |
102 | | - "explicit lifetime required in {}", |
103 | | - error_var |
104 | | - ); |
105 | | - |
106 | | - diag.span_label(span, format!("lifetime `{}` required", named)); |
107 | | - diag.span_suggestion( |
108 | | - new_ty_span, |
109 | | - &format!("add explicit lifetime `{}` to {}", named, span_label_var), |
110 | | - new_ty, |
111 | | - Applicability::Unspecified, |
112 | | - ); |
| 99 | + let named = named.to_string(); |
113 | 100 |
|
114 | | - Some(diag) |
| 101 | + let err = |
| 102 | + ExplicitLifetimeRequired { span, ident_kind, simple_ident, named, new_ty_span, new_ty }; |
| 103 | + let err = self.tcx().sess.parse_sess.create_err(err); |
| 104 | + Some(err) |
115 | 105 | } |
116 | 106 | } |
0 commit comments