|
1 | 1 | use crate::errors::{ |
2 | 2 | note_and_explain, BorrowedTooLong, FullfillReqLifetime, LfBoundNotSatisfied, OutlivesBound, |
3 | | - OutlivesContent, RegionOriginNote, |
| 3 | + OutlivesContent, RefLongerThanData, RegionOriginNote, |
4 | 4 | }; |
5 | 5 | use crate::infer::error_reporting::{note_and_explain_region, TypeErrCtxt}; |
6 | 6 | use crate::infer::{self, SubregionOrigin}; |
@@ -223,30 +223,26 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { |
223 | 223 | .into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic) |
224 | 224 | } |
225 | 225 | infer::ReferenceOutlivesReferent(ty, span) => { |
226 | | - let mut err = struct_span_err!( |
227 | | - self.tcx.sess, |
228 | | - span, |
229 | | - E0491, |
230 | | - "in type `{}`, reference has a longer lifetime than the data it references", |
231 | | - self.ty_to_string(ty) |
232 | | - ); |
233 | | - note_and_explain_region( |
| 226 | + let pointer_valid = note_and_explain::RegionExplanation::new( |
234 | 227 | self.tcx, |
235 | | - &mut err, |
236 | | - "the pointer is valid for ", |
237 | 228 | sub, |
238 | | - "", |
239 | 229 | None, |
| 230 | + note_and_explain::PrefixKind::PointerValidFor, |
| 231 | + note_and_explain::SuffixKind::Empty, |
240 | 232 | ); |
241 | | - note_and_explain_region( |
| 233 | + let data_valid = note_and_explain::RegionExplanation::new( |
242 | 234 | self.tcx, |
243 | | - &mut err, |
244 | | - "but the referenced data is only valid for ", |
245 | 235 | sup, |
246 | | - "", |
247 | 236 | None, |
| 237 | + note_and_explain::PrefixKind::DataValidFor, |
| 238 | + note_and_explain::SuffixKind::Empty, |
248 | 239 | ); |
249 | | - err |
| 240 | + RefLongerThanData { |
| 241 | + span, |
| 242 | + ty: self.resolve_vars_if_possible(ty), |
| 243 | + notes: pointer_valid.into_iter().chain(data_valid).collect(), |
| 244 | + } |
| 245 | + .into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic) |
250 | 246 | } |
251 | 247 | infer::CompareImplItemObligation { span, impl_item_def_id, trait_item_def_id } => { |
252 | 248 | let mut err = self.report_extra_impl_obligation( |
|
0 commit comments