diff options
| author | Ali MJ Al-Nasrawy <alimjalnasrawy@gmail.com> | 2023-09-17 14:32:02 +0000 |
|---|---|---|
| committer | Ali MJ Al-Nasrawy <alimjalnasrawy@gmail.com> | 2023-10-08 09:59:51 +0000 |
| commit | 996ffcb718941fc36ec5fdee38ed99ce20ec06d5 (patch) | |
| tree | e64955715a91be92e9d9dc8da3012b4dc486a982 /compiler/rustc_infer/src | |
| parent | 5be0b2283aa26f0fee1e3d1161524a23d65484b7 (diff) | |
| download | rust-996ffcb718941fc36ec5fdee38ed99ce20ec06d5.tar.gz rust-996ffcb718941fc36ec5fdee38ed99ce20ec06d5.zip | |
always show and explain sub region
Diffstat (limited to 'compiler/rustc_infer/src')
| -rw-r--r-- | compiler/rustc_infer/src/infer/error_reporting/mod.rs | 60 |
1 files changed, 23 insertions, 37 deletions
diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 0e48d09d6c6..96db169dc70 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -59,8 +59,8 @@ use crate::traits::{ }; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; +use rustc_errors::{error_code, Applicability, DiagnosticBuilder, DiagnosticStyledString}; use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed, IntoDiagnosticArg}; -use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString}; use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LocalDefId}; @@ -2341,40 +2341,29 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { }, }; - let mut err = match sub.kind() { - ty::ReEarlyBound(_) | ty::ReFree(_) if sub.has_name() => struct_span_err!( - self.tcx.sess, - span, - E0309, - "{} may not live long enough", - labeled_user_string - ), - ty::ReStatic => struct_span_err!( - self.tcx.sess, - span, - E0310, - "{} may not live long enough", - labeled_user_string - ), - _ => { - let mut err = struct_span_err!( - self.tcx.sess, - span, - E0311, - "{} may not live long enough", - labeled_user_string - ); - note_and_explain_region( - self.tcx, - &mut err, - &format!("{labeled_user_string} must be valid for "), - sub, - "...", - None, - ); - err + let mut err = self.tcx.sess.struct_span_err_with_code( + span, + format!("{labeled_user_string} may not live long enough"), + match sub.kind() { + ty::ReEarlyBound(_) | ty::ReFree(_) if sub.has_name() => error_code!(E0309), + ty::ReStatic => error_code!(E0310), + _ => error_code!(E0311), + }, + ); + + '_explain: { + let (description, span) = match sub.kind() { + ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReStatic => { + msg_span_from_named_region(self.tcx, sub, Some(span)) + } + _ => (format!("lifetime `{sub}`"), Some(span)), + }; + let prefix = format!("{labeled_user_string} must be valid for "); + label_msg_span(&mut err, &prefix, description, span, "..."); + if let Some(origin) = origin { + self.note_region_origin(&mut err, &origin); } - }; + } 'suggestion: { let msg = "consider adding an explicit lifetime bound"; @@ -2450,9 +2439,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { ); } - if let Some(origin) = origin { - self.note_region_origin(&mut err, &origin); - } err } |
