]> git.proxmox.com Git - rustc.git/blame - src/test/ui/in-band-lifetimes/elided-lifetimes.fixed
Update (un)suspicious files
[rustc.git] / src / test / ui / in-band-lifetimes / elided-lifetimes.fixed
CommitLineData
8faf50e0 1// run-rustfix
b7449926 2// edition:2018
8faf50e0
XL
3
4#![allow(unused)]
5#![deny(elided_lifetimes_in_paths)]
74b04a01 6//~^ NOTE the lint level is defined here
8faf50e0 7
a2a8927a 8use std::cell::{Ref, RefCell};
8faf50e0 9
a2a8927a
XL
10struct Foo<'a> {
11 x: &'a u32,
12}
8faf50e0
XL
13
14fn foo(x: &Foo<'_>) {
15 //~^ ERROR hidden lifetime parameters in types are deprecated
a2a8927a
XL
16 //~| NOTE expected named lifetime parameter
17 //~| HELP consider using the `'_` lifetime
8faf50e0
XL
18}
19
20fn bar(x: &Foo<'_>) {}
21
8faf50e0
XL
22struct Wrapped<'a>(&'a str);
23
24struct WrappedWithBow<'a> {
a2a8927a 25 gift: &'a str,
8faf50e0
XL
26}
27
28struct MatchedSet<'a, 'b> {
29 one: &'a str,
30 another: &'b str,
31}
32
33fn wrap_gift(gift: &str) -> Wrapped<'_> {
34 //~^ ERROR hidden lifetime parameters in types are deprecated
a2a8927a
XL
35 //~| NOTE expected named lifetime parameter
36 //~| HELP consider using the `'_` lifetime
8faf50e0
XL
37 Wrapped(gift)
38}
39
40fn wrap_gift_with_bow(gift: &str) -> WrappedWithBow<'_> {
41 //~^ ERROR hidden lifetime parameters in types are deprecated
a2a8927a
XL
42 //~| NOTE expected named lifetime parameter
43 //~| HELP consider using the `'_` lifetime
8faf50e0
XL
44 WrappedWithBow { gift }
45}
46
47fn inspect_matched_set(set: MatchedSet<'_, '_>) {
48 //~^ ERROR hidden lifetime parameters in types are deprecated
a2a8927a
XL
49 //~| NOTE expected 2 lifetime parameters
50 //~| HELP consider using the `'_` lifetime
8faf50e0
XL
51 println!("{} {}", set.one, set.another);
52}
53
a2a8927a
XL
54// Verify that the lint does not fire, because the added `'_` wouldn't be resolved correctly.
55fn match_sets() -> MatchedSet<'static, 'static> {
56 //~^ ERROR missing lifetime specifiers
57 //~| NOTE expected 2 lifetime parameters
58 //~| HELP this function's return type contains a borrowed value
59 //~| HELP consider using the `'static` lifetime
60 MatchedSet { one: "one", another: "another" }
61}
62
8faf50e0
XL
63macro_rules! autowrapper {
64 ($type_name:ident, $fn_name:ident, $lt:lifetime) => {
65 struct $type_name<$lt> {
66 gift: &$lt str
67 }
68
69 fn $fn_name(gift: &str) -> $type_name<'_> {
70 //~^ ERROR hidden lifetime parameters in types are deprecated
a2a8927a
XL
71 //~| NOTE expected named lifetime parameter
72 //~| HELP consider using the `'_` lifetime
73 //~| ERROR hidden lifetime parameters in types are deprecated
74 //~| NOTE expected named lifetime parameter
75 //~| HELP consider using the `'_` lifetime
8faf50e0
XL
76 $type_name { gift }
77 }
78 }
79}
80
81autowrapper!(Autowrapped, autowrap_gift, 'a);
82//~^ NOTE in this expansion of autowrapper!
83//~| NOTE in this expansion of autowrapper!
84
a2a8927a
XL
85// Verify that rustfix does not try to apply the fix twice.
86autowrapper!(AutowrappedAgain, autowrap_gift_again, 'a);
87//~^ NOTE in this expansion of autowrapper!
88//~| NOTE in this expansion of autowrapper!
89
8faf50e0
XL
90macro_rules! anytuple_ref_ty {
91 ($($types:ty),*) => {
92 Ref<'_, ($($types),*)>
93 //~^ ERROR hidden lifetime parameters in types are deprecated
a2a8927a
XL
94 //~| NOTE expected named lifetime parameter
95 //~| HELP consider using the `'_` lifetime
8faf50e0
XL
96 }
97}
98
a2a8927a
XL
99#[allow(elided_lifetimes_in_paths)]
100mod blah {
101 struct Thing<'a>(&'a i32);
102 struct Bar<T>(T);
103
104 fn foo(b: Bar<Thing>) {}
105}
106
8faf50e0
XL
107fn main() {
108 let honesty = RefCell::new((4, 'e'));
109 let loyalty: Ref<'_, (u32, char)> = honesty.borrow();
110 //~^ ERROR hidden lifetime parameters in types are deprecated
a2a8927a
XL
111 //~| NOTE expected named lifetime parameter
112 //~| HELP consider using the `'_` lifetime
8faf50e0
XL
113 let generosity = Ref::map(loyalty, |t| &t.0);
114
115 let laughter = RefCell::new((true, "magic"));
116 let yellow: anytuple_ref_ty!(bool, &str) = laughter.borrow();
117 //~^ NOTE in this expansion of anytuple_ref_ty!
118 //~| NOTE in this expansion of anytuple_ref_ty!
119}