1 #![warn(rust_2018_idioms, single_use_lifetimes)]
2 #![warn(future_incompatible, nonstandard_style, rust_2018_compatibility, unused)]
3 #![warn(clippy::all, clippy::pedantic, clippy::nursery)]
4 #![allow(unknown_lints)] // for old compilers
5 #![warn(
6     absolute_paths_not_starting_with_crate,
7     anonymous_parameters,
8     box_pointers,
9     deprecated_in_future,
10     elided_lifetimes_in_paths,
11     explicit_outlives_requirements,
12     indirect_structural_match,
13     keyword_idents,
14     macro_use_extern_crate,
15     meta_variable_misuse,
16     missing_copy_implementations,
17     missing_crate_level_docs,
18     missing_debug_implementations,
19     missing_docs,
20     missing_doc_code_examples,
21     non_ascii_idents,
22     private_doc_tests,
23     single_use_lifetimes,
24     trivial_casts,
25     trivial_numeric_casts,
26     unaligned_references,
27     unreachable_pub,
28     unstable_features,
29     unused_extern_crates,
30     unused_import_braces,
31     unused_lifetimes,
32     unused_qualifications,
33     unused_results,
34     variant_size_differences
35 )]
36 // unused_crate_dependencies: unrelated
37 // unsafe_code: checked in forbid_unsafe module
38 // unsafe_block_in_unsafe_fn: unstable
39 
40 // Check interoperability with rustc and clippy lints.
41 
42 pub mod basic {
43     include!("include/basic.rs");
44 }
45 
46 pub mod forbid_unsafe {
47     #![forbid(unsafe_code)]
48 
49     include!("include/basic-safe-part.rs");
50 }
51 
52 pub mod clippy {
53     use pin_project::pin_project;
54 
55     #[rustversion::attr(before(1.37), allow(single_use_lifetimes))] // https://github.com/rust-lang/rust/issues/53738
56     #[pin_project(project_replace)]
57     #[derive(Debug)]
58     pub struct MutMutStruct<'a, T, U> {
59         #[pin]
60         pub pinned: &'a mut T,
61         pub unpinned: &'a mut U,
62     }
63 
64     #[rustversion::attr(before(1.37), allow(single_use_lifetimes))] // https://github.com/rust-lang/rust/issues/53738
65     #[pin_project(project_replace)]
66     #[derive(Debug)]
67     pub struct MutMutTupleStruct<'a, T, U>(#[pin] &'a mut T, &'a mut U);
68 
69     #[rustversion::attr(before(1.37), allow(single_use_lifetimes))] // https://github.com/rust-lang/rust/issues/53738
70     #[pin_project(project_replace)]
71     #[derive(Debug)]
72     pub enum MutMutEnum<'a, T, U> {
73         Struct {
74             #[pin]
75             pinned: &'a mut T,
76             unpinned: &'a mut U,
77         },
78         Tuple(#[pin] &'a mut T, &'a mut U),
79         Unit,
80     }
81 
82     #[pin_project(project_replace)]
83     #[derive(Debug)]
84     pub struct TypeRepetitionInBoundsStruct<T, U>
85     where
86         Self: Sized,
87     {
88         #[pin]
89         pub pinned: T,
90         pub unpinned: U,
91     }
92 
93     #[pin_project(project_replace)]
94     #[derive(Debug)]
95     pub struct TypeRepetitionInBoundsTupleStruct<T, U>(#[pin] T, U)
96     where
97         Self: Sized;
98 
99     #[pin_project(project_replace)]
100     #[derive(Debug)]
101     pub enum TypeRepetitionInBoundsEnum<T, U>
102     where
103         Self: Sized,
104     {
105         Struct {
106             #[pin]
107             pinned: T,
108             unpinned: U,
109         },
110         Tuple(#[pin] T, U),
111         Unit,
112     }
113 
114     #[pin_project(project_replace)]
115     #[derive(Debug)]
116     pub struct UsedUnderscoreBindingStruct<T, U> {
117         #[pin]
118         pub _pinned: T,
119         pub _unpinned: U,
120     }
121 
122     #[pin_project(project_replace)]
123     #[derive(Debug)]
124     pub enum UsedUnderscoreBindingEnum<T, U> {
125         Struct {
126             #[pin]
127             _pinned: T,
128             _unpinned: U,
129         },
130     }
131 }
132 
133 #[allow(box_pointers)]
134 #[rustversion::attr(not(nightly), ignore)]
135 #[test]
check_lint_list()136 fn check_lint_list() {
137     use std::{env, process::Command, str};
138 
139     (|| -> Result<(), Box<dyn std::error::Error>> {
140         let current = include_str!("lint.txt");
141         let rustc = env::var_os("RUSTC").unwrap_or_else(|| "rustc".into());
142         let output = Command::new(rustc).args(&["-W", "help"]).output()?;
143         let new = str::from_utf8(&output.stdout)?;
144         assert_eq!(current, new);
145         Ok(())
146     })()
147     .unwrap_or_else(|e| panic!("{}", e));
148 }
149