Skip to content

Commit a9b959a

Browse files
committed
elided_named_lifetimes: bless & add tests
1 parent f7b0b22 commit a9b959a

File tree

45 files changed

+460
-27
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+460
-27
lines changed

Diff for: src/tools/clippy/tests/ui/needless_lifetimes.stderr

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
error: elided lifetime has a name
2+
--> tests/ui/needless_lifetimes.rs:266:52
3+
|
4+
LL | fn named_input_elided_output<'a>(_arg: &'a str) -> &str {
5+
| -- ^ this elided lifetime gets resolved as `'a`
6+
| |
7+
| lifetime `'a` declared here
8+
|
9+
= note: `-D elided-named-lifetimes` implied by `-D warnings`
10+
= help: to override `-D warnings` add `#[allow(elided_named_lifetimes)]`
11+
112
error: the following explicit lifetimes could be elided: 'a, 'b
213
--> tests/ui/needless_lifetimes.rs:17:23
314
|
@@ -553,5 +564,5 @@ LL - fn one_input<'a>(x: &'a u8) -> &'a u8 {
553564
LL + fn one_input(x: &u8) -> &u8 {
554565
|
555566

556-
error: aborting due to 46 previous errors
567+
error: aborting due to 47 previous errors
557568

Diff for: src/tools/clippy/tests/ui/ptr_arg.stderr

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
error: elided lifetime has a name
2+
--> tests/ui/ptr_arg.rs:295: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+
110
error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
211
--> tests/ui/ptr_arg.rs:13:14
312
|
@@ -212,5 +221,5 @@ error: using a reference to `Cow` is not recommended
212221
LL | fn cow_bad_ret_ty_2<'a, 'b>(input: &'a Cow<'a, str>) -> &'b str {
213222
| ^^^^^^^^^^^^^^^^ help: change this to: `&str`
214223

215-
error: aborting due to 24 previous errors
224+
error: aborting due to 25 previous errors
216225

Diff for: tests/ui/async-await/issues/issue-63388-1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ trait Foo {}
99
impl Xyz {
1010
async fn do_sth<'a>(
1111
&'a self, foo: &dyn Foo
12-
) -> &dyn Foo
12+
) -> &dyn Foo //~ WARNING elided lifetime has a name
1313
{
1414
//~^ ERROR explicit lifetime required in the type of `foo` [E0621]
1515
foo

Diff for: tests/ui/async-await/issues/issue-63388-1.stderr

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
warning: elided lifetime has a name
2+
--> $DIR/issue-63388-1.rs:12:10
3+
|
4+
LL | async fn do_sth<'a>(
5+
| -- lifetime `'a` declared here
6+
LL | &'a self, foo: &dyn Foo
7+
LL | ) -> &dyn Foo
8+
| ^ this elided lifetime gets resolved as `'a`
9+
|
10+
= note: `#[warn(elided_named_lifetimes)]` on by default
11+
112
error[E0621]: explicit lifetime required in the type of `foo`
213
--> $DIR/issue-63388-1.rs:13:5
314
|
@@ -10,6 +21,6 @@ LL | | foo
1021
LL | | }
1122
| |_____^ lifetime `'a` required
1223

13-
error: aborting due to 1 previous error
24+
error: aborting due to 1 previous error; 1 warning emitted
1425

1526
For more information about this error, try `rustc --explain E0621`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
warning: elided lifetime has a name
2+
--> $DIR/issue-71348.rs:18:68
3+
|
4+
LL | fn ask<'a, const N: &'static str>(&'a self) -> &'a <Self as Get<N>>::Target
5+
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
6+
|
7+
= note: `#[warn(elided_named_lifetimes)]` on by default
8+
9+
warning: 1 warning emitted
10+

Diff for: tests/ui/const-generics/type-dependent/issue-71348.min.stderr

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
warning: elided lifetime has a name
2+
--> $DIR/issue-71348.rs:18:68
3+
|
4+
LL | fn ask<'a, const N: &'static str>(&'a self) -> &'a <Self as Get<N>>::Target
5+
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
6+
|
7+
= note: `#[warn(elided_named_lifetimes)]` on by default
8+
19
error: `&'static str` is forbidden as the type of a const generic parameter
210
--> $DIR/issue-71348.rs:10:24
311
|
@@ -30,5 +38,5 @@ help: add `#![feature(unsized_const_params)]` to the crate attributes to enable
3038
LL + #![feature(unsized_const_params)]
3139
|
3240

33-
error: aborting due to 2 previous errors
41+
error: aborting due to 2 previous errors; 1 warning emitted
3442

Diff for: tests/ui/const-generics/type-dependent/issue-71348.rs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ trait Get<'a, const N: &'static str> {
1717
impl Foo {
1818
fn ask<'a, const N: &'static str>(&'a self) -> &'a <Self as Get<N>>::Target
1919
//[min]~^ ERROR `&'static str` is forbidden as the type of a const generic parameter
20+
//~^^ WARNING elided lifetime has a name
2021
where
2122
Self: Get<'a, N>,
2223
{

Diff for: tests/ui/consts/min_const_fn/min_const_fn.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ impl<T> Foo<T> {
4444
impl<'a, T> Foo<T> {
4545
const fn new_lt(t: T) -> Self { Foo(t) }
4646
const fn into_inner_lt(self) -> T { self.0 } //~ destructor of
47-
const fn get_lt(&'a self) -> &T { &self.0 }
48-
const fn get_mut_lt(&'a mut self) -> &mut T { &mut self.0 }
47+
const fn get_lt(&'a self) -> &T { &self.0 } //~ WARNING elided lifetime has a name
48+
const fn get_mut_lt(&'a mut self) -> &mut T { &mut self.0 } //~ WARNING elided lifetime has a name
4949
//~^ mutable references
5050
//~| mutable references
5151
//~| mutable references

Diff for: tests/ui/consts/min_const_fn/min_const_fn.stderr

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
warning: elided lifetime has a name
2+
--> $DIR/min_const_fn.rs:47:34
3+
|
4+
LL | impl<'a, T> Foo<T> {
5+
| -- lifetime `'a` declared here
6+
...
7+
LL | const fn get_lt(&'a self) -> &T { &self.0 }
8+
| ^ this elided lifetime gets resolved as `'a`
9+
|
10+
= note: `#[warn(elided_named_lifetimes)]` on by default
11+
12+
warning: elided lifetime has a name
13+
--> $DIR/min_const_fn.rs:48:42
14+
|
15+
LL | impl<'a, T> Foo<T> {
16+
| -- lifetime `'a` declared here
17+
...
18+
LL | const fn get_mut_lt(&'a mut self) -> &mut T { &mut self.0 }
19+
| ^ this elided lifetime gets resolved as `'a`
20+
121
error[E0493]: destructor of `Foo<T>` cannot be evaluated at compile-time
222
--> $DIR/min_const_fn.rs:37:25
323
|
@@ -228,7 +248,7 @@ LL | const fn no_apit(_x: impl std::fmt::Debug) {}
228248
| |
229249
| the destructor for this type cannot be evaluated in constant functions
230250

231-
error: aborting due to 24 previous errors
251+
error: aborting due to 24 previous errors; 2 warnings emitted
232252

233253
Some errors have detailed explanations: E0493, E0658.
234254
For more information about an error, try `rustc --explain E0493`.

Diff for: tests/ui/generics/generic-no-mangle.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ run-rustfix
2-
#![allow(dead_code)]
2+
#![allow(dead_code, elided_named_lifetimes)]
33
#![deny(no_mangle_generic_items)]
44

55
pub fn foo<T>() {} //~ ERROR functions generic over types or consts must be mangled

Diff for: tests/ui/generics/generic-no-mangle.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ run-rustfix
2-
#![allow(dead_code)]
2+
#![allow(dead_code, elided_named_lifetimes)]
33
#![deny(no_mangle_generic_items)]
44

55
#[no_mangle]

Diff for: tests/ui/impl-trait/impl-fn-hrtb-bounds.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ fn b() -> impl for<'a> Fn(&'a u8) -> (impl Debug + 'a) {
1313

1414
fn c() -> impl for<'a> Fn(&'a u8) -> (impl Debug + '_) {
1515
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
16+
//~| WARNING elided lifetime has a name
1617
|x| x
1718
}
1819

Diff for: tests/ui/impl-trait/impl-fn-hrtb-bounds.stderr

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0106]: missing lifetime specifier
2-
--> $DIR/impl-fn-hrtb-bounds.rs:19:38
2+
--> $DIR/impl-fn-hrtb-bounds.rs:20:38
33
|
44
LL | fn d() -> impl Fn() -> (impl Debug + '_) {
55
| ^^ expected named lifetime parameter
@@ -10,6 +10,14 @@ help: consider using the `'static` lifetime, but this is uncommon unless you're
1010
LL | fn d() -> impl Fn() -> (impl Debug + 'static) {
1111
| ~~~~~~~
1212

13+
warning: elided lifetime has a name
14+
--> $DIR/impl-fn-hrtb-bounds.rs:14:52
15+
|
16+
LL | fn c() -> impl for<'a> Fn(&'a u8) -> (impl Debug + '_) {
17+
| -- lifetime `'a` declared here ^^ this elided lifetime gets resolved as `'a`
18+
|
19+
= note: `#[warn(elided_named_lifetimes)]` on by default
20+
1321
error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
1422
--> $DIR/impl-fn-hrtb-bounds.rs:4:41
1523
|
@@ -46,7 +54,7 @@ note: lifetime declared here
4654
LL | fn c() -> impl for<'a> Fn(&'a u8) -> (impl Debug + '_) {
4755
| ^^
4856

49-
error: aborting due to 4 previous errors
57+
error: aborting due to 4 previous errors; 1 warning emitted
5058

5159
Some errors have detailed explanations: E0106, E0657.
5260
For more information about an error, try `rustc --explain E0106`.

Diff for: tests/ui/impl-trait/impl-fn-predefined-lifetimes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::fmt::Debug;
33

44
fn a<'a>() -> impl Fn(&'a u8) -> (impl Debug + '_) {
55
//~^ ERROR cannot resolve opaque type
6+
//~| WARNING elided lifetime has a name
67
|x| x
78
//~^ ERROR expected generic lifetime parameter, found `'_`
89
}
+11-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
warning: elided lifetime has a name
2+
--> $DIR/impl-fn-predefined-lifetimes.rs:4:48
3+
|
4+
LL | fn a<'a>() -> impl Fn(&'a u8) -> (impl Debug + '_) {
5+
| -- lifetime `'a` declared here ^^ this elided lifetime gets resolved as `'a`
6+
|
7+
= note: `#[warn(elided_named_lifetimes)]` on by default
8+
19
error[E0792]: expected generic lifetime parameter, found `'_`
2-
--> $DIR/impl-fn-predefined-lifetimes.rs:6:9
10+
--> $DIR/impl-fn-predefined-lifetimes.rs:7:9
311
|
412
LL | fn a<'a>() -> impl Fn(&'a u8) -> (impl Debug + '_) {
513
| -- this generic parameter must be used with a generic lifetime parameter
6-
LL |
14+
...
715
LL | |x| x
816
| ^
917

@@ -13,7 +21,7 @@ error[E0720]: cannot resolve opaque type
1321
LL | fn a<'a>() -> impl Fn(&'a u8) -> (impl Debug + '_) {
1422
| ^^^^^^^^^^^^^^^ cannot resolve opaque type
1523

16-
error: aborting due to 2 previous errors
24+
error: aborting due to 2 previous errors; 1 warning emitted
1725

1826
Some errors have detailed explanations: E0720, E0792.
1927
For more information about an error, try `rustc --explain E0720`.

Diff for: tests/ui/impl-trait/rpit-assoc-pair-with-lifetime.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//@ check-pass
22

33
pub fn iter<'a>(v: Vec<(u32, &'a u32)>) -> impl DoubleEndedIterator<Item = (u32, &u32)> {
4+
//~^ WARNING elided lifetime has a name
45
v.into_iter()
56
}
67

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
warning: elided lifetime has a name
2+
--> $DIR/rpit-assoc-pair-with-lifetime.rs:3:82
3+
|
4+
LL | pub fn iter<'a>(v: Vec<(u32, &'a u32)>) -> impl DoubleEndedIterator<Item = (u32, &u32)> {
5+
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
6+
|
7+
= note: `#[warn(elided_named_lifetimes)]` on by default
8+
9+
warning: 1 warning emitted
10+

Diff for: tests/ui/lifetimes/lifetime-elision-return-type-requires-explicit-lifetime.rs

+1
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@ fn l<'a>(_: &'a str, _: &'a str) -> &str { "" }
4747

4848
// This is ok because both `'a` are for the same parameter.
4949
fn m<'a>(_: &'a Foo<'a>) -> &str { "" }
50+
//~^ WARNING elided lifetime has a name
5051

5152
fn main() {}

Diff for: tests/ui/lifetimes/lifetime-elision-return-type-requires-explicit-lifetime.stderr

+11-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ help: consider using the `'a` lifetime
105105
LL | fn l<'a>(_: &'a str, _: &'a str) -> &'a str { "" }
106106
| ++
107107

108-
error: aborting due to 7 previous errors
108+
warning: elided lifetime has a name
109+
--> $DIR/lifetime-elision-return-type-requires-explicit-lifetime.rs:49:29
110+
|
111+
LL | fn m<'a>(_: &'a Foo<'a>) -> &str { "" }
112+
| -- ^ this elided lifetime gets resolved as `'a`
113+
| |
114+
| lifetime `'a` declared here
115+
|
116+
= note: `#[warn(elided_named_lifetimes)]` on by default
117+
118+
error: aborting due to 7 previous errors; 1 warning emitted
109119

110120
For more information about this error, try `rustc --explain E0106`.

Diff for: tests/ui/lifetimes/lifetime-errors/ex1-return-one-existing-name-if-else-using-impl-3.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ struct Foo {
44

55
impl Foo {
66
fn foo<'a>(&'a self, x: &i32) -> &i32 {
7+
//~^ WARNING elided lifetime has a name
78

89
if true { &self.field } else { x } //~ ERROR explicit lifetime
910

Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1+
warning: elided lifetime has a name
2+
--> $DIR/ex1-return-one-existing-name-if-else-using-impl-3.rs:6:36
3+
|
4+
LL | fn foo<'a>(&'a self, x: &i32) -> &i32 {
5+
| -- ^ this elided lifetime gets resolved as `'a`
6+
| |
7+
| lifetime `'a` declared here
8+
|
9+
= note: `#[warn(elided_named_lifetimes)]` on by default
10+
111
error[E0621]: explicit lifetime required in the type of `x`
2-
--> $DIR/ex1-return-one-existing-name-if-else-using-impl-3.rs:8:36
12+
--> $DIR/ex1-return-one-existing-name-if-else-using-impl-3.rs:9:36
313
|
414
LL | fn foo<'a>(&'a self, x: &i32) -> &i32 {
515
| ---- help: add explicit lifetime `'a` to the type of `x`: `&'a i32`
6-
LL |
16+
...
717
LL | if true { &self.field } else { x }
818
| ^ lifetime `'a` required
919

10-
error: aborting due to 1 previous error
20+
error: aborting due to 1 previous error; 1 warning emitted
1121

1222
For more information about this error, try `rustc --explain E0621`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![deny(elided_named_lifetimes)]
2+
3+
struct Foo;
4+
5+
impl Foo {
6+
pub fn get_mut(&'static self, x: &mut u8) -> &mut u8 {
7+
//~^ ERROR elided lifetime has a name
8+
unsafe { &mut *(x as *mut _) }
9+
}
10+
}
11+
12+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: elided lifetime has a name
2+
--> $DIR/example-from-issue48686.rs:6:50
3+
|
4+
LL | pub fn get_mut(&'static self, x: &mut u8) -> &mut u8 {
5+
| ^ this elided lifetime gets resolved as `'static`
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/example-from-issue48686.rs:1:9
9+
|
10+
LL | #![deny(elided_named_lifetimes)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to 1 previous error
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#![deny(elided_named_lifetimes)]
2+
3+
fn ampersand<'a>(x: &'a u8) -> &u8 {
4+
//~^ ERROR elided lifetime has a name
5+
x
6+
}
7+
8+
struct Brackets<'a>(&'a u8);
9+
10+
fn brackets<'a>(x: &'a u8) -> Brackets {
11+
//~^ ERROR elided lifetime has a name
12+
Brackets(x)
13+
}
14+
15+
struct Comma<'a, T>(&'a T);
16+
17+
fn comma<'a>(x: &'a u8) -> Comma<u8> {
18+
//~^ ERROR elided lifetime has a name
19+
Comma(x)
20+
}
21+
22+
fn underscore<'a>(x: &'a u8) -> &'_ u8 {
23+
//~^ ERROR elided lifetime has a name
24+
x
25+
}
26+
27+
fn main() {}

0 commit comments

Comments
 (0)