]> git.lizzy.rs Git - rust.git/blob - tests/ui/single-use-lifetime/one-use-in-fn-argument.rs
Rollup merge of #106625 - Swatinem:ref/cov6, r=nagisa
[rust.git] / tests / ui / single-use-lifetime / one-use-in-fn-argument.rs
1 #![deny(single_use_lifetimes)]
2 #![allow(dead_code)]
3 #![allow(unused_variables)]
4
5 // Test that we DO warn when lifetime name is used only
6 // once in a fn argument.
7
8 fn a<'a>(x: &'a u32) { //~ ERROR `'a` only used once
9     //~^ HELP elide the single-use lifetime
10 }
11
12 struct Single<'a> { x: &'a u32 }
13 struct Double<'a, 'b> { f: &'a &'b u32 }
14
15 fn center<'m>(_: Single<'m>) {} //~ ERROR `'m` only used once
16 //~^ HELP elide the single-use lifetime
17 fn left<'x, 'y>(foo: Double<'x, 'y>) -> &'x u32 { foo.f } //~ ERROR `'y` only used once
18 //~^ HELP elide the single-use lifetime
19 fn right<'x, 'y>(foo: Double<'x, 'y>) -> &'y u32 { foo.f } //~ ERROR `'x` only used once
20 //~^ HELP elide the single-use lifetime
21
22 pub trait Tfv<'a> {}
23
24 // Do NOT lint in an HRTB.
25 pub fn g<T: for<'a> Tfv<'a>>() {}
26
27 // Do NOT lint for trait bounds.
28 pub fn h<'a, S>(_: S)
29 where
30     S: Tfv<'a>,
31 {}
32
33 fn main() {}