|
| 1 | +#![warn(clippy::use_self)] |
| 2 | +#![allow(clippy::type_complexity)] |
| 3 | + |
| 4 | +fn main() {} |
| 5 | + |
| 6 | +struct Basic { |
| 7 | + flag: Option<Box<Basic>>, |
| 8 | + //~^ use_self |
| 9 | +} |
| 10 | + |
| 11 | +struct BasicSelf { |
| 12 | + okay: Option<Box<Self>>, |
| 13 | +} |
| 14 | + |
| 15 | +struct Generic<'q, T: From<u8>> { |
| 16 | + t: &'q T, |
| 17 | + flag: Option<Box<Generic<'q, T>>>, |
| 18 | + //~^ use_self |
| 19 | +} |
| 20 | + |
| 21 | +struct GenericSelf<'q, T: From<u8>> { |
| 22 | + t: &'q T, |
| 23 | + okay: Option<Box<Self>>, |
| 24 | +} |
| 25 | + |
| 26 | +struct MixedLifetimes<'q, T: From<u8> + 'static> { |
| 27 | + t: &'q T, |
| 28 | + okay: Option<Box<MixedLifetimes<'static, T>>>, |
| 29 | +} |
| 30 | + |
| 31 | +struct ConcreteType<'q, T: From<u8>> { |
| 32 | + t: &'q T, |
| 33 | + okay: Option<Box<ConcreteType<'q, u64>>>, |
| 34 | +} |
| 35 | + |
| 36 | +struct ConcreteAndGeneric<'q, T: From<u8>> { |
| 37 | + t: &'q T, |
| 38 | + flag: Option<Box<ConcreteAndGeneric<'q, T>>>, |
| 39 | + //~^ use_self |
| 40 | + okay: Option<Box<ConcreteAndGeneric<'q, u64>>>, |
| 41 | +} |
| 42 | + |
| 43 | +struct ConcreteAndGenericSelf<'q, T: From<u8>> { |
| 44 | + t: &'q T, |
| 45 | + okay_1: Option<Box<Self>>, |
| 46 | + okay_2: Option<Box<ConcreteAndGeneric<'q, u64>>>, |
| 47 | +} |
| 48 | + |
| 49 | +macro_rules! recursive_struct { |
| 50 | + ($name:ident) => { |
| 51 | + struct $name { |
| 52 | + okay: Option<Box<$name>>, |
| 53 | + } |
| 54 | + }; |
| 55 | +} |
| 56 | + |
| 57 | +recursive_struct!(X); |
| 58 | +recursive_struct!(Y); |
| 59 | +recursive_struct!(Z); |
| 60 | + |
| 61 | +struct Tree { |
| 62 | + left: Option<Box<Tree>>, |
| 63 | + //~^ use_self |
| 64 | + right: Option<Box<Tree>>, |
| 65 | + //~^ use_self |
| 66 | +} |
| 67 | + |
| 68 | +struct TreeSelf { |
| 69 | + left: Option<Box<Self>>, |
| 70 | + right: Option<Box<Self>>, |
| 71 | +} |
| 72 | + |
| 73 | +struct TreeMixed { |
| 74 | + left: Option<Box<Self>>, |
| 75 | + right: Option<Box<TreeMixed>>, |
| 76 | + //~^ use_self |
| 77 | +} |
| 78 | + |
| 79 | +struct Nested { |
| 80 | + flag: Option<Box<Option<Box<Nested>>>>, |
| 81 | + //~^ use_self |
| 82 | +} |
| 83 | + |
| 84 | +struct NestedSelf { |
| 85 | + okay: Option<Box<Option<Box<Self>>>>, |
| 86 | +} |
| 87 | + |
| 88 | +struct Tuple(Option<Box<Tuple>>); |
| 89 | +//~^ use_self |
| 90 | + |
| 91 | +struct TupleSelf(Option<Box<Self>>); |
| 92 | + |
| 93 | +use std::cell::RefCell; |
| 94 | +use std::rc::{Rc, Weak}; |
| 95 | + |
| 96 | +struct Containers { |
| 97 | + flag: Vec<Option<Rc<RefCell<Weak<Vec<Box<Containers>>>>>>>, |
| 98 | + //~^ use_self |
| 99 | +} |
| 100 | + |
| 101 | +struct ContainersSelf { |
| 102 | + okay: Vec<Option<Rc<RefCell<Weak<Vec<Box<Self>>>>>>>, |
| 103 | +} |
| 104 | + |
| 105 | +type Wrappers<T> = Vec<Option<Rc<RefCell<Weak<Vec<Box<T>>>>>>>; |
| 106 | + |
| 107 | +struct Alias { |
| 108 | + flag: Wrappers<Alias>, |
| 109 | + //~^ use_self |
| 110 | +} |
| 111 | + |
| 112 | +struct AliasSelf { |
| 113 | + okay: Wrappers<Self>, |
| 114 | +} |
| 115 | + |
| 116 | +struct Array<const N: usize> { |
| 117 | + flag: [Option<Box<Array<N>>>; N], |
| 118 | + //~^ use_self |
| 119 | +} |
| 120 | + |
| 121 | +struct ArraySelf<const N: usize> { |
| 122 | + okay: [Option<Box<Self>>; N], |
| 123 | +} |
| 124 | + |
| 125 | +enum Enum { |
| 126 | + Nil, |
| 127 | + Cons(Box<Enum>), |
| 128 | + //~^ use_self |
| 129 | +} |
| 130 | + |
| 131 | +enum EnumSelf { |
| 132 | + Nil, |
| 133 | + Cons(Box<Self>), |
| 134 | +} |
0 commit comments