|
| 1 | +#![deny(elided_lifetimes_in_paths)] |
| 2 | + |
| 3 | +// Most of the time, we focus on elided lifetimes in function |
| 4 | +// signatures, but they can also appear in other places! The original |
| 5 | +// version of this lint handled all these cases in one location, but |
| 6 | +// it's desired that the one lint actually be multiple. |
| 7 | + |
| 8 | +struct ContainsLifetime<'a>(&'a u8); |
| 9 | + |
| 10 | +impl<'a> ContainsLifetime<'a> { |
| 11 | + fn use_it() {} |
| 12 | +} |
| 13 | + |
| 14 | +struct ContainsLifetimeAndType<'a, T>(&'a T); |
| 15 | + |
| 16 | +impl<'a, T> ContainsLifetimeAndType<'a, T> { |
| 17 | + fn use_it() {} |
| 18 | +} |
| 19 | + |
| 20 | +fn use_via_turbofish<T>() {} |
| 21 | + |
| 22 | +trait UseViaTrait { |
| 23 | + fn use_it() {} |
| 24 | +} |
| 25 | + |
| 26 | +impl UseViaTrait for ContainsLifetime<'_> {} |
| 27 | + |
| 28 | +trait TraitWithLifetime<'a> { |
| 29 | + fn use_it() {} |
| 30 | +} |
| 31 | + |
| 32 | +impl<'a> TraitWithLifetime<'a> for u8 {} |
| 33 | + |
| 34 | +enum EnumWithType<T> { |
| 35 | + VariantStructLike { v: T }, |
| 36 | + VariantTupleLike(T), |
| 37 | + VariantUnit, |
| 38 | +} |
| 39 | + |
| 40 | +type TypeAliasWithLifetime<'a> = EnumWithType<&'a u8>; |
| 41 | + |
| 42 | +// ========== |
| 43 | + |
| 44 | +static USE_VIA_STATIC: ContainsLifetime = ContainsLifetime(&42); |
| 45 | +//~^ ERROR hidden lifetime parameters |
| 46 | + |
| 47 | +fn main() { |
| 48 | + use_via_turbofish::<ContainsLifetime>(); |
| 49 | + //~^ ERROR hidden lifetime parameters |
| 50 | + |
| 51 | + let _use_via_binding: ContainsLifetime; |
| 52 | + //~^ ERROR hidden lifetime parameters |
| 53 | + |
| 54 | + <ContainsLifetime as UseViaTrait>::use_it(); |
| 55 | + //~^ ERROR hidden lifetime parameters |
| 56 | + |
| 57 | + <ContainsLifetime>::use_it(); |
| 58 | + //~^ ERROR hidden lifetime parameters |
| 59 | + |
| 60 | + ContainsLifetime::use_it(); |
| 61 | + |
| 62 | + ContainsLifetimeAndType::<u8>::use_it(); |
| 63 | + |
| 64 | + <u8 as TraitWithLifetime>::use_it(); |
| 65 | +} |
| 66 | + |
| 67 | +impl TypeAliasWithLifetime<'_> { |
| 68 | + fn use_via_match(self) { |
| 69 | + match self { |
| 70 | + TypeAliasWithLifetime::VariantStructLike { .. } => (), |
| 71 | + TypeAliasWithLifetime::VariantTupleLike(_) => (), |
| 72 | + TypeAliasWithLifetime::VariantUnit => (), |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + fn use_via_create(v: u8) -> Self { |
| 77 | + match v { |
| 78 | + 0 => TypeAliasWithLifetime::VariantStructLike { v: &42 }, |
| 79 | + 1 => TypeAliasWithLifetime::VariantTupleLike(&42), |
| 80 | + _ => TypeAliasWithLifetime::VariantUnit, |
| 81 | + } |
| 82 | + } |
| 83 | +} |
0 commit comments