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