-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathlint.rs
160 lines (144 loc) · 4.32 KB
/
lint.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#![warn(nonstandard_style, rust_2018_compatibility, rust_2018_idioms, unused)]
// Note: This does not guarantee compatibility with `forbid(future_incompatible)` in the future.
// If rustc adds a new lint, we may not be able to keep this.
#![forbid(future_incompatible)]
#![forbid(unsafe_code)]
#![allow(unknown_lints)] // for old compilers
#![warn(
absolute_paths_not_starting_with_crate,
anonymous_parameters,
box_pointers,
deprecated_in_future,
elided_lifetimes_in_paths,
explicit_outlives_requirements,
keyword_idents,
macro_use_extern_crate,
meta_variable_misuse,
missing_copy_implementations,
missing_crate_level_docs,
missing_debug_implementations,
missing_docs,
missing_doc_code_examples,
non_ascii_idents,
pointer_structural_match,
private_doc_tests,
single_use_lifetimes,
trivial_casts,
trivial_numeric_casts,
unaligned_references,
unreachable_pub,
unused_extern_crates,
unused_import_braces,
unused_lifetimes,
unused_qualifications,
unused_results,
variant_size_differences
)]
// unused_crate_dependencies: unrelated
// unsafe_code: forbidden
// unsafe_block_in_unsafe_fn: unstable
// unstable_features: deprecated: https://doc.rust-lang.org/beta/rustc/lints/listing/allowed-by-default.html#unstable-features
#![warn(clippy::all, clippy::pedantic, clippy::nursery)]
#![warn(clippy::restriction)]
#![allow(clippy::blanket_clippy_restriction_lints)] // this is a test, so enable all restriction lints intentionally.
// Check interoperability with rustc and clippy lints.
pub mod basic {
include!("include/basic.rs");
}
pub mod box_pointers {
use pin_project_lite::pin_project;
pin_project! {
#[derive(Debug)]
pub struct Struct {
#[pin]
pub p: Box<isize>,
pub u: Box<isize>,
}
}
}
pub mod explicit_outlives_requirements {
use pin_project_lite::pin_project;
pin_project! {
#[derive(Debug)]
pub struct Struct<'a, T, U>
where
T: ?Sized,
U: ?Sized,
{
#[pin]
pub pinned: &'a mut T,
pub unpinned: &'a mut U,
}
}
}
pub mod clippy_mut_mut {
use pin_project_lite::pin_project;
pin_project! {
#[derive(Debug)]
pub struct Struct<'a, T, U> {
#[pin]
pub pinned: &'a mut T,
pub unpinned: &'a mut U,
}
}
}
pub mod clippy_type_repetition_in_bounds {
use pin_project_lite::pin_project;
pin_project! {
#[derive(Debug)]
pub struct Struct<T, U>
where
Struct<T, U>: Sized,
{
#[pin]
pub pinned: T,
pub unpinned: U,
}
}
}
pub mod clippy_used_underscore_binding {
use pin_project_lite::pin_project;
pin_project! {
#[derive(Debug)]
pub struct Struct<T, U> {
#[pin]
pub _pinned: T,
pub _unpinned: U,
}
}
}
#[allow(box_pointers)]
#[allow(clippy::restriction)]
#[rustversion::attr(not(nightly), ignore)]
#[test]
fn check_lint_list() {
use std::{env, fs, path::PathBuf, process::Command, str};
type Result<T, E = Box<dyn std::error::Error>> = std::result::Result<T, E>;
fn assert_eq(expected_path: &str, actual: &str) -> Result<()> {
let manifest_dir = env::var_os("CARGO_MANIFEST_DIR")
.map(PathBuf::from)
.expect("CARGO_MANIFEST_DIR not set");
let expected_path = manifest_dir.join(expected_path);
let expected = fs::read_to_string(&expected_path)?;
if expected != actual {
if env::var_os("CI").map_or(false, |v| v == "true") {
panic!(
"assertion failed:\n\nEXPECTED:\n{0}\n{1}\n{0}\n\nACTUAL:\n{0}\n{2}\n{0}\n",
"-".repeat(60),
expected,
actual,
);
} else {
fs::write(&expected_path, actual)?;
}
}
Ok(())
}
(|| -> Result<()> {
let rustc = env::var_os("RUSTC").unwrap_or_else(|| "rustc".into());
let output = Command::new(rustc).args(&["-W", "help"]).output()?;
let new = str::from_utf8(&output.stdout)?;
assert_eq("tests/lint.txt", new)
})()
.unwrap_or_else(|e| panic!("{}", e));
}