1 // Check interoperability with rustc and clippy lints.
2 
3 #![forbid(unsafe_code)]
4 // for old compilers
5 #![allow(unknown_lints)]
6 #![warn(nonstandard_style, rust_2018_idioms, unused)]
7 // Note: This does not guarantee compatibility with forbidding these lints in the future.
8 // If rustc adds a new lint, we may not be able to keep this.
9 #![forbid(future_incompatible, rust_2018_compatibility, rust_2021_compatibility)]
10 // lints forbidden as a part of future_incompatible, rust_2018_compatibility, and rust_2021_compatibility are not included in the list below.
11 // elided_lifetimes_in_paths, explicit_outlives_requirements, unused_extern_crates:  as a part of rust_2018_idioms
12 // unsafe_op_in_unsafe_fn: requires Rust 1.52. and, we don't generate unsafe fn.
13 // non_exhaustive_omitted_patterns, multiple_supertrait_upcastable: unstable
14 // unstable_features: no way to generate #![feature(..)] by macros, expect for unstable inner attribute. and this lint is deprecated: https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#unstable-features
15 // unused_crate_dependencies, must_not_suspend: unrelated
16 // unsafe_code: checked in forbid_unsafe module
17 #![warn(
18     box_pointers,
19     deprecated_in_future,
20     fuzzy_provenance_casts,
21     invalid_reference_casting,
22     let_underscore_drop,
23     lossy_provenance_casts,
24     macro_use_extern_crate,
25     meta_variable_misuse,
26     missing_abi,
27     missing_copy_implementations,
28     missing_debug_implementations,
29     missing_docs,
30     non_ascii_idents,
31     noop_method_call,
32     private_bounds,
33     private_interfaces,
34     single_use_lifetimes,
35     trivial_casts,
36     trivial_numeric_casts,
37     unnameable_types,
38     unreachable_pub,
39     unused_import_braces,
40     unused_lifetimes,
41     unused_qualifications,
42     unused_results,
43     unused_tuple_struct_fields,
44     variant_size_differences
45 )]
46 #![warn(clippy::all, clippy::pedantic, clippy::nursery, clippy::restriction)]
47 #![allow(clippy::blanket_clippy_restriction_lints)] // this is a test, so enable all restriction lints intentionally.
48 #![allow(
49     clippy::exhaustive_enums,
50     clippy::exhaustive_structs,
51     clippy::min_ident_chars,
52     clippy::single_char_lifetime_names
53 )] // TODO
54 
55 pub mod basic {
56     include!("include/basic.rs");
57 }
58 
59 pub mod box_pointers {
60     use pin_project_lite::pin_project;
61 
62     pin_project! {
63         #[derive(Debug)]
64         pub struct Struct {
65             #[pin]
66             pub p: Box<isize>,
67             pub u: Box<isize>,
68         }
69     }
70 
71     pin_project! {
72         #[project = EnumProj]
73         #[project_ref = EnumProjRef]
74         #[project(!Unpin)]
75         #[derive(Debug)]
76         pub enum Enum {
77             Struct {
78                 #[pin]
79                 p: Box<isize>,
80                 u: Box<isize>,
81             },
82             Unit,
83         }
84     }
85 }
86 
87 pub mod explicit_outlives_requirements {
88     use pin_project_lite::pin_project;
89 
90     pin_project! {
91         #[derive(Debug)]
92         pub struct Struct<'a, T, U>
93         where
94             T: ?Sized,
95             U: ?Sized,
96         {
97             #[pin]
98             pub pinned: &'a mut T,
99             pub unpinned: &'a mut U,
100         }
101     }
102 
103     pin_project! {
104         #[project = EnumProj]
105         #[project_ref = EnumProjRef]
106         #[project(!Unpin)]
107         #[derive(Debug)]
108         pub enum Enum<'a, T, U>
109         where
110             T: ?Sized,
111             U: ?Sized,
112         {
113             Struct {
114                 #[pin]
115                 pinned: &'a mut T,
116                 unpinned: &'a mut U,
117             },
118             Unit,
119         }
120     }
121 }
122 
123 pub mod variant_size_differences {
124     use pin_project_lite::pin_project;
125 
126     pin_project! {
127         #[project = EnumProj]
128         #[project_ref = EnumProjRef]
129         #[project(!Unpin)]
130         #[allow(missing_debug_implementations, missing_copy_implementations)] // https://github.com/rust-lang/rust/pull/74060
131         #[allow(variant_size_differences)] // for the type itself
132         #[allow(clippy::large_enum_variant)] // for the type itself
133         pub enum Enum {
134             V1 { f: u8 },
135             V2 { f: [u8; 1024] },
136         }
137     }
138 }
139 
140 pub mod clippy_mut_mut {
141     use pin_project_lite::pin_project;
142 
143     pin_project! {
144         #[derive(Debug)]
145         pub struct Struct<'a, T, U> {
146             #[pin]
147             pub pinned: &'a mut T,
148             pub unpinned: &'a mut U,
149         }
150     }
151 
152     pin_project! {
153         #[project = EnumProj]
154         #[project_ref = EnumProjRef]
155         #[project(!Unpin)]
156         #[derive(Debug)]
157         pub enum Enum<'a, T, U> {
158             Struct {
159                 #[pin]
160                 pinned: &'a mut T,
161                 unpinned: &'a mut U,
162             },
163             Unit,
164         }
165     }
166 }
167 
168 #[allow(unreachable_pub)]
169 mod clippy_redundant_pub_crate {
170     use pin_project_lite::pin_project;
171 
172     pin_project! {
173         #[derive(Debug)]
174         pub struct Struct<T, U> {
175             #[pin]
176             pub pinned: T,
177             pub unpinned: U,
178         }
179     }
180 
181     pin_project! {
182         #[project = EnumProj]
183         #[project_ref = EnumProjRef]
184         #[project(!Unpin)]
185         #[derive(Debug)]
186         pub enum Enum<T, U> {
187             Struct {
188                 #[pin]
189                 pinned: T,
190                 unpinned: U,
191             },
192             Unit,
193         }
194     }
195 }
196 
197 #[allow(clippy::use_self)]
198 pub mod clippy_type_repetition_in_bounds {
199     use pin_project_lite::pin_project;
200 
201     pin_project! {
202         #[derive(Debug)]
203         pub struct Struct<T, U>
204         where
205             Struct<T, U>: Sized,
206         {
207             #[pin]
208             pub pinned: T,
209             pub unpinned: U,
210         }
211     }
212 
213     pin_project! {
214         #[project = EnumProj]
215         #[project_ref = EnumProjRef]
216         #[project(!Unpin)]
217         #[derive(Debug)]
218         pub enum Enum<T, U>
219         where
220             Enum<T, U>: Sized,
221         {
222             Struct {
223                 #[pin]
224                 pinned: T,
225                 unpinned: U,
226             },
227             Unit,
228         }
229     }
230 }
231 
232 #[allow(missing_debug_implementations)]
233 pub mod clippy_used_underscore_binding {
234     use pin_project_lite::pin_project;
235 
236     pin_project! {
237         pub struct Struct<T, U> {
238             #[pin]
239             pub _pinned: T,
240             pub _unpinned: U,
241         }
242     }
243 
244     pin_project! {
245         #[project = EnumProj]
246         #[project_ref = EnumProjRef]
247         #[project(!Unpin)]
248         pub enum Enum<T, U> {
249             Struct {
250                 #[pin]
251                 _pinned: T,
252                 _unpinned: U,
253             },
254         }
255     }
256 }
257 
258 pub mod clippy_ref_option_ref {
259     use pin_project_lite::pin_project;
260 
261     pin_project! {
262         pub struct Struct<'a> {
263             #[pin]
264             pub _pinned: Option<&'a ()>,
265             pub _unpinned: Option<&'a ()>,
266         }
267     }
268 
269     pin_project! {
270         #[project = EnumProj]
271         #[project_ref = EnumProjRef]
272         #[project(!Unpin)]
273         pub enum Enum<'a> {
274             Struct {
275                 #[pin]
276                 _pinned: Option<&'a ()>,
277                 _unpinned: Option<&'a ()>,
278             },
279         }
280     }
281 }
282