Skip to content

Commit 872febf

Browse files
committed
Auto merge of #138677 - shepmaster:consistent-elided-lifetime-syntax, r=traviscross,jieyouxu
Add a new `mismatched-lifetime-syntaxes` lint The lang-team [discussed this](https://hackmd.io/nf4ZUYd7Rp6rq-1svJZSaQ) and I attempted to [summarize](rust-lang/rust#120808 (comment)) their decision. The summary-of-the-summary is: - Using two different kinds of syntax for elided lifetimes is confusing. In rare cases, it may even [lead to unsound code](rust-lang/rust#48686)! Some examples: ```rust // Lint will warn about these fn(v: ContainsLifetime) -> ContainsLifetime<'_>; fn(&'static u8) -> &u8; ``` - Matching up references with no lifetime syntax, references with anonymous lifetime syntax, and paths with anonymous lifetime syntax is an exception to the simplest possible rule: ```rust // Lint will not warn about these fn(&u8) -> &'_ u8; fn(&'_ u8) -> &u8; fn(&u8) -> ContainsLifetime<'_>; ``` - Having a lint for consistent syntax of elided lifetimes will make the [future goal](rust-lang/rust#91639) of warning-by-default for paths participating in elision much simpler. --- This new lint attempts to accomplish the goal of enforcing consistent syntax. In the process, it supersedes and replaces the existing `elided-named-lifetimes` lint, which means it starts out life as warn-by-default.
2 parents 0ba8f92 + 7d58616 commit 872febf

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tests/pass/fat_ptr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ fn fat_ptr_via_local(a: &[u8]) -> &[u8] {
1919
x
2020
}
2121

22-
fn fat_ptr_from_struct(s: FatPtrContainer) -> &[u8] {
22+
fn fat_ptr_from_struct(s: FatPtrContainer<'_>) -> &[u8] {
2323
s.ptr
2424
}
2525

26-
fn fat_ptr_to_struct(a: &[u8]) -> FatPtrContainer {
26+
fn fat_ptr_to_struct(a: &[u8]) -> FatPtrContainer<'_> {
2727
FatPtrContainer { ptr: a }
2828
}
2929

0 commit comments

Comments
 (0)