Split infer_explicit_lifetime_required into several diags
This commit is contained in:
parent
19b8579803
commit
7ecd064bbe
3 changed files with 50 additions and 37 deletions
|
@ -523,23 +523,38 @@ pub struct MismatchedStaticLifetime<'a> {
|
|||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(infer_explicit_lifetime_required, code = "E0621")]
|
||||
pub struct ExplicitLifetimeRequired<'a> {
|
||||
#[primary_span]
|
||||
#[label]
|
||||
pub span: Span,
|
||||
pub ident_kind: &'static str,
|
||||
pub simple_ident: String,
|
||||
pub named: String,
|
||||
|
||||
#[suggestion(
|
||||
infer_explicit_lifetime_required_sugg,
|
||||
code = "{new_ty}",
|
||||
applicability = "unspecified"
|
||||
)]
|
||||
pub new_ty_span: Span,
|
||||
#[skip_arg]
|
||||
pub new_ty: Ty<'a>,
|
||||
pub enum ExplicitLifetimeRequired<'a> {
|
||||
#[diag(infer_explicit_lifetime_required_with_ident, code = "E0621")]
|
||||
WithIdent {
|
||||
#[primary_span]
|
||||
#[label]
|
||||
span: Span,
|
||||
simple_ident: Ident,
|
||||
named: String,
|
||||
#[suggestion(
|
||||
infer_explicit_lifetime_required_sugg_with_ident,
|
||||
code = "{new_ty}",
|
||||
applicability = "unspecified"
|
||||
)]
|
||||
new_ty_span: Span,
|
||||
#[skip_arg]
|
||||
new_ty: Ty<'a>,
|
||||
},
|
||||
#[diag(infer_explicit_lifetime_required_with_param_type, code = "E0621")]
|
||||
WithParamType {
|
||||
#[primary_span]
|
||||
#[label]
|
||||
span: Span,
|
||||
named: String,
|
||||
#[suggestion(
|
||||
infer_explicit_lifetime_required_sugg_with_param_type,
|
||||
code = "{new_ty}",
|
||||
applicability = "unspecified"
|
||||
)]
|
||||
new_ty_span: Span,
|
||||
#[skip_arg]
|
||||
new_ty: Ty<'a>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
|
|
|
@ -89,18 +89,17 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
let simple_ident = param.pat.simple_ident();
|
||||
let (ident_kind, simple_ident) = match simple_ident {
|
||||
Some(ident) => ("ident", ident.to_string()),
|
||||
None => ("param_type", String::new()),
|
||||
};
|
||||
|
||||
let named = named.to_string();
|
||||
|
||||
let err =
|
||||
ExplicitLifetimeRequired { span, ident_kind, simple_ident, named, new_ty_span, new_ty };
|
||||
let err = self.tcx().sess.parse_sess.create_err(err);
|
||||
Some(err)
|
||||
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 },
|
||||
};
|
||||
Some(self.tcx().sess.parse_sess.create_err(err))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue