-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split needless_lifetime '_ suggestions into elidable_lifetime_names
- Loading branch information
Showing
14 changed files
with
456 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#![warn(clippy::needless_lifetimes, clippy::elidable_lifetime_names)] | ||
|
||
type Ref<'r> = &'r u8; | ||
|
||
// No error; same lifetime on two params. | ||
fn lifetime_param_1<'a>(_x: Ref<'a>, _y: &'a u8) {} | ||
|
||
fn lifetime_param_2(_x: Ref<'_>, _y: &u8) {} | ||
|
||
// No error; bounded lifetime. | ||
fn lifetime_param_3<'a, 'b: 'a>(_x: Ref<'a>, _y: &'b u8) {} | ||
|
||
// No error; bounded lifetime. | ||
fn lifetime_param_4<'a, 'b>(_x: Ref<'a>, _y: &'b u8) | ||
where | ||
'b: 'a, | ||
{ | ||
} | ||
|
||
struct Lt<'a, I: 'static> { | ||
x: &'a I, | ||
} | ||
|
||
// No error; fn bound references `'a`. | ||
fn fn_bound<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I> | ||
where | ||
F: Fn(Lt<'a, I>) -> Lt<'a, I>, | ||
{ | ||
unreachable!() | ||
} | ||
|
||
fn fn_bound_2<F, I>(_m: Lt<'_, I>, _f: F) -> Lt<'_, I> | ||
where | ||
for<'x> F: Fn(Lt<'x, I>) -> Lt<'x, I>, | ||
{ | ||
unreachable!() | ||
} | ||
|
||
struct Foo<'a>(&'a u8); | ||
|
||
fn struct_with_lt(_foo: Foo<'_>) -> &str { | ||
unimplemented!() | ||
} | ||
|
||
// No warning; two input lifetimes (named on the reference, anonymous on `Foo`). | ||
fn struct_with_lt2<'a>(_foo: &'a Foo) -> &'a str { | ||
unimplemented!() | ||
} | ||
|
||
// No warning; two input lifetimes (anonymous on the reference, named on `Foo`). | ||
fn struct_with_lt3<'a>(_foo: &Foo<'a>) -> &'a str { | ||
unimplemented!() | ||
} | ||
|
||
// Warning; two input lifetimes, but the output lifetime is not elided, i.e., the following is | ||
// valid: | ||
// fn struct_with_lt4a<'a>(_foo: &'a Foo<'_>) -> &'a str | ||
// ^^ | ||
fn struct_with_lt4a<'a>(_foo: &'a Foo<'_>) -> &'a str { | ||
unimplemented!() | ||
} | ||
|
||
type FooAlias<'a> = Foo<'a>; | ||
|
||
fn alias_with_lt(_foo: FooAlias<'_>) -> &str { | ||
unimplemented!() | ||
} | ||
|
||
// No warning; two input lifetimes (named on the reference, anonymous on `FooAlias`). | ||
fn alias_with_lt2<'a>(_foo: &'a FooAlias) -> &'a str { | ||
unimplemented!() | ||
} | ||
|
||
// No warning; two input lifetimes (anonymous on the reference, named on `FooAlias`). | ||
fn alias_with_lt3<'a>(_foo: &FooAlias<'a>) -> &'a str { | ||
unimplemented!() | ||
} | ||
|
||
// Warning; two input lifetimes, but the output lifetime is not elided, i.e., the following is | ||
// valid: | ||
// fn alias_with_lt4a<'a>(_foo: &'a FooAlias<'_>) -> &'a str | ||
// ^^ | ||
fn alias_with_lt4a<'a>(_foo: &'a FooAlias<'_>) -> &'a str { | ||
unimplemented!() | ||
} | ||
|
||
// Issue #3284: give hint regarding lifetime in return type. | ||
struct Cow<'a> { | ||
x: &'a str, | ||
} | ||
fn out_return_type_lts(e: &str) -> Cow<'_> { | ||
unimplemented!() | ||
} | ||
|
||
mod issue2944 { | ||
trait Foo {} | ||
struct Bar; | ||
struct Baz<'a> { | ||
bar: &'a Bar, | ||
} | ||
|
||
impl Foo for Baz<'_> {} | ||
impl Bar { | ||
fn baz(&self) -> impl Foo + '_ { | ||
Baz { bar: self } | ||
} | ||
} | ||
} |
Oops, something went wrong.