]> git.lizzy.rs Git - rust.git/blob - src/test/ui/in-band-lifetimes/elided-lifetimes.rs
Rollup merge of #53407 - pnkfelix:partial-53351-make-more-ported-compile-fail-tests...
[rust.git] / src / test / ui / in-band-lifetimes / elided-lifetimes.rs
1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // run-rustfix
12 // compile-flags: --edition 2018
13
14 #![allow(unused)]
15 #![deny(elided_lifetimes_in_paths)]
16 //~^ NOTE lint level defined here
17
18 use std::cell::{RefCell, Ref};
19
20
21 struct Foo<'a> { x: &'a u32 }
22
23 fn foo(x: &Foo) {
24     //~^ ERROR hidden lifetime parameters in types are deprecated
25     //~| HELP indicate the anonymous lifetime
26 }
27
28 fn bar(x: &Foo<'_>) {}
29
30
31 struct Wrapped<'a>(&'a str);
32
33 struct WrappedWithBow<'a> {
34     gift: &'a str
35 }
36
37 struct MatchedSet<'a, 'b> {
38     one: &'a str,
39     another: &'b str,
40 }
41
42 fn wrap_gift(gift: &str) -> Wrapped {
43     //~^ ERROR hidden lifetime parameters in types are deprecated
44     //~| HELP indicate the anonymous lifetime
45     Wrapped(gift)
46 }
47
48 fn wrap_gift_with_bow(gift: &str) -> WrappedWithBow {
49     //~^ ERROR hidden lifetime parameters in types are deprecated
50     //~| HELP indicate the anonymous lifetime
51     WrappedWithBow { gift }
52 }
53
54 fn inspect_matched_set(set: MatchedSet) {
55     //~^ ERROR hidden lifetime parameters in types are deprecated
56     //~| HELP indicate the anonymous lifetime
57     println!("{} {}", set.one, set.another);
58 }
59
60 macro_rules! autowrapper {
61     ($type_name:ident, $fn_name:ident, $lt:lifetime) => {
62         struct $type_name<$lt> {
63             gift: &$lt str
64         }
65
66         fn $fn_name(gift: &str) -> $type_name {
67             //~^ ERROR hidden lifetime parameters in types are deprecated
68             //~| HELP indicate the anonymous lifetime
69             $type_name { gift }
70         }
71     }
72 }
73
74 autowrapper!(Autowrapped, autowrap_gift, 'a);
75 //~^ NOTE in this expansion of autowrapper!
76 //~| NOTE in this expansion of autowrapper!
77
78 macro_rules! anytuple_ref_ty {
79     ($($types:ty),*) => {
80         Ref<($($types),*)>
81         //~^ ERROR hidden lifetime parameters in types are deprecated
82         //~| HELP indicate the anonymous lifetime
83     }
84 }
85
86 fn main() {
87     let honesty = RefCell::new((4, 'e'));
88     let loyalty: Ref<(u32, char)> = honesty.borrow();
89     //~^ ERROR hidden lifetime parameters in types are deprecated
90     //~| HELP indicate the anonymous lifetime
91     let generosity = Ref::map(loyalty, |t| &t.0);
92
93     let laughter = RefCell::new((true, "magic"));
94     let yellow: anytuple_ref_ty!(bool, &str) = laughter.borrow();
95     //~^ NOTE in this expansion of anytuple_ref_ty!
96     //~| NOTE in this expansion of anytuple_ref_ty!
97 }