5 #![deny(elided_lifetimes_in_paths)]
6 //~^ NOTE the lint level is defined here
8 use std::cell::{Ref, RefCell};
15 //~^ ERROR hidden lifetime parameters in types are deprecated
16 //~| NOTE expected named lifetime parameter
17 //~| HELP consider using the `'_` lifetime
20 fn bar(x: &Foo<'_>) {}
22 struct Wrapped<'a>(&'a str);
24 struct WrappedWithBow<'a> {
28 struct MatchedSet<'a, 'b> {
33 fn wrap_gift(gift: &str) -> Wrapped<'_> {
34 //~^ ERROR hidden lifetime parameters in types are deprecated
35 //~| NOTE expected named lifetime parameter
36 //~| HELP consider using the `'_` lifetime
40 fn wrap_gift_with_bow(gift: &str) -> WrappedWithBow<'_> {
41 //~^ ERROR hidden lifetime parameters in types are deprecated
42 //~| NOTE expected named lifetime parameter
43 //~| HELP consider using the `'_` lifetime
44 WrappedWithBow { gift }
47 fn inspect_matched_set(set: MatchedSet<'_, '_>) {
48 //~^ ERROR hidden lifetime parameters in types are deprecated
49 //~| NOTE expected 2 lifetime parameters
50 //~| HELP consider using the `'_` lifetime
51 println!("{} {}", set.one, set.another);
54 // Verify that the lint does not fire, because the added `'_` wouldn't be resolved correctly.
55 fn 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" }
63 macro_rules! autowrapper {
64 ($type_name:ident, $fn_name:ident, $lt:lifetime) => {
65 struct $type_name<$lt> {
69 fn $fn_name(gift: &str) -> $type_name<'_> {
70 //~^ ERROR hidden lifetime parameters in types are deprecated
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
81 autowrapper!(Autowrapped, autowrap_gift, 'a);
82 //~^ NOTE in this expansion of autowrapper!
83 //~| NOTE in this expansion of autowrapper!
85 // Verify that rustfix does not try to apply the fix twice.
86 autowrapper!(AutowrappedAgain, autowrap_gift_again, 'a);
87 //~^ NOTE in this expansion of autowrapper!
88 //~| NOTE in this expansion of autowrapper!
90 macro_rules! anytuple_ref_ty {
92 Ref<'_, ($($types),*)>
93 //~^ ERROR hidden lifetime parameters in types are deprecated
94 //~| NOTE expected named lifetime parameter
95 //~| HELP consider using the `'_` lifetime
99 #[allow(elided_lifetimes_in_paths)]
101 struct Thing<'a>(&'a i32);
104 fn foo(b: Bar<Thing>) {}
108 let honesty = RefCell::new((4, 'e'));
109 let loyalty: Ref<'_, (u32, char)> = honesty.borrow();
110 //~^ ERROR hidden lifetime parameters in types are deprecated
111 //~| NOTE expected named lifetime parameter
112 //~| HELP consider using the `'_` lifetime
113 let generosity = Ref::map(loyalty, |t| &t.0);
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!