Skip to content

Commit 1f6a98d

Browse files
committed
Introduce the mismatched_lifetime_syntaxes lint
1 parent 29d3b70 commit 1f6a98d

File tree

8 files changed

+1348
-3
lines changed

8 files changed

+1348
-3
lines changed

compiler/rustc_hir/src/hir.rs

+1-1
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

+22
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,28 @@ lint_metavariable_still_repeating = variable `{$name}` is still repeating at thi
512512
513513
lint_metavariable_wrong_operator = meta-variable repeats with different Kleene operator
514514
515+
lint_mismatched_lifetime_syntaxes =
516+
lifetime flowing from input to output with different syntax
517+
.label_mismatched_lifetime_syntaxes_inputs =
518+
{$n_inputs ->
519+
[one] this lifetime flows
520+
*[other] these lifetimes flow
521+
} to the output
522+
.label_mismatched_lifetime_syntaxes_outputs =
523+
the elided {$n_outputs ->
524+
[one] lifetime gets
525+
*[other] lifetimes get
526+
} resolved as `{$lifetime_name}`
527+
528+
lint_mismatched_lifetime_syntaxes_suggestion_explicit =
529+
one option is to consistently use `{$lifetime_name}`
530+
531+
lint_mismatched_lifetime_syntaxes_suggestion_implicit =
532+
one option is to consistently hide the lifetime
533+
534+
lint_mismatched_lifetime_syntaxes_suggestion_mixed =
535+
one option is to hide the lifetime for references and use the anonymous lifetime for paths
536+
515537
lint_missing_fragment_specifier = missing fragment specifier
516538
517539
lint_missing_unsafe_on_extern = extern blocks should be unsafe

compiler/rustc_lint/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ mod invalid_from_utf8;
5757
mod late;
5858
mod let_underscore;
5959
mod levels;
60+
mod lifetime_style;
6061
mod lints;
6162
mod macro_expr_fragment_specifier_2024_migration;
6263
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_style::*;
101103
use macro_expr_fragment_specifier_2024_migration::*;
102104
use map_unit_fn::*;
103105
use multiple_supertrait_upcastable::*;
@@ -246,6 +248,7 @@ late_lint_methods!(
246248
IfLetRescope: IfLetRescope::default(),
247249
StaticMutRefs: StaticMutRefs,
248250
UnqualifiedLocalImports: UnqualifiedLocalImports,
251+
LifetimeStyle: LifetimeStyle,
249252
]
250253
]
251254
);

0 commit comments

Comments
 (0)