Split infer_explicit_lifetime_required into several diags

This commit is contained in:
Nikita Tomashevich 2022-11-03 20:45:14 +03:00
parent 19b8579803
commit 7ecd064bbe
No known key found for this signature in database
GPG Key ID: B29791D4D878E345
3 changed files with 50 additions and 37 deletions

View File

@ -173,16 +173,15 @@ infer_msl_trait_note = this has an implicit `'static` lifetime requirement
infer_msl_trait_sugg = consider relaxing the implicit `'static` requirement infer_msl_trait_sugg = consider relaxing the implicit `'static` requirement
infer_suggest_add_let_for_letchains = consider adding `let` infer_suggest_add_let_for_letchains = consider adding `let`
infer_explicit_lifetime_required = explicit lifetime required in {$ident_kind -> infer_explicit_lifetime_required_with_ident = explicit lifetime required in the type of `{$simple_ident}`
[ident] the type of `{$simple_ident}`
*[param_type] parameter type
}
.label = lifetime `{$named}` required .label = lifetime `{$named}` required
infer_explicit_lifetime_required_sugg = add explicit lifetime `{$named}` to {$ident_kind -> infer_explicit_lifetime_required_with_param_type = explicit lifetime required in parameter type
[ident] the type of `{$simple_ident}` .label = lifetime `{$named}` required
*[param_type] type
} infer_explicit_lifetime_required_sugg_with_ident = add explicit lifetime `{$named}` to the type of `{$simple_ident}`
infer_explicit_lifetime_required_sugg_with_param_type = add explicit lifetime `{$named}` to type
infer_actual_impl_expl_expected_signature_two = {$leading_ellipsis -> infer_actual_impl_expl_expected_signature_two = {$leading_ellipsis ->
[true] ... [true] ...

View File

@ -523,23 +523,38 @@ pub struct MismatchedStaticLifetime<'a> {
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(infer_explicit_lifetime_required, code = "E0621")] pub enum ExplicitLifetimeRequired<'a> {
pub struct ExplicitLifetimeRequired<'a> { #[diag(infer_explicit_lifetime_required_with_ident, code = "E0621")]
WithIdent {
#[primary_span] #[primary_span]
#[label] #[label]
pub span: Span, span: Span,
pub ident_kind: &'static str, simple_ident: Ident,
pub simple_ident: String, named: String,
pub named: String,
#[suggestion( #[suggestion(
infer_explicit_lifetime_required_sugg, infer_explicit_lifetime_required_sugg_with_ident,
code = "{new_ty}", code = "{new_ty}",
applicability = "unspecified" applicability = "unspecified"
)] )]
pub new_ty_span: Span, new_ty_span: Span,
#[skip_arg] #[skip_arg]
pub new_ty: Ty<'a>, 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)] #[derive(Subdiagnostic)]

View File

@ -89,18 +89,17 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
{ {
return None; 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 named = named.to_string();
let err = match param.pat.simple_ident() {
let err = Some(simple_ident) => ExplicitLifetimeRequired::WithIdent {
ExplicitLifetimeRequired { span, ident_kind, simple_ident, named, new_ty_span, new_ty }; span,
let err = self.tcx().sess.parse_sess.create_err(err); simple_ident,
Some(err) 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))
} }
} }