]> git.lizzy.rs Git - rust.git/blob - tests/ui/single_char_lifetime_names.rs
Auto merge of #8359 - flip1995:rustup, r=flip1995
[rust.git] / tests / ui / single_char_lifetime_names.rs
1 #![warn(clippy::single_char_lifetime_names)]
2
3 // Lifetimes should only be linted when they're introduced
4 struct DiagnosticCtx<'a, 'b>
5 where
6     'a: 'b,
7 {
8     _source: &'a str,
9     _unit: &'b (),
10 }
11
12 // Only the lifetimes on the `impl`'s generics should be linted
13 impl<'a, 'b> DiagnosticCtx<'a, 'b> {
14     fn new(source: &'a str, unit: &'b ()) -> DiagnosticCtx<'a, 'b> {
15         Self {
16             _source: source,
17             _unit: unit,
18         }
19     }
20 }
21
22 // No lifetimes should be linted here
23 impl<'src, 'unit> DiagnosticCtx<'src, 'unit> {
24     fn new_pass(source: &'src str, unit: &'unit ()) -> DiagnosticCtx<'src, 'unit> {
25         Self {
26             _source: source,
27             _unit: unit,
28         }
29     }
30 }
31
32 // Only 'a should be linted here
33 fn split_once<'a>(base: &'a str, other: &'_ str) -> (&'a str, Option<&'a str>) {
34     base.split_once(other)
35         .map(|(left, right)| (left, Some(right)))
36         .unwrap_or((base, None))
37 }
38
39 fn main() {
40     let src = "loop {}";
41     let unit = ();
42     DiagnosticCtx::new(src, &unit);
43 }