Skip to content

Commit bfaf48b

Browse files
committed
Update clippy
1 parent ab6606b commit bfaf48b

File tree

109 files changed

+2616
-1421
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+2616
-1421
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,7 @@ Released 2018-09-13
11471147
[`float_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_arithmetic
11481148
[`float_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp
11491149
[`float_cmp_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp_const
1150+
[`fn_params_excessive_bools`]: https://rust-lang.github.io/rust-clippy/master/index.html#fn_params_excessive_bools
11501151
[`fn_to_numeric_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#fn_to_numeric_cast
11511152
[`fn_to_numeric_cast_with_truncation`]: https://rust-lang.github.io/rust-clippy/master/index.html#fn_to_numeric_cast_with_truncation
11521153
[`for_kv_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#for_kv_map
@@ -1217,6 +1218,7 @@ Released 2018-09-13
12171218
[`match_overlapping_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_overlapping_arm
12181219
[`match_ref_pats`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_ref_pats
12191220
[`match_same_arms`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
1221+
[`match_single_binding`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_single_binding
12201222
[`match_wild_err_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_wild_err_arm
12211223
[`maybe_infinite_iter`]: https://rust-lang.github.io/rust-clippy/master/index.html#maybe_infinite_iter
12221224
[`mem_discriminant_non_enum`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_discriminant_non_enum
@@ -1274,6 +1276,7 @@ Released 2018-09-13
12741276
[`op_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#op_ref
12751277
[`option_and_then_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_and_then_some
12761278
[`option_as_ref_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_as_ref_deref
1279+
[`option_env_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_env_unwrap
12771280
[`option_expect_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_expect_used
12781281
[`option_map_or_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_or_none
12791282
[`option_map_unit_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_unit_fn
@@ -1341,6 +1344,7 @@ Released 2018-09-13
13411344
[`string_extend_chars`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_extend_chars
13421345
[`string_lit_as_bytes`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_lit_as_bytes
13431346
[`string_to_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_to_string
1347+
[`struct_excessive_bools`]: https://rust-lang.github.io/rust-clippy/master/index.html#struct_excessive_bools
13441348
[`suspicious_arithmetic_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_arithmetic_impl
13451349
[`suspicious_assignment_formatting`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_assignment_formatting
13461350
[`suspicious_else_formatting`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_else_formatting

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ It's worth noting that the majority of `clippy_lints/src/lib.rs` is autogenerate
110110
```rust
111111
// ./clippy_lints/src/else_if_without_else.rs
112112

113-
use rustc::lint::{EarlyLintPass, LintArray, LintPass};
113+
use rustc_lint::{EarlyLintPass, EarlyContext};
114114

115115
// ...
116116

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
88

9-
[There are 351 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
9+
[There are 355 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
1010

1111
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
1212

clippy_dev/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ authors = ["Philipp Hansch <dev@phansch.net>"]
55
edition = "2018"
66

77
[dependencies]
8+
bytecount = "0.6"
89
clap = "2.33"
910
itertools = "0.8"
1011
regex = "1"

clippy_dev/src/lib.rs

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use regex::Regex;
66
use std::collections::HashMap;
77
use std::ffi::OsStr;
88
use std::fs;
9-
use std::io::prelude::*;
109
use std::path::{Path, PathBuf};
1110
use walkdir::WalkDir;
1211

@@ -31,9 +30,10 @@ lazy_static! {
3130
)
3231
.unwrap();
3332
static ref NL_ESCAPE_RE: Regex = Regex::new(r#"\\\n\s*"#).unwrap();
34-
pub static ref DOCS_LINK: String = "https://rust-lang.github.io/rust-clippy/master/index.html".to_string();
3533
}
3634

35+
pub static DOCS_LINK: &str = "https://rust-lang.github.io/rust-clippy/master/index.html";
36+
3737
/// Lint data parsed from the Clippy source code.
3838
#[derive(Clone, PartialEq, Debug)]
3939
pub struct Lint {
@@ -121,7 +121,7 @@ pub fn gen_changelog_lint_list(lints: Vec<Lint>) -> Vec<String> {
121121
if l.is_internal() {
122122
None
123123
} else {
124-
Some(format!("[`{}`]: {}#{}", l.name, DOCS_LINK.clone(), l.name))
124+
Some(format!("[`{}`]: {}#{}", l.name, DOCS_LINK, l.name))
125125
}
126126
})
127127
.collect()
@@ -172,9 +172,7 @@ pub fn gather_all() -> impl Iterator<Item = Lint> {
172172
}
173173

174174
fn gather_from_file(dir_entry: &walkdir::DirEntry) -> impl Iterator<Item = Lint> {
175-
let mut file = fs::File::open(dir_entry.path()).unwrap();
176-
let mut content = String::new();
177-
file.read_to_string(&mut content).unwrap();
175+
let content = fs::read_to_string(dir_entry.path()).unwrap();
178176
let mut filename = dir_entry.path().file_stem().unwrap().to_str().unwrap();
179177
// If the lints are stored in mod.rs, we get the module name from
180178
// the containing directory:
@@ -209,7 +207,7 @@ fn lint_files() -> impl Iterator<Item = walkdir::DirEntry> {
209207
let path = clippy_project_root().join("clippy_lints/src");
210208
WalkDir::new(path)
211209
.into_iter()
212-
.filter_map(std::result::Result::ok)
210+
.filter_map(Result::ok)
213211
.filter(|f| f.path().extension() == Some(OsStr::new("rs")))
214212
}
215213

@@ -225,7 +223,6 @@ pub struct FileChange {
225223
/// `path` is the relative path to the file on which you want to perform the replacement.
226224
///
227225
/// See `replace_region_in_text` for documentation of the other options.
228-
#[allow(clippy::expect_fun_call)]
229226
pub fn replace_region_in_file<F>(
230227
path: &Path,
231228
start: &str,
@@ -235,22 +232,15 @@ pub fn replace_region_in_file<F>(
235232
replacements: F,
236233
) -> FileChange
237234
where
238-
F: Fn() -> Vec<String>,
235+
F: FnOnce() -> Vec<String>,
239236
{
240-
let path = clippy_project_root().join(path);
241-
let mut f = fs::File::open(&path).expect(&format!("File not found: {}", path.to_string_lossy()));
242-
let mut contents = String::new();
243-
f.read_to_string(&mut contents)
244-
.expect("Something went wrong reading the file");
237+
let contents = fs::read_to_string(path).unwrap_or_else(|e| panic!("Cannot read from {}: {}", path.display(), e));
245238
let file_change = replace_region_in_text(&contents, start, end, replace_start, replacements);
246239

247240
if write_back {
248-
let mut f = fs::File::create(&path).expect(&format!("File not found: {}", path.to_string_lossy()));
249-
f.write_all(file_change.new_lines.as_bytes())
250-
.expect("Unable to write file");
251-
// Ensure we write the changes with a trailing newline so that
252-
// the file has the proper line endings.
253-
f.write_all(b"\n").expect("Unable to write file");
241+
if let Err(e) = fs::write(path, file_change.new_lines.as_bytes()) {
242+
panic!("Cannot write to {}: {}", path.display(), e);
243+
}
254244
}
255245
file_change
256246
}
@@ -273,31 +263,32 @@ where
273263
///
274264
/// ```
275265
/// let the_text = "replace_start\nsome text\nthat will be replaced\nreplace_end";
276-
/// let result = clippy_dev::replace_region_in_text(the_text, r#"replace_start"#, r#"replace_end"#, false, || {
277-
/// vec!["a different".to_string(), "text".to_string()]
278-
/// })
279-
/// .new_lines;
266+
/// let result =
267+
/// clippy_dev::replace_region_in_text(the_text, "replace_start", "replace_end", false, || {
268+
/// vec!["a different".to_string(), "text".to_string()]
269+
/// })
270+
/// .new_lines;
280271
/// assert_eq!("replace_start\na different\ntext\nreplace_end", result);
281272
/// ```
282273
pub fn replace_region_in_text<F>(text: &str, start: &str, end: &str, replace_start: bool, replacements: F) -> FileChange
283274
where
284-
F: Fn() -> Vec<String>,
275+
F: FnOnce() -> Vec<String>,
285276
{
286-
let lines = text.lines();
277+
let replace_it = replacements();
287278
let mut in_old_region = false;
288279
let mut found = false;
289280
let mut new_lines = vec![];
290281
let start = Regex::new(start).unwrap();
291282
let end = Regex::new(end).unwrap();
292283

293-
for line in lines.clone() {
284+
for line in text.lines() {
294285
if in_old_region {
295-
if end.is_match(&line) {
286+
if end.is_match(line) {
296287
in_old_region = false;
297-
new_lines.extend(replacements());
288+
new_lines.extend(replace_it.clone());
298289
new_lines.push(line.to_string());
299290
}
300-
} else if start.is_match(&line) {
291+
} else if start.is_match(line) {
301292
if !replace_start {
302293
new_lines.push(line.to_string());
303294
}
@@ -315,10 +306,12 @@ where
315306
eprintln!("error: regex `{:?}` not found. You may have to update it.", start);
316307
}
317308

318-
FileChange {
319-
changed: lines.ne(new_lines.clone()),
320-
new_lines: new_lines.join("\n"),
309+
let mut new_lines = new_lines.join("\n");
310+
if text.ends_with('\n') {
311+
new_lines.push('\n');
321312
}
313+
let changed = new_lines != text;
314+
FileChange { changed, new_lines }
322315
}
323316

324317
/// Returns the path to the Clippy project directory

clippy_dev/src/main.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mod fmt;
88
mod new_lint;
99
mod stderr_length_check;
1010

11-
#[derive(PartialEq)]
11+
#[derive(Clone, Copy, PartialEq)]
1212
enum UpdateMode {
1313
Check,
1414
Change,
@@ -113,9 +113,9 @@ fn main() {
113113
if matches.is_present("print-only") {
114114
print_lints();
115115
} else if matches.is_present("check") {
116-
update_lints(&UpdateMode::Check);
116+
update_lints(UpdateMode::Check);
117117
} else {
118-
update_lints(&UpdateMode::Change);
118+
update_lints(UpdateMode::Change);
119119
}
120120
},
121121
("new_lint", Some(matches)) => {
@@ -124,7 +124,7 @@ fn main() {
124124
matches.value_of("name"),
125125
matches.value_of("category"),
126126
) {
127-
Ok(_) => update_lints(&UpdateMode::Change),
127+
Ok(_) => update_lints(UpdateMode::Change),
128128
Err(e) => eprintln!("Unable to create lint: {}", e),
129129
}
130130
},
@@ -150,7 +150,7 @@ fn print_lints() {
150150
println!(
151151
"* [{}]({}#{}) ({})",
152152
lint.name,
153-
clippy_dev::DOCS_LINK.clone(),
153+
clippy_dev::DOCS_LINK,
154154
lint.name,
155155
lint.desc
156156
);
@@ -161,7 +161,7 @@ fn print_lints() {
161161
}
162162

163163
#[allow(clippy::too_many_lines)]
164-
fn update_lints(update_mode: &UpdateMode) {
164+
fn update_lints(update_mode: UpdateMode) {
165165
let lint_list: Vec<Lint> = gather_all().collect();
166166

167167
let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list.clone().into_iter()).collect();
@@ -175,7 +175,7 @@ fn update_lints(update_mode: &UpdateMode) {
175175
"begin lint list",
176176
"end lint list",
177177
false,
178-
update_mode == &UpdateMode::Change,
178+
update_mode == UpdateMode::Change,
179179
|| {
180180
format!(
181181
"pub const ALL_LINTS: [Lint; {}] = {:#?};",
@@ -191,23 +191,25 @@ fn update_lints(update_mode: &UpdateMode) {
191191

192192
file_change |= replace_region_in_file(
193193
Path::new("README.md"),
194-
r#"\[There are \d+ lints included in this crate!\]\(https://rust-lang.github.io/rust-clippy/master/index.html\)"#,
194+
&format!(r#"\[There are \d+ lints included in this crate!\]\({}\)"#, DOCS_LINK),
195195
"",
196196
true,
197-
update_mode == &UpdateMode::Change,
197+
update_mode == UpdateMode::Change,
198198
|| {
199-
vec![
200-
format!("[There are {} lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)", lint_count)
201-
]
202-
}
203-
).changed;
199+
vec![format!(
200+
"[There are {} lints included in this crate!]({})",
201+
lint_count, DOCS_LINK
202+
)]
203+
},
204+
)
205+
.changed;
204206

205207
file_change |= replace_region_in_file(
206208
Path::new("CHANGELOG.md"),
207209
"<!-- begin autogenerated links to lint list -->",
208210
"<!-- end autogenerated links to lint list -->",
209211
false,
210-
update_mode == &UpdateMode::Change,
212+
update_mode == UpdateMode::Change,
211213
|| gen_changelog_lint_list(lint_list.clone()),
212214
)
213215
.changed;
@@ -217,7 +219,7 @@ fn update_lints(update_mode: &UpdateMode) {
217219
"begin deprecated lints",
218220
"end deprecated lints",
219221
false,
220-
update_mode == &UpdateMode::Change,
222+
update_mode == UpdateMode::Change,
221223
|| gen_deprecated(&lint_list),
222224
)
223225
.changed;
@@ -227,7 +229,7 @@ fn update_lints(update_mode: &UpdateMode) {
227229
"begin register lints",
228230
"end register lints",
229231
false,
230-
update_mode == &UpdateMode::Change,
232+
update_mode == UpdateMode::Change,
231233
|| gen_register_lint_list(&lint_list),
232234
)
233235
.changed;
@@ -237,7 +239,7 @@ fn update_lints(update_mode: &UpdateMode) {
237239
"begin lints modules",
238240
"end lints modules",
239241
false,
240-
update_mode == &UpdateMode::Change,
242+
update_mode == UpdateMode::Change,
241243
|| gen_modules_list(lint_list.clone()),
242244
)
243245
.changed;
@@ -248,7 +250,7 @@ fn update_lints(update_mode: &UpdateMode) {
248250
r#"store.register_group\(true, "clippy::all""#,
249251
r#"\]\);"#,
250252
false,
251-
update_mode == &UpdateMode::Change,
253+
update_mode == UpdateMode::Change,
252254
|| {
253255
// clippy::all should only include the following lint groups:
254256
let all_group_lints = usable_lints
@@ -271,13 +273,13 @@ fn update_lints(update_mode: &UpdateMode) {
271273
&format!("store.register_group\\(true, \"clippy::{}\"", lint_group),
272274
r#"\]\);"#,
273275
false,
274-
update_mode == &UpdateMode::Change,
276+
update_mode == UpdateMode::Change,
275277
|| gen_lint_group_list(lints.clone()),
276278
)
277279
.changed;
278280
}
279281

280-
if update_mode == &UpdateMode::Check && file_change {
282+
if update_mode == UpdateMode::Check && file_change {
281283
println!(
282284
"Not all lints defined properly. \
283285
Please run `cargo dev update_lints` to make sure all lints are defined properly."

clippy_dev/src/new_lint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ fn get_lint_file_contents(
117117
context_import: &str,
118118
) -> String {
119119
format!(
120-
"use rustc_lint::{{LintArray, LintPass, {type}, {context_import}}};
120+
"use rustc_lint::{{{type}, {context_import}}};
121121
use rustc_session::{{declare_lint_pass, declare_tool_lint}};
122122
{pass_import}
123123

0 commit comments

Comments
 (0)