2023-07-27 13:23:04 +00:00
|
|
|
//@aux-build:proc_macro_derive.rs
|
2022-06-24 10:00:06 +00:00
|
|
|
|
2020-08-05 01:37:29 +00:00
|
|
|
#![allow(
|
|
|
|
unused,
|
|
|
|
dead_code,
|
|
|
|
clippy::needless_lifetimes,
|
|
|
|
clippy::needless_pass_by_value,
|
|
|
|
clippy::needless_arbitrary_self_type
|
|
|
|
)]
|
2018-07-28 15:34:52 +00:00
|
|
|
#![warn(clippy::extra_unused_lifetimes)]
|
2015-12-06 21:36:22 +00:00
|
|
|
|
2022-06-24 10:00:06 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate proc_macro_derive;
|
|
|
|
|
2018-12-09 22:26:16 +00:00
|
|
|
fn empty() {}
|
2015-12-06 21:36:22 +00:00
|
|
|
|
2018-12-09 22:26:16 +00:00
|
|
|
fn used_lt<'a>(x: &'a u8) {}
|
2015-12-06 21:36:22 +00:00
|
|
|
|
2018-12-09 22:26:16 +00:00
|
|
|
fn unused_lt<'a>(x: u8) {}
|
2015-12-06 21:36:22 +00:00
|
|
|
|
2017-02-08 13:58:07 +00:00
|
|
|
fn unused_lt_transitive<'a, 'b: 'a>(x: &'b u8) {
|
2015-12-06 21:36:22 +00:00
|
|
|
// 'a is useless here since it's not directly bound
|
|
|
|
}
|
|
|
|
|
|
|
|
fn lt_return<'a, 'b: 'a>(x: &'b u8) -> &'a u8 {
|
|
|
|
panic!()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn lt_return_only<'a>() -> &'a u8 {
|
|
|
|
panic!()
|
|
|
|
}
|
|
|
|
|
2019-05-30 06:23:47 +00:00
|
|
|
fn unused_lt_blergh<'a>(x: Option<Box<dyn Send + 'a>>) {}
|
2015-12-06 21:36:22 +00:00
|
|
|
|
|
|
|
trait Foo<'a> {
|
|
|
|
fn x(&self, a: &'a u8);
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Foo<'a> for u8 {
|
2018-12-09 22:26:16 +00:00
|
|
|
fn x(&self, a: &'a u8) {}
|
2015-12-06 21:36:22 +00:00
|
|
|
}
|
2015-12-10 16:44:12 +00:00
|
|
|
|
2016-05-17 21:25:20 +00:00
|
|
|
struct Bar;
|
|
|
|
|
|
|
|
impl Bar {
|
2017-02-08 13:58:07 +00:00
|
|
|
fn x<'a>(&self) {}
|
2016-05-17 21:25:20 +00:00
|
|
|
}
|
|
|
|
|
2015-12-10 16:44:12 +00:00
|
|
|
// test for #489 (used lifetimes in bounds)
|
2018-12-09 22:26:16 +00:00
|
|
|
pub fn parse<'a, I: Iterator<Item = &'a str>>(_it: &mut I) {
|
2015-12-10 16:44:12 +00:00
|
|
|
unimplemented!()
|
|
|
|
}
|
2018-12-09 22:26:16 +00:00
|
|
|
pub fn parse2<'a, I>(_it: &mut I)
|
|
|
|
where
|
|
|
|
I: Iterator<Item = &'a str>,
|
|
|
|
{
|
2015-12-10 16:44:12 +00:00
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
2018-12-09 22:26:16 +00:00
|
|
|
struct X {
|
|
|
|
x: u32,
|
|
|
|
}
|
2016-01-14 18:27:24 +00:00
|
|
|
|
|
|
|
impl X {
|
|
|
|
fn self_ref_with_lifetime<'a>(&'a self) {}
|
|
|
|
fn explicit_self_with_lifetime<'a>(self: &'a Self) {}
|
|
|
|
}
|
|
|
|
|
2019-08-31 06:16:04 +00:00
|
|
|
// Methods implementing traits must have matching lifetimes
|
|
|
|
mod issue4291 {
|
2019-09-01 05:55:29 +00:00
|
|
|
trait BadTrait {
|
|
|
|
fn unused_lt<'a>(x: u8) {}
|
2019-08-31 06:16:04 +00:00
|
|
|
}
|
|
|
|
|
2019-09-01 05:55:29 +00:00
|
|
|
impl BadTrait for () {
|
|
|
|
fn unused_lt<'a>(_x: u8) {}
|
2019-08-31 06:16:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-23 00:05:18 +00:00
|
|
|
mod issue6437 {
|
|
|
|
pub struct Scalar;
|
|
|
|
|
|
|
|
impl<'a> std::ops::AddAssign<&Scalar> for &mut Scalar {
|
|
|
|
fn add_assign(&mut self, _rhs: &Scalar) {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'b> Scalar {
|
|
|
|
pub fn something<'c>() -> Self {
|
|
|
|
Self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-25 09:20:08 +00:00
|
|
|
// https://github.com/rust-lang/rust-clippy/pull/8737#pullrequestreview-951268213
|
|
|
|
mod first_case {
|
|
|
|
use serde::de::Visitor;
|
|
|
|
pub trait Expected {
|
|
|
|
fn fmt(&self, formatter: &mut std::fmt::Formatter);
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'de, T> Expected for T
|
|
|
|
where
|
|
|
|
T: Visitor<'de>,
|
|
|
|
{
|
|
|
|
fn fmt(&self, formatter: &mut std::fmt::Formatter) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// https://github.com/rust-lang/rust-clippy/pull/8737#pullrequestreview-951268213
|
|
|
|
mod second_case {
|
|
|
|
pub trait Source {
|
|
|
|
fn hey();
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, T: Source + ?Sized + 'a> Source for Box<T> {
|
|
|
|
fn hey() {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-24 10:00:06 +00:00
|
|
|
// Should not lint
|
|
|
|
#[derive(ExtraLifetimeDerive)]
|
|
|
|
struct Human<'a> {
|
|
|
|
pub bones: i32,
|
|
|
|
pub name: &'a str,
|
|
|
|
}
|
|
|
|
|
2018-12-09 22:26:16 +00:00
|
|
|
fn main() {}
|