Skip to content

Commit e0cec6b

Browse files
test that '_ is not linted by single_char_lifetime_names
1 parent dd569f4 commit e0cec6b

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

tests/ui/single_char_lifetime_names.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![warn(clippy::single_char_lifetime_names)]
22

3+
// Lifetimes should only be linted when they're introduced
34
struct DiagnosticCtx<'a, 'b>
45
where
56
'a: 'b,
@@ -8,6 +9,7 @@ where
89
_unit: &'b (),
910
}
1011

12+
// Only the lifetimes on the `impl`'s generics should be linted
1113
impl<'a, 'b> DiagnosticCtx<'a, 'b> {
1214
fn new(source: &'a str, unit: &'b ()) -> DiagnosticCtx<'a, 'b> {
1315
Self {
@@ -17,6 +19,7 @@ impl<'a, 'b> DiagnosticCtx<'a, 'b> {
1719
}
1820
}
1921

22+
// No lifetimes should be linted here
2023
impl<'src, 'unit> DiagnosticCtx<'src, 'unit> {
2124
fn new_pass(source: &'src str, unit: &'unit ()) -> DiagnosticCtx<'src, 'unit> {
2225
Self {
@@ -26,6 +29,13 @@ impl<'src, 'unit> DiagnosticCtx<'src, 'unit> {
2629
}
2730
}
2831

32+
// Only 'a should be linted here
33+
fn split_once<'a>(base: &'a str, other: &'_ str) -> (&'a str, Option<&'a str>) {
34+
base.split_once(other)
35+
.map(|(left, right)| (left, Some(right)))
36+
.unwrap_or((base, None))
37+
}
38+
2939
fn main() {
3040
let src = "loop {}";
3141
let unit = ();
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: single-character lifetime names are likely uninformative
2-
--> $DIR/single_char_lifetime_names.rs:3:22
2+
--> $DIR/single_char_lifetime_names.rs:4:22
33
|
44
LL | struct DiagnosticCtx<'a, 'b>
55
| ^^
@@ -8,28 +8,36 @@ LL | struct DiagnosticCtx<'a, 'b>
88
= help: use a more informative name
99

1010
error: single-character lifetime names are likely uninformative
11-
--> $DIR/single_char_lifetime_names.rs:3:26
11+
--> $DIR/single_char_lifetime_names.rs:4:26
1212
|
1313
LL | struct DiagnosticCtx<'a, 'b>
1414
| ^^
1515
|
1616
= help: use a more informative name
1717

1818
error: single-character lifetime names are likely uninformative
19-
--> $DIR/single_char_lifetime_names.rs:11:6
19+
--> $DIR/single_char_lifetime_names.rs:13:6
2020
|
2121
LL | impl<'a, 'b> DiagnosticCtx<'a, 'b> {
2222
| ^^
2323
|
2424
= help: use a more informative name
2525

2626
error: single-character lifetime names are likely uninformative
27-
--> $DIR/single_char_lifetime_names.rs:11:10
27+
--> $DIR/single_char_lifetime_names.rs:13:10
2828
|
2929
LL | impl<'a, 'b> DiagnosticCtx<'a, 'b> {
3030
| ^^
3131
|
3232
= help: use a more informative name
3333

34-
error: aborting due to 4 previous errors
34+
error: single-character lifetime names are likely uninformative
35+
--> $DIR/single_char_lifetime_names.rs:33:15
36+
|
37+
LL | fn split_once<'a>(base: &'a str, other: &'_ str) -> (&'a str, Option<&'a str>) {
38+
| ^^
39+
|
40+
= help: use a more informative name
41+
42+
error: aborting due to 5 previous errors
3543

0 commit comments

Comments
 (0)