]> git.lizzy.rs Git - rust.git/blob - tests/ui/unused_lt.rs
Merge branch 'master' into rustfmt_tests
[rust.git] / tests / ui / unused_lt.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 #![allow(
11     unused,
12     dead_code,
13     clippy::needless_lifetimes,
14     clippy::needless_pass_by_value,
15     clippy::trivially_copy_pass_by_ref
16 )]
17 #![warn(clippy::extra_unused_lifetimes)]
18
19 fn empty() {}
20
21 fn used_lt<'a>(x: &'a u8) {}
22
23 fn unused_lt<'a>(x: u8) {}
24
25 fn unused_lt_transitive<'a, 'b: 'a>(x: &'b u8) {
26     // 'a is useless here since it's not directly bound
27 }
28
29 fn lt_return<'a, 'b: 'a>(x: &'b u8) -> &'a u8 {
30     panic!()
31 }
32
33 fn lt_return_only<'a>() -> &'a u8 {
34     panic!()
35 }
36
37 fn unused_lt_blergh<'a>(x: Option<Box<Send + 'a>>) {}
38
39 trait Foo<'a> {
40     fn x(&self, a: &'a u8);
41 }
42
43 impl<'a> Foo<'a> for u8 {
44     fn x(&self, a: &'a u8) {}
45 }
46
47 struct Bar;
48
49 impl Bar {
50     fn x<'a>(&self) {}
51 }
52
53 // test for #489 (used lifetimes in bounds)
54 pub fn parse<'a, I: Iterator<Item = &'a str>>(_it: &mut I) {
55     unimplemented!()
56 }
57 pub fn parse2<'a, I>(_it: &mut I)
58 where
59     I: Iterator<Item = &'a str>,
60 {
61     unimplemented!()
62 }
63
64 struct X {
65     x: u32,
66 }
67
68 impl X {
69     fn self_ref_with_lifetime<'a>(&'a self) {}
70     fn explicit_self_with_lifetime<'a>(self: &'a Self) {}
71 }
72
73 fn main() {}