1
Fork 0

Move "elided lifetime in path" to subdiagnostic struct

This requires nested subdiagnostics.
This commit is contained in:
Xiretza 2024-04-20 13:21:15 +00:00
parent b220b741c6
commit 6974e9cf70
5 changed files with 40 additions and 33 deletions

View file

@ -1,4 +1,4 @@
use rustc_errors::{codes::*, Applicability, MultiSpan};
use rustc_errors::{codes::*, Applicability, ElidedLifetimeInPathSubdiag, MultiSpan};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{
symbol::{Ident, Symbol},
@ -907,6 +907,8 @@ pub(crate) struct ExplicitAnonymousLivetimeReportError {
pub(crate) struct ImplicitElidedLifetimeNotAllowedHere {
#[primary_span]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) subdiag: ElidedLifetimeInPathSubdiag,
}
#[derive(Diagnostic)]

View file

@ -1883,20 +1883,18 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
// async fn foo(_: std::cell::Ref<u32>) { ... }
LifetimeRibKind::AnonymousCreateParameter { report_in_path: true, .. }
| LifetimeRibKind::AnonymousWarn(_) => {
let mut err =
self.r.dcx().create_err(errors::ImplicitElidedLifetimeNotAllowedHere {
span: path_span,
});
let sess = self.r.tcx.sess;
rustc_errors::add_elided_lifetime_in_path_suggestion(
let subdiag = rustc_errors::elided_lifetime_in_path_suggestion(
sess.source_map(),
&mut err,
expected_lifetimes,
path_span,
!segment.has_generic_args,
elided_lifetime_span,
);
err.emit();
self.r.dcx().emit_err(errors::ImplicitElidedLifetimeNotAllowedHere {
span: path_span,
subdiag,
});
should_lint = false;
for id in node_ids {