Skip to content

Commit 7ecd064

Browse files
committed
Split infer_explicit_lifetime_required into several diags
1 parent 19b8579 commit 7ecd064

File tree

3 files changed

+50
-37
lines changed

3 files changed

+50
-37
lines changed

compiler/rustc_error_messages/locales/en-US/infer.ftl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,15 @@ infer_msl_trait_note = this has an implicit `'static` lifetime requirement
173173
infer_msl_trait_sugg = consider relaxing the implicit `'static` requirement
174174
infer_suggest_add_let_for_letchains = consider adding `let`
175175
176-
infer_explicit_lifetime_required = explicit lifetime required in {$ident_kind ->
177-
[ident] the type of `{$simple_ident}`
178-
*[param_type] parameter type
179-
}
176+
infer_explicit_lifetime_required_with_ident = explicit lifetime required in the type of `{$simple_ident}`
180177
.label = lifetime `{$named}` required
181178
182-
infer_explicit_lifetime_required_sugg = add explicit lifetime `{$named}` to {$ident_kind ->
183-
[ident] the type of `{$simple_ident}`
184-
*[param_type] type
185-
}
179+
infer_explicit_lifetime_required_with_param_type = explicit lifetime required in parameter type
180+
.label = lifetime `{$named}` required
181+
182+
infer_explicit_lifetime_required_sugg_with_ident = add explicit lifetime `{$named}` to the type of `{$simple_ident}`
183+
184+
infer_explicit_lifetime_required_sugg_with_param_type = add explicit lifetime `{$named}` to type
186185
187186
infer_actual_impl_expl_expected_signature_two = {$leading_ellipsis ->
188187
[true] ...

compiler/rustc_infer/src/errors/mod.rs

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -523,23 +523,38 @@ pub struct MismatchedStaticLifetime<'a> {
523523
}
524524

525525
#[derive(Diagnostic)]
526-
#[diag(infer_explicit_lifetime_required, code = "E0621")]
527-
pub struct ExplicitLifetimeRequired<'a> {
528-
#[primary_span]
529-
#[label]
530-
pub span: Span,
531-
pub ident_kind: &'static str,
532-
pub simple_ident: String,
533-
pub named: String,
534-
535-
#[suggestion(
536-
infer_explicit_lifetime_required_sugg,
537-
code = "{new_ty}",
538-
applicability = "unspecified"
539-
)]
540-
pub new_ty_span: Span,
541-
#[skip_arg]
542-
pub new_ty: Ty<'a>,
526+
pub enum ExplicitLifetimeRequired<'a> {
527+
#[diag(infer_explicit_lifetime_required_with_ident, code = "E0621")]
528+
WithIdent {
529+
#[primary_span]
530+
#[label]
531+
span: Span,
532+
simple_ident: Ident,
533+
named: String,
534+
#[suggestion(
535+
infer_explicit_lifetime_required_sugg_with_ident,
536+
code = "{new_ty}",
537+
applicability = "unspecified"
538+
)]
539+
new_ty_span: Span,
540+
#[skip_arg]
541+
new_ty: Ty<'a>,
542+
},
543+
#[diag(infer_explicit_lifetime_required_with_param_type, code = "E0621")]
544+
WithParamType {
545+
#[primary_span]
546+
#[label]
547+
span: Span,
548+
named: String,
549+
#[suggestion(
550+
infer_explicit_lifetime_required_sugg_with_param_type,
551+
code = "{new_ty}",
552+
applicability = "unspecified"
553+
)]
554+
new_ty_span: Span,
555+
#[skip_arg]
556+
new_ty: Ty<'a>,
557+
},
543558
}
544559

545560
#[derive(Subdiagnostic)]

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,17 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
8989
{
9090
return None;
9191
}
92-
93-
let simple_ident = param.pat.simple_ident();
94-
let (ident_kind, simple_ident) = match simple_ident {
95-
Some(ident) => ("ident", ident.to_string()),
96-
None => ("param_type", String::new()),
97-
};
98-
9992
let named = named.to_string();
100-
101-
let err =
102-
ExplicitLifetimeRequired { span, ident_kind, simple_ident, named, new_ty_span, new_ty };
103-
let err = self.tcx().sess.parse_sess.create_err(err);
104-
Some(err)
93+
let err = match param.pat.simple_ident() {
94+
Some(simple_ident) => ExplicitLifetimeRequired::WithIdent {
95+
span,
96+
simple_ident,
97+
named,
98+
new_ty_span,
99+
new_ty,
100+
},
101+
None => ExplicitLifetimeRequired::WithParamType { span, named, new_ty_span, new_ty },
102+
};
103+
Some(self.tcx().sess.parse_sess.create_err(err))
105104
}
106105
}

0 commit comments

Comments
 (0)