Skip to content

Commit ab6606b

Browse files
committed
Update Clippy
1 parent 61c096c commit ab6606b

File tree

67 files changed

+713
-575
lines changed

Some content is hidden

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

67 files changed

+713
-575
lines changed

.cargo/config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[alias]
22
uitest = "test --test compile-test"
3+
dev = "run --package clippy_dev --bin clippy_dev --manifest-path clippy_dev/Cargo.toml --"
34

45
[build]
56
rustflags = ["-Zunstable-options"]

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ checked during review or continuous integration.
1515
- [ ] Followed [lint naming conventions][lint_naming]
1616
- [ ] Added passing UI tests (including committed `.stderr` file)
1717
- [ ] `cargo test` passes locally
18-
- [ ] Executed `./util/dev update_lints`
18+
- [ ] Executed `cargo dev update_lints`
1919
- [ ] Added lint documentation
20-
- [ ] Run `./util/dev fmt`
20+
- [ ] Run `cargo dev fmt`
2121

2222
[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints
2323

CHANGELOG.md

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,60 @@ document.
66

77
## Unreleased / In Rust Beta or Nightly
88

9-
[c8e3cfb...master](https://github.com/rust-lang/rust-clippy/compare/c8e3cfb...master)
9+
[69f99e7...master](https://github.com/rust-lang/rust-clippy/compare/69f99e7...master)
1010

11-
## Rust 1.41
11+
## Rust 1.42
1212

1313
Current Beta
1414

15+
## Rust 1.41
16+
17+
Current stable, released 2020-01-30
18+
19+
[c8e3cfb...69f99e7](https://github.com/rust-lang/rust-clippy/compare/c8e3cfb...69f99e7)
20+
21+
* New Lints:
22+
* [`exit`] [#4697](https://github.com/rust-lang/rust-clippy/pull/4697)
23+
* [`to_digit_is_some`] [#4801](https://github.com/rust-lang/rust-clippy/pull/4801)
24+
* [`tabs_in_doc_comments`] [#4806](https://github.com/rust-lang/rust-clippy/pull/4806)
25+
* [`large_stack_arrays`] [#4807](https://github.com/rust-lang/rust-clippy/pull/4807)
26+
* [`same_functions_in_if_condition`] [#4814](https://github.com/rust-lang/rust-clippy/pull/4814)
27+
* [`zst_offset`] [#4816](https://github.com/rust-lang/rust-clippy/pull/4816)
28+
* [`as_conversions`] [#4821](https://github.com/rust-lang/rust-clippy/pull/4821)
29+
* [`missing_errors_doc`] [#4884](https://github.com/rust-lang/rust-clippy/pull/4884)
30+
* [`transmute_float_to_int`] [#4889](https://github.com/rust-lang/rust-clippy/pull/4889)
31+
* Remove plugin interface, see
32+
[Inside Rust Blog](https://blog.rust-lang.org/inside-rust/2019/11/04/Clippy-removes-plugin-interface.html) for
33+
details [#4714](https://github.com/rust-lang/rust-clippy/pull/4714)
34+
* Move [`use_self`] to nursery group [#4863](https://github.com/rust-lang/rust-clippy/pull/4863)
35+
* Deprecate [`into_iter_on_array`] [#4788](https://github.com/rust-lang/rust-clippy/pull/4788)
36+
* Expand [`string_lit_as_bytes`] to also trigger when literal has escapes
37+
[#4808](https://github.com/rust-lang/rust-clippy/pull/4808)
38+
* Fix false positive in `comparison_chain` [#4842](https://github.com/rust-lang/rust-clippy/pull/4842)
39+
* Fix false positive in `while_immutable_condition` [#4730](https://github.com/rust-lang/rust-clippy/pull/4730)
40+
* Fix false positive in `explicit_counter_loop` [#4803](https://github.com/rust-lang/rust-clippy/pull/4803)
41+
* Fix false positive in `must_use_candidate` [#4794](https://github.com/rust-lang/rust-clippy/pull/4794)
42+
* Fix false positive in `print_with_newline` and `write_with_newline`
43+
[#4769](https://github.com/rust-lang/rust-clippy/pull/4769)
44+
* Fix false positive in `derive_hash_xor_eq` [#4766](https://github.com/rust-lang/rust-clippy/pull/4766)
45+
* Fix false positive in `missing_inline_in_public_items` [#4870](https://github.com/rust-lang/rust-clippy/pull/4870)
46+
* Fix false positive in `string_add` [#4880](https://github.com/rust-lang/rust-clippy/pull/4880)
47+
* Fix false positive in `float_arithmetic` [#4851](https://github.com/rust-lang/rust-clippy/pull/4851)
48+
* Fix false positive in `cast_sign_loss` [#4883](https://github.com/rust-lang/rust-clippy/pull/4883)
49+
* Fix false positive in `manual_swap` [#4877](https://github.com/rust-lang/rust-clippy/pull/4877)
50+
* Fix ICEs occurring while checking some block expressions [#4772](https://github.com/rust-lang/rust-clippy/pull/4772)
51+
* Fix ICE in `use_self` [#4776](https://github.com/rust-lang/rust-clippy/pull/4776)
52+
* Fix ICEs related to `const_generics` [#4780](https://github.com/rust-lang/rust-clippy/pull/4780)
53+
* Display help when running `clippy-driver` without arguments, instead of ICEing
54+
[#4810](https://github.com/rust-lang/rust-clippy/pull/4810)
55+
* Clippy has its own ICE message now [#4588](https://github.com/rust-lang/rust-clippy/pull/4588)
56+
* Show deprecated lints in the documentation again [#4757](https://github.com/rust-lang/rust-clippy/pull/4757)
57+
* Improve Documentation by adding positive examples to some lints
58+
[#4832](https://github.com/rust-lang/rust-clippy/pull/4832)
59+
1560
## Rust 1.40
1661

17-
Current stable, released 2019-12-19
62+
Released 2019-12-19
1863

1964
[4e7e71b...c8e3cfb](https://github.com/rust-lang/rust-clippy/compare/4e7e71b...c8e3cfb)
2065

@@ -1153,6 +1198,7 @@ Released 2018-09-13
11531198
[`len_without_is_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#len_without_is_empty
11541199
[`len_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#len_zero
11551200
[`let_and_return`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return
1201+
[`let_underscore_lock`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_underscore_lock
11561202
[`let_underscore_must_use`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_underscore_must_use
11571203
[`let_unit_value`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value
11581204
[`linkedlist`]: https://rust-lang.github.io/rust-clippy/master/index.html#linkedlist
@@ -1284,6 +1330,7 @@ Released 2018-09-13
12841330
[`should_implement_trait`]: https://rust-lang.github.io/rust-clippy/master/index.html#should_implement_trait
12851331
[`similar_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#similar_names
12861332
[`single_char_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_pattern
1333+
[`single_component_path_imports`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_component_path_imports
12871334
[`single_match`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_match
12881335
[`single_match_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else
12891336
[`skip_while_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#skip_while_next

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub fn register_plugins(reg: &mut rustc_driver::plugin::Registry) {
105105

106106
The [`plugin::PluginRegistry`][plugin_registry] provides two methods to register lints: [register_early_lint_pass][reg_early_lint_pass] and [register_late_lint_pass][reg_late_lint_pass].
107107
Both take an object that implements an [`EarlyLintPass`][early_lint_pass] or [`LateLintPass`][late_lint_pass] respectively. This is done in every single lint.
108-
It's worth noting that the majority of `clippy_lints/src/lib.rs` is autogenerated by `util/dev update_lints` and you don't have to add anything by hand. When you are writing your own lint, you can use that script to save you some time.
108+
It's worth noting that the majority of `clippy_lints/src/lib.rs` is autogenerated by `cargo dev update_lints` and you don't have to add anything by hand. When you are writing your own lint, you can use that script to save you some time.
109109

110110
```rust
111111
// ./clippy_lints/src/else_if_without_else.rs

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 349 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
9+
[There are 351 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

ci/base-tests.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ cargo test --features deny-warnings
2222
)
2323

2424
# Perform various checks for lint registration
25-
./util/dev update_lints --check
26-
./util/dev --limit-stderr-length
25+
cargo dev update_lints --check
26+
cargo dev --limit-stderr-length
2727

2828
# Check running clippy-driver without cargo
2929
(

clippy_dev/src/fmt.rs

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
use clippy_dev::clippy_project_root;
12
use shell_escape::escape;
23
use std::ffi::OsStr;
34
use std::io;
4-
use std::path::{Path, PathBuf};
5+
use std::path::Path;
56
use std::process::{self, Command};
67
use walkdir::WalkDir;
78

89
#[derive(Debug)]
910
pub enum CliError {
1011
CommandFailed(String),
1112
IoError(io::Error),
12-
ProjectRootNotFound,
1313
RustfmtNotInstalled,
1414
WalkDirError(walkdir::Error),
1515
}
@@ -35,7 +35,7 @@ pub fn run(check: bool, verbose: bool) {
3535
fn try_run(context: &FmtContext) -> Result<bool, CliError> {
3636
let mut success = true;
3737

38-
let project_root = project_root()?;
38+
let project_root = clippy_project_root();
3939

4040
rustfmt_test(context)?;
4141

@@ -69,9 +69,6 @@ pub fn run(check: bool, verbose: bool) {
6969
CliError::IoError(err) => {
7070
eprintln!("error: {}", err);
7171
},
72-
CliError::ProjectRootNotFound => {
73-
eprintln!("error: Can't determine root of project. Please run inside a Clippy working dir.");
74-
},
7572
CliError::RustfmtNotInstalled => {
7673
eprintln!("error: rustfmt nightly is not installed.");
7774
},
@@ -88,7 +85,7 @@ pub fn run(check: bool, verbose: bool) {
8885
Ok(false) => {
8986
eprintln!();
9087
eprintln!("Formatting check failed.");
91-
eprintln!("Run `./util/dev fmt` to update formatting.");
88+
eprintln!("Run `cargo dev fmt` to update formatting.");
9289
1
9390
},
9491
Err(err) => {
@@ -176,22 +173,3 @@ fn rustfmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
176173
}
177174
Ok(success)
178175
}
179-
180-
fn project_root() -> Result<PathBuf, CliError> {
181-
let current_dir = std::env::current_dir()?;
182-
for path in current_dir.ancestors() {
183-
let result = std::fs::read_to_string(path.join("Cargo.toml"));
184-
if let Err(err) = &result {
185-
if err.kind() == io::ErrorKind::NotFound {
186-
continue;
187-
}
188-
}
189-
190-
let content = result?;
191-
if content.contains("[package]\nname = \"clippy\"") {
192-
return Ok(path.to_path_buf());
193-
}
194-
}
195-
196-
Err(CliError::ProjectRootNotFound)
197-
}

clippy_dev/src/lib.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::collections::HashMap;
77
use std::ffi::OsStr;
88
use std::fs;
99
use std::io::prelude::*;
10+
use std::path::{Path, PathBuf};
1011
use walkdir::WalkDir;
1112

1213
lazy_static! {
@@ -205,7 +206,8 @@ fn parse_contents(content: &str, filename: &str) -> impl Iterator<Item = Lint> {
205206
fn lint_files() -> impl Iterator<Item = walkdir::DirEntry> {
206207
// We use `WalkDir` instead of `fs::read_dir` here in order to recurse into subdirectories.
207208
// Otherwise we would not collect all the lints, for example in `clippy_lints/src/methods/`.
208-
WalkDir::new("../clippy_lints/src")
209+
let path = clippy_project_root().join("clippy_lints/src");
210+
WalkDir::new(path)
209211
.into_iter()
210212
.filter_map(std::result::Result::ok)
211213
.filter(|f| f.path().extension() == Some(OsStr::new("rs")))
@@ -225,7 +227,7 @@ pub struct FileChange {
225227
/// See `replace_region_in_text` for documentation of the other options.
226228
#[allow(clippy::expect_fun_call)]
227229
pub fn replace_region_in_file<F>(
228-
path: &str,
230+
path: &Path,
229231
start: &str,
230232
end: &str,
231233
replace_start: bool,
@@ -235,14 +237,15 @@ pub fn replace_region_in_file<F>(
235237
where
236238
F: Fn() -> Vec<String>,
237239
{
238-
let mut f = fs::File::open(path).expect(&format!("File not found: {}", path));
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()));
239242
let mut contents = String::new();
240243
f.read_to_string(&mut contents)
241244
.expect("Something went wrong reading the file");
242245
let file_change = replace_region_in_text(&contents, start, end, replace_start, replacements);
243246

244247
if write_back {
245-
let mut f = fs::File::create(path).expect(&format!("File not found: {}", path));
248+
let mut f = fs::File::create(&path).expect(&format!("File not found: {}", path.to_string_lossy()));
246249
f.write_all(file_change.new_lines.as_bytes())
247250
.expect("Unable to write file");
248251
// Ensure we write the changes with a trailing newline so that
@@ -318,6 +321,26 @@ where
318321
}
319322
}
320323

324+
/// Returns the path to the Clippy project directory
325+
#[must_use]
326+
pub fn clippy_project_root() -> PathBuf {
327+
let current_dir = std::env::current_dir().unwrap();
328+
for path in current_dir.ancestors() {
329+
let result = std::fs::read_to_string(path.join("Cargo.toml"));
330+
if let Err(err) = &result {
331+
if err.kind() == std::io::ErrorKind::NotFound {
332+
continue;
333+
}
334+
}
335+
336+
let content = result.unwrap();
337+
if content.contains("[package]\nname = \"clippy\"") {
338+
return path.to_path_buf();
339+
}
340+
}
341+
panic!("error: Can't determine root of project. Please run inside a Clippy working dir.");
342+
}
343+
321344
#[test]
322345
fn test_parse_contents() {
323346
let result: Vec<Lint> = parse_contents(

clippy_dev/src/main.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use clap::{App, Arg, SubCommand};
44
use clippy_dev::*;
5+
use std::path::Path;
56

67
mod fmt;
78
mod new_lint;
@@ -49,12 +50,12 @@ fn main() {
4950
.arg(
5051
Arg::with_name("check")
5152
.long("check")
52-
.help("Checks that util/dev update_lints has been run. Used on CI."),
53+
.help("Checks that `cargo dev update_lints` has been run. Used on CI."),
5354
),
5455
)
5556
.subcommand(
5657
SubCommand::with_name("new_lint")
57-
.about("Create new lint and run util/dev update_lints")
58+
.about("Create new lint and run `cargo dev update_lints`")
5859
.arg(
5960
Arg::with_name("pass")
6061
.short("p")
@@ -170,7 +171,7 @@ fn update_lints(update_mode: &UpdateMode) {
170171
sorted_usable_lints.sort_by_key(|lint| lint.name.clone());
171172

172173
let mut file_change = replace_region_in_file(
173-
"../src/lintlist/mod.rs",
174+
Path::new("src/lintlist/mod.rs"),
174175
"begin lint list",
175176
"end lint list",
176177
false,
@@ -189,7 +190,7 @@ fn update_lints(update_mode: &UpdateMode) {
189190
.changed;
190191

191192
file_change |= replace_region_in_file(
192-
"../README.md",
193+
Path::new("README.md"),
193194
r#"\[There are \d+ lints included in this crate!\]\(https://rust-lang.github.io/rust-clippy/master/index.html\)"#,
194195
"",
195196
true,
@@ -202,7 +203,7 @@ fn update_lints(update_mode: &UpdateMode) {
202203
).changed;
203204

204205
file_change |= replace_region_in_file(
205-
"../CHANGELOG.md",
206+
Path::new("CHANGELOG.md"),
206207
"<!-- begin autogenerated links to lint list -->",
207208
"<!-- end autogenerated links to lint list -->",
208209
false,
@@ -212,7 +213,7 @@ fn update_lints(update_mode: &UpdateMode) {
212213
.changed;
213214

214215
file_change |= replace_region_in_file(
215-
"../clippy_lints/src/lib.rs",
216+
Path::new("clippy_lints/src/lib.rs"),
216217
"begin deprecated lints",
217218
"end deprecated lints",
218219
false,
@@ -222,7 +223,7 @@ fn update_lints(update_mode: &UpdateMode) {
222223
.changed;
223224

224225
file_change |= replace_region_in_file(
225-
"../clippy_lints/src/lib.rs",
226+
Path::new("clippy_lints/src/lib.rs"),
226227
"begin register lints",
227228
"end register lints",
228229
false,
@@ -232,7 +233,7 @@ fn update_lints(update_mode: &UpdateMode) {
232233
.changed;
233234

234235
file_change |= replace_region_in_file(
235-
"../clippy_lints/src/lib.rs",
236+
Path::new("clippy_lints/src/lib.rs"),
236237
"begin lints modules",
237238
"end lints modules",
238239
false,
@@ -243,7 +244,7 @@ fn update_lints(update_mode: &UpdateMode) {
243244

244245
// Generate lists of lints in the clippy::all lint group
245246
file_change |= replace_region_in_file(
246-
"../clippy_lints/src/lib.rs",
247+
Path::new("clippy_lints/src/lib.rs"),
247248
r#"store.register_group\(true, "clippy::all""#,
248249
r#"\]\);"#,
249250
false,
@@ -266,7 +267,7 @@ fn update_lints(update_mode: &UpdateMode) {
266267
// Generate the list of lints for all other lint groups
267268
for (lint_group, lints) in Lint::by_lint_group(&usable_lints) {
268269
file_change |= replace_region_in_file(
269-
"../clippy_lints/src/lib.rs",
270+
Path::new("clippy_lints/src/lib.rs"),
270271
&format!("store.register_group\\(true, \"clippy::{}\"", lint_group),
271272
r#"\]\);"#,
272273
false,
@@ -279,7 +280,7 @@ fn update_lints(update_mode: &UpdateMode) {
279280
if update_mode == &UpdateMode::Check && file_change {
280281
println!(
281282
"Not all lints defined properly. \
282-
Please run `util/dev update_lints` to make sure all lints are defined properly."
283+
Please run `cargo dev update_lints` to make sure all lints are defined properly."
283284
);
284285
std::process::exit(1);
285286
}

0 commit comments

Comments
 (0)