Skip to content

Commit 0ffc997

Browse files
committed
Introduce the mismatched_lifetime_syntaxes lint
1 parent 651278a commit 0ffc997

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
@@ -56,6 +56,7 @@ mod invalid_from_utf8;
5656
mod late;
5757
mod let_underscore;
5858
mod levels;
59+
mod lifetime_syntax;
5960
mod lints;
6061
mod macro_expr_fragment_specifier_2024_migration;
6162
mod map_unit_fn;
@@ -98,6 +99,7 @@ use impl_trait_overcaptures::ImplTraitOvercaptures;
9899
use internal::*;
99100
use invalid_from_utf8::*;
100101
use let_underscore::*;
102+
use lifetime_syntax::*;
101103
use macro_expr_fragment_specifier_2024_migration::*;
102104
use map_unit_fn::*;
103105
use multiple_supertrait_upcastable::*;
@@ -249,6 +251,7 @@ late_lint_methods!(
249251
StaticMutRefs: StaticMutRefs,
250252
UnqualifiedLocalImports: UnqualifiedLocalImports,
251253
CheckTransmutes: CheckTransmutes,
254+
LifetimeSyntax: LifetimeSyntax,
252255
]
253256
]
254257
);

0 commit comments

Comments
 (0)