Skip to content

Commit 73fb568

Browse files
committed
Introduce the mismatched_lifetime_syntaxes lint
1 parent c6894ec commit 73fb568

File tree

8 files changed

+1353
-3
lines changed

8 files changed

+1353
-3
lines changed

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl ParamName {
206206
}
207207
}
208208

209-
#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable_Generic)]
209+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, HashStable_Generic)]
210210
pub enum LifetimeKind {
211211
/// User-given names or fresh (synthetic) names.
212212
Param(LocalDefId),

compiler/rustc_lint/messages.ftl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,28 @@ lint_metavariable_still_repeating = variable `{$name}` is still repeating at thi
518518
519519
lint_metavariable_wrong_operator = meta-variable repeats with different Kleene operator
520520
521+
lint_mismatched_lifetime_syntaxes =
522+
lifetime flowing from input to output with different syntax can be confusing
523+
.label_mismatched_lifetime_syntaxes_inputs =
524+
{$n_inputs ->
525+
[one] this lifetime flows
526+
*[other] these lifetimes flow
527+
} to the output
528+
.label_mismatched_lifetime_syntaxes_outputs =
529+
the elided {$n_outputs ->
530+
[one] lifetime gets
531+
*[other] lifetimes get
532+
} resolved as `{$lifetime_name}`
533+
534+
lint_mismatched_lifetime_syntaxes_suggestion_explicit =
535+
one option is to consistently use `{$lifetime_name}`
536+
537+
lint_mismatched_lifetime_syntaxes_suggestion_implicit =
538+
one option is to consistently remove the lifetime
539+
540+
lint_mismatched_lifetime_syntaxes_suggestion_mixed =
541+
one option is to remove the lifetime for references and use the anonymous lifetime for paths
542+
521543
lint_missing_fragment_specifier = missing fragment specifier
522544
523545
lint_missing_unsafe_on_extern = extern blocks should be unsafe

compiler/rustc_lint/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ mod invalid_from_utf8;
5555
mod late;
5656
mod let_underscore;
5757
mod levels;
58+
mod lifetime_syntax;
5859
mod lints;
5960
mod macro_expr_fragment_specifier_2024_migration;
6061
mod map_unit_fn;
@@ -96,6 +97,7 @@ use impl_trait_overcaptures::ImplTraitOvercaptures;
9697
use internal::*;
9798
use invalid_from_utf8::*;
9899
use let_underscore::*;
100+
use lifetime_syntax::*;
99101
use macro_expr_fragment_specifier_2024_migration::*;
100102
use map_unit_fn::*;
101103
use multiple_supertrait_upcastable::*;
@@ -246,6 +248,7 @@ late_lint_methods!(
246248
StaticMutRefs: StaticMutRefs,
247249
UnqualifiedLocalImports: UnqualifiedLocalImports,
248250
CheckTransmutes: CheckTransmutes,
251+
LifetimeSyntax: LifetimeSyntax,
249252
]
250253
]
251254
);

0 commit comments

Comments
 (0)