Skip to content

Commit d12e7b0

Browse files
committed
Warn about hidden_lifetimes_in_output_paths by default
1 parent f6ec6b4 commit d12e7b0

File tree

50 files changed

+72
-75
lines changed

Some content is hidden

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

50 files changed

+72
-75
lines changed

compiler/rustc_lint/src/lifetime_style.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ declare_lint! {
136136
///
137137
/// [placeholder lifetime]: https://doc.rust-lang.org/reference/lifetime-elision.html#lifetime-elision-in-functions
138138
pub HIDDEN_LIFETIMES_IN_OUTPUT_PATHS,
139-
Allow,
139+
Warn,
140140
"hidden lifetime parameters in types in function return values are deprecated"
141141
}
142142

tests/ui/associated-types/associated-types-impl-redirect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ trait Iterator {
2121
}
2222

2323
trait IteratorExt: Iterator + Sized {
24-
fn by_ref(&mut self) -> ByRef<Self> {
24+
fn by_ref(&mut self) -> ByRef<'_, Self> {
2525
ByRef(self)
2626
}
2727
}

tests/ui/associated-types/associated-types-normalize-in-bounds-ufcs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ trait SliceExt2 {
2121
impl<T> SliceExt2 for [T] {
2222
type Item = T;
2323

24-
fn split2<P>(&self, pred: P) -> Splits<T, P> where P: FnMut(&T) -> bool {
24+
fn split2<P>(&self, pred: P) -> Splits<'_, T, P> where P: FnMut(&T) -> bool {
2525
loop {}
2626
}
2727

28-
fn splitn2<P>(&self, n: u32, pred: P) -> SplitsN<Splits<T, P>> where P: FnMut(&T) -> bool {
28+
fn splitn2<P>(&self, n: u32, pred: P) -> SplitsN<Splits<'_, T, P>> where P: FnMut(&T) -> bool {
2929
SliceExt2::split2(self, pred);
3030
loop {}
3131
}

tests/ui/associated-types/associated-types-normalize-in-bounds.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,17 @@ trait SliceExt2 {
2121
impl<T> SliceExt2 for [T] {
2222
type Item = T;
2323

24-
fn split2<P>(&self, pred: P) -> Splits<T, P> where P: FnMut(&T) -> bool {
24+
fn split2<P>(&self, pred: P) -> Splits<'_, T, P>
25+
where
26+
P: FnMut(&T) -> bool,
27+
{
2528
loop {}
2629
}
2730

28-
fn splitn2<P>(&self, n: usize, pred: P) -> SplitsN<Splits<T, P>> where P: FnMut(&T) -> bool {
31+
fn splitn2<P>(&self, n: usize, pred: P) -> SplitsN<Splits<'_, T, P>>
32+
where
33+
P: FnMut(&T) -> bool,
34+
{
2935
self.split2(pred);
3036
loop {}
3137
}

tests/ui/associated-types/associated-types-where-clause-impl-ambiguity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ trait Iterator {
2020
}
2121

2222
trait IteratorExt: Iterator + Sized {
23-
fn by_ref(&mut self) -> ByRef<Self> {
23+
fn by_ref(&mut self) -> ByRef<'_, Self> {
2424
ByRef(self)
2525
}
2626
}

tests/ui/associated-types/cache/elision.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(hidden_lifetimes_in_output_paths)]
2+
13
// Check that you are allowed to implement using elision but write
24
// trait without elision (a bug in this cropped up during
35
// bootstrapping, so this is a regression test).

tests/ui/associated-types/project-defer-unification.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ where P: Pixel + 'static,
5050
loop { }
5151
}
5252

53-
pub fn pixels_mut(&mut self) -> PixelsMut<P> {
53+
pub fn pixels_mut(&mut self) -> PixelsMut<'_, P> {
5454
loop { }
5555
}
5656
}

tests/ui/borrowck/copy-suggestion-region-vid.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub struct HelperStruct<'n> {
77
}
88

99
impl DataStruct {
10-
pub fn f(&self) -> HelperStruct {
10+
pub fn f(&self) -> HelperStruct<'_> {
1111
let helpers = [vec![], vec![]];
1212

1313
HelperStruct { helpers: helpers.clone(), is_empty: helpers[0].is_empty() }

tests/ui/borrowck/copy-suggestion-region-vid.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub struct HelperStruct<'n> {
77
}
88

99
impl DataStruct {
10-
pub fn f(&self) -> HelperStruct {
10+
pub fn f(&self) -> HelperStruct<'_> {
1111
let helpers = [vec![], vec![]];
1212

1313
HelperStruct { helpers, is_empty: helpers[0].is_empty() }

tests/ui/const-generics/type-dependent/issue-71348.full.stderr

-17
This file was deleted.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ LL + #![feature(unsized_const_params)]
1717
error: `&'static str` is forbidden as the type of a const generic parameter
1818
--> $DIR/issue-71348.rs:18:25
1919
|
20-
LL | fn ask<'a, const N: &'static str>(&'a self) -> &'a <Self as Get<N>>::Target
20+
LL | fn ask<'a, const N: &'static str>(&'a self) -> &'a <Self as Get<'a, N>>::Target
2121
| ^^^^^^^^^^^^
2222
|
2323
= note: the only supported types are integers, `bool`, and `char`

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ trait Get<'a, const N: &'static str> {
1515
}
1616

1717
impl Foo {
18-
fn ask<'a, const N: &'static str>(&'a self) -> &'a <Self as Get<N>>::Target
18+
fn ask<'a, const N: &'static str>(&'a self) -> &'a <Self as Get<'a, N>>::Target
1919
//[min]~^ ERROR `&'static str` is forbidden as the type of a const generic parameter
20-
//[full]~^^ WARNING lifetime flowing from input to output with different syntax
2120
where
2221
Self: Get<'a, N>,
2322
{

tests/ui/drop/drop-order-comparisons.e2021.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ impl Events {
548548
Ok(LogDrop(self, m))
549549
}
550550
/// Return an `Err` value that logs its drop.
551-
fn err(&self, m: u64) -> Result<LogDrop, LogDrop> {
551+
fn err(&self, m: u64) -> Result<LogDrop<'_>, LogDrop<'_>> {
552552
Err(LogDrop(self, m))
553553
}
554554
/// Log an event.

tests/ui/drop/drop-order-comparisons.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ impl Events {
548548
Ok(LogDrop(self, m))
549549
}
550550
/// Return an `Err` value that logs its drop.
551-
fn err(&self, m: u64) -> Result<LogDrop, LogDrop> {
551+
fn err(&self, m: u64) -> Result<LogDrop<'_>, LogDrop<'_>> {
552552
Err(LogDrop(self, m))
553553
}
554554
/// Log an event.

tests/ui/drop/drop_order.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ impl Drop for LoudDrop<'_> {
2222
}
2323

2424
impl DropOrderCollector {
25-
fn option_loud_drop(&self, n: u32) -> Option<LoudDrop> {
25+
fn option_loud_drop(&self, n: u32) -> Option<LoudDrop<'_>> {
2626
Some(LoudDrop(self, n))
2727
}
2828

29-
fn loud_drop(&self, n: u32) -> LoudDrop {
29+
fn loud_drop(&self, n: u32) -> LoudDrop<'_> {
3030
LoudDrop(self, n)
3131
}
3232

tests/ui/drop/drop_order_if_let_rescope.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl Drop for LoudDrop<'_> {
2020
}
2121

2222
impl DropOrderCollector {
23-
fn option_loud_drop(&self, n: u32) -> Option<LoudDrop> {
23+
fn option_loud_drop(&self, n: u32) -> Option<LoudDrop<'_>> {
2424
Some(LoudDrop(self, n))
2525
}
2626

tests/ui/drop/issue-2735-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl<'a> Drop for defer<'a> {
1414
}
1515
}
1616

17-
fn defer(b: &Cell<bool>) -> defer {
17+
fn defer(b: &Cell<bool>) -> defer<'_> {
1818
defer {
1919
b: b
2020
}

tests/ui/drop/issue-2735-3.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl<'a> Drop for defer<'a> {
1414
}
1515
}
1616

17-
fn defer(b: &Cell<bool>) -> defer {
17+
fn defer(b: &Cell<bool>) -> defer<'_> {
1818
defer {
1919
b: b
2020
}

tests/ui/drop/issue-979.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl<'a> Drop for r<'a> {
1313
}
1414
}
1515

16-
fn r(b: &Cell<isize>) -> r {
16+
fn r(b: &Cell<isize>) -> r<'_> {
1717
r {
1818
b: b
1919
}

tests/ui/drop/tail-expr-drop-order.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ impl Drop for LoudDrop<'_> {
2828
}
2929

3030
impl DropOrderCollector {
31-
fn option_loud_drop(&self, n: u32) -> Option<LoudDrop> {
31+
fn option_loud_drop(&self, n: u32) -> Option<LoudDrop<'_>> {
3232
Some(LoudDrop(self, n))
3333
}
3434

35-
fn loud_drop(&self, n: u32) -> LoudDrop {
35+
fn loud_drop(&self, n: u32) -> LoudDrop<'_> {
3636
LoudDrop(self, n)
3737
}
3838

tests/ui/higher-ranked/trait-bounds/normalize-under-binder/issue-62529-1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ where
2525

2626
impl<T: 'static> Inject for RefMutFamily<T> {
2727
type I = Self;
28-
fn inject(_: &()) -> <Self::I as FamilyLt>::Out {
28+
fn inject(_: &()) -> <Self::I as FamilyLt<'_>>::Out {
2929
unimplemented!()
3030
}
3131
}

tests/ui/issues/issue-2502.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl<'a> font<'a> {
1414
}
1515
}
1616

17-
fn font(fontbuf: &Vec<u8> ) -> font {
17+
fn font(fontbuf: &Vec<u8> ) -> font<'_> {
1818
font {
1919
fontbuf: fontbuf
2020
}

tests/ui/issues/issue-42552.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ run-pass
22
// Regression test for an obscure issue with the projection cache.
33

4-
fn into_iter<I: Iterator>(a: &I) -> Groups<I> {
4+
fn into_iter<I: Iterator>(a: &I) -> Groups<'_, I> {
55
Groups { _a: a }
66
}
77

tests/ui/issues/issue-47703-1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl Drop for AtomicBorrowRefMut {
1313
}
1414
}
1515

16-
fn map(orig: AtomicRefMut) -> AtomicRefMut {
16+
fn map(orig: AtomicRefMut<'_>) -> AtomicRefMut<'_> {
1717
AtomicRefMut {
1818
value: orig.value,
1919
borrow: orig.borrow,

tests/ui/issues/issue-5708.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct Outer<'a> {
2525
}
2626

2727
impl<'a> Outer<'a> {
28-
fn new(inner: &dyn Inner) -> Outer {
28+
fn new(inner: &dyn Inner) -> Outer<'_> {
2929
Outer {
3030
inner: inner
3131
}

tests/ui/late-bound-lifetimes/issue-47511.rs

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

3-
fn f(_: X) -> X {
3+
fn f(_: X<'_>) -> X<'_> {
44
unimplemented!()
55
}
66

tests/ui/late-bound-lifetimes/late_bound_through_alias.rs

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

3-
fn f(_: X) -> X {
3+
fn f(_: X<'_>) -> X<'_> {
44
unimplemented!()
55
}
66

tests/ui/lazy-type-alias/constrained-late-bound-regions.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#![feature(lazy_type_alias)]
55
#![allow(incomplete_features)]
6+
#![allow(hidden_lifetimes_in_output_paths)]
67

78
type Ref<'a> = &'a ();
89

tests/ui/lifetimes/elided-lifetime-in-path-in-impl-Fn.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
struct Foo<'a>(&'a ());
44

5-
fn with_fn() -> fn(Foo) {
5+
fn with_fn() -> fn(Foo<'_>) {
66
|_| ()
77
}
88

9-
fn with_impl_fn() -> impl Fn(Foo) {
9+
fn with_impl_fn() -> impl Fn(Foo<'_>) {
1010
|_| ()
1111
}
1212

tests/ui/lifetimes/issue-103582-hint-for-missing-lifetime-bound-on-trait-object-using-type-alias.fixed

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//@ run-rustfix
22

3+
#![allow(hidden_lifetimes_in_output_paths)]
4+
35
trait Greeter0 {
46
fn greet(&self);
57
}

tests/ui/lifetimes/issue-103582-hint-for-missing-lifetime-bound-on-trait-object-using-type-alias.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//@ run-rustfix
22

3+
#![allow(hidden_lifetimes_in_output_paths)]
4+
35
trait Greeter0 {
46
fn greet(&self);
57
}

tests/ui/lifetimes/issue-103582-hint-for-missing-lifetime-bound-on-trait-object-using-type-alias.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: lifetime may not live long enough
2-
--> $DIR/issue-103582-hint-for-missing-lifetime-bound-on-trait-object-using-type-alias.rs:32:9
2+
--> $DIR/issue-103582-hint-for-missing-lifetime-bound-on-trait-object-using-type-alias.rs:34:9
33
|
44
LL | pub fn get(&self, i: usize) -> BoxedGreeter {
55
| - let's call the lifetime of this reference `'1`

tests/ui/lifetimes/mismatched-lifetime-syntaxes-details/missing-lifetime-kind.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![deny(mismatched_lifetime_syntaxes)]
2+
#![allow(hidden_lifetimes_in_output_paths)]
23

34
fn ampersand<'a>(x: &'a u8) -> &u8 {
45
//~^ ERROR lifetime flowing from input to output with different syntax

tests/ui/lifetimes/mismatched-lifetime-syntaxes-details/missing-lifetime-kind.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: lifetime flowing from input to output with different syntax
2-
--> $DIR/missing-lifetime-kind.rs:3:22
2+
--> $DIR/missing-lifetime-kind.rs:4:22
33
|
44
LL | fn ampersand<'a>(x: &'a u8) -> &u8 {
55
| ^^ --- the elided lifetime gets resolved as `'a`
@@ -17,7 +17,7 @@ LL | fn ampersand<'a>(x: &'a u8) -> &'a u8 {
1717
| ++
1818

1919
error: lifetime flowing from input to output with different syntax
20-
--> $DIR/missing-lifetime-kind.rs:10:21
20+
--> $DIR/missing-lifetime-kind.rs:11:21
2121
|
2222
LL | fn brackets<'a>(x: &'a u8) -> Brackets {
2323
| ^^ -------- the elided lifetime gets resolved as `'a`
@@ -30,7 +30,7 @@ LL | fn brackets<'a>(x: &'a u8) -> Brackets<'a> {
3030
| ++++
3131

3232
error: lifetime flowing from input to output with different syntax
33-
--> $DIR/missing-lifetime-kind.rs:17:18
33+
--> $DIR/missing-lifetime-kind.rs:18:18
3434
|
3535
LL | fn comma<'a>(x: &'a u8) -> Comma<u8> {
3636
| ^^ --------- the elided lifetime gets resolved as `'a`
@@ -43,7 +43,7 @@ LL | fn comma<'a>(x: &'a u8) -> Comma<'a, u8> {
4343
| +++
4444

4545
error: lifetime flowing from input to output with different syntax
46-
--> $DIR/missing-lifetime-kind.rs:22:23
46+
--> $DIR/missing-lifetime-kind.rs:23:23
4747
|
4848
LL | fn underscore<'a>(x: &'a u8) -> &'_ u8 {
4949
| ^^ -- the elided lifetime gets resolved as `'a`

tests/ui/lifetimes/mismatched-lifetime-syntaxes-details/static.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![deny(mismatched_lifetime_syntaxes)]
2+
#![allow(hidden_lifetimes_in_output_paths)]
23

34
use std::borrow::Cow;
45

tests/ui/lifetimes/mismatched-lifetime-syntaxes-details/static.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: lifetime flowing from input to output with different syntax
2-
--> $DIR/static.rs:16:18
2+
--> $DIR/static.rs:17:18
33
|
44
LL | fn ampersand(x: &'static u8) -> &u8 {
55
| ^^^^^^^ --- the elided lifetime gets resolved as `'static`
@@ -17,7 +17,7 @@ LL | fn ampersand(x: &'static u8) -> &'static u8 {
1717
| +++++++
1818

1919
error: lifetime flowing from input to output with different syntax
20-
--> $DIR/static.rs:23:17
20+
--> $DIR/static.rs:24:17
2121
|
2222
LL | fn brackets(x: &'static u8) -> Brackets {
2323
| ^^^^^^^ -------- the elided lifetime gets resolved as `'static`
@@ -30,7 +30,7 @@ LL | fn brackets(x: &'static u8) -> Brackets<'static> {
3030
| +++++++++
3131

3232
error: lifetime flowing from input to output with different syntax
33-
--> $DIR/static.rs:30:14
33+
--> $DIR/static.rs:31:14
3434
|
3535
LL | fn comma(x: &'static u8) -> Comma<u8> {
3636
| ^^^^^^^ --------- the elided lifetime gets resolved as `'static`
@@ -43,7 +43,7 @@ LL | fn comma(x: &'static u8) -> Comma<'static, u8> {
4343
| ++++++++
4444

4545
error: lifetime flowing from input to output with different syntax
46-
--> $DIR/static.rs:35:19
46+
--> $DIR/static.rs:36:19
4747
|
4848
LL | fn underscore(x: &'static u8) -> &'_ u8 {
4949
| ^^^^^^^ -- the elided lifetime gets resolved as `'static`

0 commit comments

Comments
 (0)