Skip to content

Commit 8b59e34

Browse files
committed
Replace elided_named_lifetimes with mismatched_lifetime_syntaxes
1 parent 4effc58 commit 8b59e34

15 files changed

+54
-45
lines changed

tests/ui/explicit_iter_loop.fixed

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ fn main() {
7777

7878
struct NoIntoIter();
7979
impl NoIntoIter {
80-
fn iter(&self) -> slice::Iter<u8> {
80+
fn iter(&self) -> slice::Iter<'_, u8> {
8181
unimplemented!()
8282
}
8383

84-
fn iter_mut(&mut self) -> slice::IterMut<u8> {
84+
fn iter_mut(&mut self) -> slice::IterMut<'_, u8> {
8585
unimplemented!()
8686
}
8787
}

tests/ui/explicit_iter_loop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ fn main() {
7777

7878
struct NoIntoIter();
7979
impl NoIntoIter {
80-
fn iter(&self) -> slice::Iter<u8> {
80+
fn iter(&self) -> slice::Iter<'_, u8> {
8181
unimplemented!()
8282
}
8383

84-
fn iter_mut(&mut self) -> slice::IterMut<u8> {
84+
fn iter_mut(&mut self) -> slice::IterMut<'_, u8> {
8585
unimplemented!()
8686
}
8787
}

tests/ui/iter_next_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn main() {
88

99
struct Unrelated(&'static [u8]);
1010
impl Unrelated {
11-
fn next(&self) -> std::slice::Iter<u8> {
11+
fn next(&self) -> std::slice::Iter<'_, u8> {
1212
self.0.iter()
1313
}
1414
}

tests/ui/iter_not_returning_iterator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl S {
7171

7272
struct S2([u8]);
7373
impl S2 {
74-
fn iter(&self) -> core::slice::Iter<u8> {
74+
fn iter(&self) -> core::slice::Iter<'_, u8> {
7575
self.0.iter()
7676
}
7777
}

tests/ui/methods.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct Lt2<'a> {
4949

5050
impl<'a> Lt2<'a> {
5151
// The lifetime is different, but that’s irrelevant; see issue #734.
52-
pub fn new(s: &str) -> Lt2 {
52+
pub fn new(s: &str) -> Lt2<'_> {
5353
unimplemented!()
5454
}
5555
}

tests/ui/needless_lifetimes.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
clippy::unnecessary_wraps,
1111
dyn_drop,
1212
clippy::get_first,
13-
elided_named_lifetimes
13+
mismatched_lifetime_syntaxes,
1414
)]
1515

1616
extern crate proc_macros;

tests/ui/needless_lifetimes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
clippy::unnecessary_wraps,
1111
dyn_drop,
1212
clippy::get_first,
13-
elided_named_lifetimes
13+
mismatched_lifetime_syntaxes,
1414
)]
1515

1616
extern crate proc_macros;

tests/ui/ptr_arg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ mod issue_9218 {
312312

313313
// Inferred to be `&'a str`, afaik.
314314
fn cow_good_ret_ty<'a>(input: &'a Cow<'a, str>) -> &str {
315-
//~^ ERROR: elided lifetime has a name
315+
//~^ ERROR: lifetime flowing from input to output with different syntax
316316
todo!()
317317
}
318318
}

tests/ui/ptr_arg.stderr

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
error: elided lifetime has a name
2-
--> tests/ui/ptr_arg.rs:314:56
3-
|
4-
LL | fn cow_good_ret_ty<'a>(input: &'a Cow<'a, str>) -> &str {
5-
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
6-
|
7-
= note: `-D elided-named-lifetimes` implied by `-D warnings`
8-
= help: to override `-D warnings` add `#[allow(elided_named_lifetimes)]`
9-
101
error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
112
--> tests/ui/ptr_arg.rs:13:14
123
|
@@ -240,5 +231,21 @@ error: writing `&String` instead of `&str` involves a new object where a slice w
240231
LL | fn good(v1: &String, v2: &String) {
241232
| ^^^^^^^ help: change this to: `&str`
242233

234+
error: lifetime flowing from input to output with different syntax can be confusing
235+
--> tests/ui/ptr_arg.rs:314:36
236+
|
237+
LL | fn cow_good_ret_ty<'a>(input: &'a Cow<'a, str>) -> &str {
238+
| ^^ ^^ ---- the lifetime gets resolved as `'a`
239+
| | |
240+
| | these lifetimes flow to the output
241+
| these lifetimes flow to the output
242+
|
243+
= note: `-D mismatched-lifetime-syntaxes` implied by `-D warnings`
244+
= help: to override `-D warnings` add `#[allow(mismatched_lifetime_syntaxes)]`
245+
help: one option is to consistently use `'a`
246+
|
247+
LL | fn cow_good_ret_ty<'a>(input: &'a Cow<'a, str>) -> &'a str {
248+
| ++
249+
243250
error: aborting due to 27 previous errors
244251

tests/ui/significant_drop_in_scrutinee.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ struct CounterWrapper<'a> {
191191
}
192192

193193
impl<'a> CounterWrapper<'a> {
194-
fn new(counter: &Counter) -> CounterWrapper {
194+
fn new(counter: &Counter) -> CounterWrapper<'_> {
195195
counter.i.fetch_add(1, Ordering::Relaxed);
196196
CounterWrapper { counter }
197197
}
@@ -204,7 +204,7 @@ impl<'a> Drop for CounterWrapper<'a> {
204204
}
205205

206206
impl Counter {
207-
fn temp_increment(&self) -> Vec<CounterWrapper> {
207+
fn temp_increment(&self) -> Vec<CounterWrapper<'_>> {
208208
vec![CounterWrapper::new(self), CounterWrapper::new(self)]
209209
}
210210
}
@@ -480,7 +480,7 @@ impl StateWithBoxedMutexGuard {
480480
fn new() -> StateWithBoxedMutexGuard {
481481
StateWithBoxedMutexGuard { u: Mutex::new(42) }
482482
}
483-
fn lock(&self) -> Box<MutexGuard<u64>> {
483+
fn lock(&self) -> Box<MutexGuard<'_, u64>> {
484484
Box::new(self.u.lock().unwrap())
485485
}
486486
}
@@ -507,7 +507,7 @@ impl StateStringWithBoxedMutexGuard {
507507
s: Mutex::new("A String".to_owned()),
508508
}
509509
}
510-
fn lock(&self) -> Box<MutexGuard<String>> {
510+
fn lock(&self) -> Box<MutexGuard<'_, String>> {
511511
Box::new(self.s.lock().unwrap())
512512
}
513513
}
@@ -686,11 +686,11 @@ struct Guard<'a, T>(MutexGuard<'a, T>);
686686
struct Ref<'a, T>(&'a T);
687687

688688
impl<'a, T> Guard<'a, T> {
689-
fn guard(&self) -> &MutexGuard<T> {
689+
fn guard(&self) -> &MutexGuard<'_, T> {
690690
&self.0
691691
}
692692

693-
fn guard_ref(&self) -> Ref<MutexGuard<T>> {
693+
fn guard_ref(&self) -> Ref<'_, MutexGuard<'_, T>> {
694694
Ref(&self.0)
695695
}
696696

0 commit comments

Comments
 (0)