2022-01-09 14:27:36 +00:00
|
|
|
#![warn(clippy::single_char_lifetime_names)]
|
2022-03-17 23:53:28 +00:00
|
|
|
#![allow(clippy::let_unit_value)]
|
2022-01-09 14:27:36 +00:00
|
|
|
|
|
|
|
// Lifetimes should only be linted when they're introduced
|
|
|
|
struct DiagnosticCtx<'a, 'b>
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: single-character lifetime names are likely uninformative
|
|
|
|
//~| ERROR: single-character lifetime names are likely uninformative
|
2022-01-09 14:27:36 +00:00
|
|
|
where
|
|
|
|
'a: 'b,
|
|
|
|
{
|
|
|
|
_source: &'a str,
|
|
|
|
_unit: &'b (),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only the lifetimes on the `impl`'s generics should be linted
|
|
|
|
impl<'a, 'b> DiagnosticCtx<'a, 'b> {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: single-character lifetime names are likely uninformative
|
|
|
|
//~| ERROR: single-character lifetime names are likely uninformative
|
2022-01-09 14:27:36 +00:00
|
|
|
fn new(source: &'a str, unit: &'b ()) -> DiagnosticCtx<'a, 'b> {
|
|
|
|
Self {
|
|
|
|
_source: source,
|
|
|
|
_unit: unit,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No lifetimes should be linted here
|
|
|
|
impl<'src, 'unit> DiagnosticCtx<'src, 'unit> {
|
|
|
|
fn new_pass(source: &'src str, unit: &'unit ()) -> DiagnosticCtx<'src, 'unit> {
|
|
|
|
Self {
|
|
|
|
_source: source,
|
|
|
|
_unit: unit,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only 'a should be linted here
|
|
|
|
fn split_once<'a>(base: &'a str, other: &'_ str) -> (&'a str, Option<&'a str>) {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: single-character lifetime names are likely uninformative
|
2022-01-09 14:27:36 +00:00
|
|
|
base.split_once(other)
|
|
|
|
.map(|(left, right)| (left, Some(right)))
|
|
|
|
.unwrap_or((base, None))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let src = "loop {}";
|
|
|
|
let unit = ();
|
|
|
|
DiagnosticCtx::new(src, &unit);
|
|
|
|
}
|