Skip to content

Commit eecb648

Browse files
committed
Auto merge of #2824 - JohnTitor:style-check-fix, r=Amanieu
Don't check typedefs in impls in style checker Signed-off-by: Yuki Okushi <[email protected]>
2 parents 81c333f + ba9676c commit eecb648

File tree

1 file changed

+32
-43
lines changed

1 file changed

+32
-43
lines changed

ci/style.rs

Lines changed: 32 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
//!
1515
//! The current style is:
1616
//!
17-
//! * No trailing whitespace
18-
//! * No tabs
19-
//! * 100-character lines
2017
//! * Specific module layout:
2118
//! 1. use directives
2219
//! 2. typedefs
@@ -29,7 +26,6 @@
2926
//! Things not verified:
3027
//!
3128
//! * alignment
32-
//! * 4-space tabs
3329
//! * leading colons on paths
3430
3531
use std::env;
@@ -38,10 +34,12 @@ use std::io::prelude::*;
3834
use std::path::Path;
3935

4036
macro_rules! t {
41-
($e:expr) => (match $e {
42-
Ok(e) => e,
43-
Err(e) => panic!("{} failed with {}", stringify!($e), e),
44-
})
37+
($e:expr) => {
38+
match $e {
39+
Ok(e) => e,
40+
Err(e) => panic!("{} failed with {}", stringify!($e), e),
41+
}
42+
};
4543
}
4644

4745
fn main() {
@@ -62,18 +60,14 @@ fn walk(path: &Path, err: &mut Errors) {
6260
let path = entry.path();
6361
if t!(entry.file_type()).is_dir() {
6462
walk(&path, err);
65-
continue
63+
continue;
6664
}
6765

6866
let name = entry.file_name().into_string().unwrap();
6967
match &name[..] {
7068
n if !n.ends_with(".rs") => continue,
7169

72-
"dox.rs" |
73-
"lib.rs" |
74-
"ctypes.rs" |
75-
"libc.rs" |
76-
"macros.rs" => continue,
70+
"lib.rs" | "macros.rs" => continue,
7771

7872
_ => {}
7973
}
@@ -105,43 +99,32 @@ fn check_style(file: &str, path: &Path, err: &mut Errors) {
10599
let mut state = State::Start;
106100
let mut s_macros = 0;
107101
let mut f_macros = 0;
108-
let mut prev_blank = false;
102+
let mut in_impl = false;
109103

110104
for (i, line) in file.lines().enumerate() {
111-
if line == "" {
112-
if prev_blank {
113-
err.error(path, i, "double blank line");
114-
}
115-
prev_blank = true;
116-
} else {
117-
prev_blank = false;
118-
}
119-
if line != line.trim_end() {
120-
err.error(path, i, "trailing whitespace");
121-
}
122-
if line.contains("\t") {
123-
err.error(path, i, "tab character");
124-
}
125-
if line.len() > 100 && !(line.contains("https://") || line.contains("http://")) {
126-
err.error(path, i, "line longer than 100 chars");
127-
}
128-
if line.contains("#[cfg(") && line.contains(']') && !line.contains(" if ")
129-
&& !(line.contains("target_endian") ||
130-
line.contains("target_arch"))
105+
if line.contains("#[cfg(")
106+
&& line.contains(']')
107+
&& !line.contains(" if ")
108+
&& !(line.contains("target_endian") || line.contains("target_arch"))
131109
{
132110
if state != State::Structs {
133-
err.error(path, i, "use cfg_if! and submodules \
134-
instead of #[cfg]");
111+
err.error(path, i, "use cfg_if! and submodules instead of #[cfg]");
135112
}
136113
}
137114
if line.contains("#[derive(") && (line.contains("Copy") || line.contains("Clone")) {
138115
err.error(path, i, "impl ::Copy and ::Clone manually");
139116
}
117+
if line.contains("impl") {
118+
in_impl = true;
119+
}
120+
if in_impl && line.starts_with('}') {
121+
in_impl = false;
122+
}
140123

141124
let orig_line = line;
142125
let line = line.trim_start();
143126
let is_pub = line.starts_with("pub ");
144-
let line = if is_pub {&line[4..]} else {line};
127+
let line = if is_pub { &line[4..] } else { line };
145128

146129
let line_state = if line.starts_with("use ") {
147130
if line.contains("c_void") {
@@ -154,7 +137,7 @@ fn check_style(file: &str, path: &Path, err: &mut Errors) {
154137
}
155138
} else if line.starts_with("const ") {
156139
State::Constants
157-
} else if line.starts_with("type ") {
140+
} else if line.starts_with("type ") && !in_impl {
158141
State::Typedefs
159142
} else if line.starts_with("s! {") {
160143
s_macros += 1;
@@ -167,13 +150,19 @@ fn check_style(file: &str, path: &Path, err: &mut Errors) {
167150
} else if line.starts_with("mod ") {
168151
State::Modules
169152
} else {
170-
continue
153+
continue;
171154
};
172155

173156
if state as usize > line_state as usize {
174-
err.error(path, i, &format!("{} found after {} when \
175-
it belongs before",
176-
line_state.desc(), state.desc()));
157+
err.error(
158+
path,
159+
i,
160+
&format!(
161+
"{} found after {} when it belongs before",
162+
line_state.desc(),
163+
state.desc()
164+
),
165+
);
177166
}
178167

179168
if f_macros == 2 {

0 commit comments

Comments
 (0)