use proc_macro2::TokenStream;
use quote::quote;
use syn::Generics;
pub fn lifetime_lint_allows(generics: &Generics) -> TokenStream {
if generics.lifetimes().next().is_some() {
quote! {
#[allow(clippy::elidable_lifetime_names, clippy::needless_lifetimes)]
}
} else {
TokenStream::new()
}
}
#[cfg(test)]
mod tests {
use syn::parse_quote;
use super::*;
#[test]
fn test_no_lifetimes_returns_empty() {
let generics: Generics = parse_quote!();
let result = lifetime_lint_allows(&generics);
assert!(result.is_empty());
}
#[test]
fn test_type_params_only_returns_empty() {
let generics: Generics = parse_quote!(<T, U>);
let result = lifetime_lint_allows(&generics);
assert!(result.is_empty());
}
#[test]
fn test_with_lifetime_returns_allows() {
let generics: Generics = parse_quote!(<'a>);
let result = lifetime_lint_allows(&generics);
let output = result.to_string();
assert!(output.contains("allow"));
assert!(output.contains("elidable_lifetime_names"));
assert!(output.contains("needless_lifetimes"));
}
#[test]
fn test_mixed_params_with_lifetime_returns_allows() {
let generics: Generics = parse_quote!(<'a, T, 'b>);
let result = lifetime_lint_allows(&generics);
let output = result.to_string();
assert!(output.contains("allow"));
}
#[test]
fn test_const_generics_only_returns_empty() {
let generics: Generics = parse_quote!(<const N: usize>);
let result = lifetime_lint_allows(&generics);
assert!(result.is_empty());
}
}