Skip to content

Commit cea4237

Browse files
authored
Merge branch 'rust-lang:master' into issue-6776
2 parents a71e475 + 32a3744 commit cea4237

File tree

224 files changed

+2915
-1480
lines changed

Some content is hidden

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

224 files changed

+2915
-1480
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6440,6 +6440,7 @@ Released 2018-09-13
64406440
[`used_underscore_items`]: https://rust-lang.github.io/rust-clippy/master/index.html#used_underscore_items
64416441
[`useless_asref`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_asref
64426442
[`useless_attribute`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_attribute
6443+
[`useless_concat`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_concat
64436444
[`useless_conversion`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion
64446445
[`useless_format`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_format
64456446
[`useless_let_if_seq`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_let_if_seq

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Clippy team directly by mentioning them in the issue or over on [Zulip]. All
5151
currently active team members can be found
5252
[here](https://github.com/rust-lang/rust-clippy/blob/master/triagebot.toml#L18)
5353

54-
Some issues are easier than others. The [`good-first-issue`] label can be used to find the easy
54+
Some issues are easier than others. The [`good first issue`] label can be used to find the easy
5555
issues. You can use `@rustbot claim` to assign the issue to yourself.
5656

5757
There are also some abandoned PRs, marked with [`S-inactive-closed`].
@@ -70,7 +70,7 @@ To figure out how this syntax structure is encoded in the AST, it is recommended
7070
Usually the lint will end up to be a nested series of matches and ifs, [like so][deep-nesting].
7171
But we can make it nest-less by using [let chains], [like this][nest-less].
7272

73-
[`E-medium`] issues are generally pretty easy too, though it's recommended you work on an [`good-first-issue`]
73+
[`E-medium`] issues are generally pretty easy too, though it's recommended you work on an [`good first issue`]
7474
first. Sometimes they are only somewhat involved code wise, but not difficult per-se.
7575
Note that [`E-medium`] issues may require some knowledge of Clippy internals or some
7676
debugging to find the actual problem behind the issue.
@@ -79,7 +79,7 @@ debugging to find the actual problem behind the issue.
7979
lot of methods that are useful, though one of the most useful would be `expr_ty` (gives the type of
8080
an AST expression).
8181

82-
[`good-first-issue`]: https://github.com/rust-lang/rust-clippy/labels/good-first-issue
82+
[`good first issue`]: https://github.com/rust-lang/rust-clippy/labels/good%20first%20issue
8383
[`S-inactive-closed`]: https://github.com/rust-lang/rust-clippy/pulls?q=is%3Aclosed+label%3AS-inactive-closed
8484
[`T-AST`]: https://github.com/rust-lang/rust-clippy/labels/T-AST
8585
[`T-middle`]: https://github.com/rust-lang/rust-clippy/labels/T-middle

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ walkdir = "2.3"
4242
filetime = "0.2.9"
4343
itertools = "0.12"
4444
pulldown-cmark = { version = "0.11", default-features = false, features = ["html"] }
45-
askama = { version = "0.13", default-features = false, features = ["alloc", "config", "derive"] }
45+
askama = { version = "0.14", default-features = false, features = ["alloc", "config", "derive"] }
4646

4747
# UI test dependencies
4848
if_chain = "1.0"

book/src/development/basics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ toolchain called `clippy` by default, see `cargo dev setup toolchain --help`
151151
for other options.
152152

153153
```terminal
154-
cargo dev setup toolcahin
154+
cargo dev setup toolchain
155155
```
156156

157157
Now you may run `cargo +clippy clippy` in any project using the new toolchain.

book/src/development/the_team.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ this group to help with triaging, which can include:
3333

3434
1. **Labeling issues**
3535

36-
For the `good-first-issue` label, it can still be good to use `@rustbot` to
36+
For the `good first issue` label, it can still be good to use `@rustbot` to
3737
subscribe to the issue and help interested parties, if they post questions
3838
in the comments.
3939

book/src/lint_configuration.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,7 @@ The minimum rust version that the project supports. Defaults to the `rust-versio
836836
* [`manual_repeat_n`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_repeat_n)
837837
* [`manual_retain`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_retain)
838838
* [`manual_slice_fill`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_slice_fill)
839+
* [`manual_slice_size_calculation`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_slice_size_calculation)
839840
* [`manual_split_once`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_split_once)
840841
* [`manual_str_repeat`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_str_repeat)
841842
* [`manual_strip`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_strip)
@@ -1025,7 +1026,7 @@ The order of associated items in traits.
10251026
The maximum size (in bytes) to consider a `Copy` type for passing by value instead of by
10261027
reference.
10271028

1028-
**Default Value:** `target_pointer_width * 2`
1029+
**Default Value:** `target_pointer_width`
10291030

10301031
---
10311032
**Affected lints:**

clippy_config/src/conf.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,7 @@ define_Conf! {
739739
manual_repeat_n,
740740
manual_retain,
741741
manual_slice_fill,
742+
manual_slice_size_calculation,
742743
manual_split_once,
743744
manual_str_repeat,
744745
manual_strip,
@@ -827,7 +828,7 @@ define_Conf! {
827828
trait_assoc_item_kinds_order: SourceItemOrderingTraitAssocItemKinds = DEFAULT_TRAIT_ASSOC_ITEM_KINDS_ORDER.into(),
828829
/// The maximum size (in bytes) to consider a `Copy` type for passing by value instead of by
829830
/// reference.
830-
#[default_text = "target_pointer_width * 2"]
831+
#[default_text = "target_pointer_width"]
831832
#[lints(trivially_copy_pass_by_ref)]
832833
trivial_copy_size_limit: Option<u64> = None,
833834
/// The maximum complexity a type can have

clippy_dev/src/fmt.rs

Lines changed: 80 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
use crate::utils::{ClippyInfo, ErrAction, UpdateMode, panic_action, run_with_args_split, run_with_output};
1+
use crate::utils::{
2+
ErrAction, FileUpdater, UpdateMode, UpdateStatus, expect_action, run_with_output, split_args_for_threads,
3+
walk_dir_no_dot_or_target,
4+
};
25
use itertools::Itertools;
36
use rustc_lexer::{TokenKind, tokenize};
7+
use std::fmt::Write;
48
use std::fs;
59
use std::io::{self, Read};
610
use std::ops::ControlFlow;
711
use std::path::PathBuf;
812
use std::process::{self, Command, Stdio};
9-
use walkdir::WalkDir;
1013

1114
pub enum Error {
1215
Io(io::Error),
@@ -225,49 +228,59 @@ fn fmt_conf(check: bool) -> Result<(), Error> {
225228
Ok(())
226229
}
227230

228-
fn run_rustfmt(clippy: &ClippyInfo, update_mode: UpdateMode) {
231+
/// Format the symbols list
232+
fn fmt_syms(update_mode: UpdateMode) {
233+
FileUpdater::default().update_file_checked(
234+
"cargo dev fmt",
235+
update_mode,
236+
"clippy_utils/src/sym.rs",
237+
&mut |_, text: &str, new_text: &mut String| {
238+
let (pre, conf) = text.split_once("generate! {\n").expect("can't find generate! call");
239+
let (conf, post) = conf.split_once("\n}\n").expect("can't find end of generate! call");
240+
let mut lines = conf
241+
.lines()
242+
.map(|line| {
243+
let line = line.trim();
244+
line.strip_suffix(',').unwrap_or(line).trim_end()
245+
})
246+
.collect::<Vec<_>>();
247+
lines.sort_unstable();
248+
write!(
249+
new_text,
250+
"{pre}generate! {{\n {},\n}}\n{post}",
251+
lines.join(",\n "),
252+
)
253+
.unwrap();
254+
if text == new_text {
255+
UpdateStatus::Unchanged
256+
} else {
257+
UpdateStatus::Changed
258+
}
259+
},
260+
);
261+
}
262+
263+
fn run_rustfmt(update_mode: UpdateMode) {
229264
let mut rustfmt_path = String::from_utf8(run_with_output(
230265
"rustup which rustfmt",
231266
Command::new("rustup").args(["which", "rustfmt"]),
232267
))
233268
.expect("invalid rustfmt path");
234269
rustfmt_path.truncate(rustfmt_path.trim_end().len());
235270

236-
let mut cargo_path = String::from_utf8(run_with_output(
237-
"rustup which cargo",
238-
Command::new("rustup").args(["which", "cargo"]),
239-
))
240-
.expect("invalid cargo path");
241-
cargo_path.truncate(cargo_path.trim_end().len());
242-
243-
// Start all format jobs first before waiting on the results.
244-
let mut children = Vec::with_capacity(16);
245-
for &path in &[
246-
".",
247-
"clippy_config",
248-
"clippy_dev",
249-
"clippy_lints",
250-
"clippy_utils",
251-
"rustc_tools_util",
252-
"lintcheck",
253-
] {
254-
let mut cmd = Command::new(&cargo_path);
255-
cmd.current_dir(clippy.path.join(path))
256-
.args(["fmt"])
257-
.env("RUSTFMT", &rustfmt_path)
258-
.stdout(Stdio::null())
259-
.stdin(Stdio::null())
260-
.stderr(Stdio::piped());
261-
if update_mode.is_check() {
262-
cmd.arg("--check");
263-
}
264-
match cmd.spawn() {
265-
Ok(x) => children.push(("cargo fmt", x)),
266-
Err(ref e) => panic_action(&e, ErrAction::Run, "cargo fmt".as_ref()),
267-
}
268-
}
271+
let args: Vec<_> = walk_dir_no_dot_or_target()
272+
.filter_map(|e| {
273+
let e = expect_action(e, ErrAction::Read, ".");
274+
e.path()
275+
.as_os_str()
276+
.as_encoded_bytes()
277+
.ends_with(b".rs")
278+
.then(|| e.into_path().into_os_string())
279+
})
280+
.collect();
269281

270-
run_with_args_split(
282+
let mut children: Vec<_> = split_args_for_threads(
283+
32,
271284
|| {
272285
let mut cmd = Command::new(&rustfmt_path);
273286
if update_mode.is_check() {
@@ -276,67 +289,45 @@ fn run_rustfmt(clippy: &ClippyInfo, update_mode: UpdateMode) {
276289
cmd.stdout(Stdio::null())
277290
.stdin(Stdio::null())
278291
.stderr(Stdio::piped())
279-
.args(["--config", "show_parse_errors=false"]);
292+
.args(["--unstable-features", "--skip-children"]);
280293
cmd
281294
},
282-
|cmd| match cmd.spawn() {
283-
Ok(x) => children.push(("rustfmt", x)),
284-
Err(ref e) => panic_action(&e, ErrAction::Run, "rustfmt".as_ref()),
285-
},
286-
WalkDir::new("tests")
287-
.into_iter()
288-
.filter_entry(|p| p.path().file_name().is_none_or(|x| x != "skip_rustfmt"))
289-
.filter_map(|e| {
290-
let e = e.expect("error reading `tests`");
291-
e.path()
292-
.as_os_str()
293-
.as_encoded_bytes()
294-
.ends_with(b".rs")
295-
.then(|| e.into_path().into_os_string())
296-
}),
297-
);
295+
args.iter(),
296+
)
297+
.map(|mut cmd| expect_action(cmd.spawn(), ErrAction::Run, "rustfmt"))
298+
.collect();
298299

299-
for (name, child) in &mut children {
300-
match child.wait() {
301-
Ok(status) => match (update_mode, status.exit_ok()) {
302-
(UpdateMode::Check | UpdateMode::Change, Ok(())) => {},
303-
(UpdateMode::Check, Err(_)) => {
304-
let mut s = String::new();
305-
if let Some(mut stderr) = child.stderr.take()
306-
&& stderr.read_to_string(&mut s).is_ok()
307-
{
308-
eprintln!("{s}");
309-
}
310-
eprintln!("Formatting check failed!\nRun `cargo dev fmt` to update.");
311-
process::exit(1);
312-
},
313-
(UpdateMode::Change, Err(e)) => {
314-
let mut s = String::new();
315-
if let Some(mut stderr) = child.stderr.take()
316-
&& stderr.read_to_string(&mut s).is_ok()
317-
{
318-
eprintln!("{s}");
319-
}
320-
panic_action(&e, ErrAction::Run, name.as_ref());
321-
},
300+
for child in &mut children {
301+
let status = expect_action(child.wait(), ErrAction::Run, "rustfmt");
302+
match (update_mode, status.exit_ok()) {
303+
(UpdateMode::Check | UpdateMode::Change, Ok(())) => {},
304+
(UpdateMode::Check, Err(_)) => {
305+
let mut s = String::new();
306+
if let Some(mut stderr) = child.stderr.take()
307+
&& stderr.read_to_string(&mut s).is_ok()
308+
{
309+
eprintln!("{s}");
310+
}
311+
eprintln!("Formatting check failed!\nRun `cargo dev fmt` to update.");
312+
process::exit(1);
313+
},
314+
(UpdateMode::Change, e) => {
315+
let mut s = String::new();
316+
if let Some(mut stderr) = child.stderr.take()
317+
&& stderr.read_to_string(&mut s).is_ok()
318+
{
319+
eprintln!("{s}");
320+
}
321+
expect_action(e, ErrAction::Run, "rustfmt");
322322
},
323-
Err(ref e) => panic_action(e, ErrAction::Run, name.as_ref()),
324323
}
325324
}
326325
}
327326

328327
// the "main" function of cargo dev fmt
329-
pub fn run(clippy: &ClippyInfo, update_mode: UpdateMode) {
330-
if clippy.has_intellij_hook {
331-
eprintln!(
332-
"error: a local rustc repo is enabled as path dependency via `cargo dev setup intellij`.\n\
333-
Not formatting because that would format the local repo as well!\n\
334-
Please revert the changes to `Cargo.toml`s with `cargo dev remove intellij`."
335-
);
336-
return;
337-
}
338-
run_rustfmt(clippy, update_mode);
339-
328+
pub fn run(update_mode: UpdateMode) {
329+
run_rustfmt(update_mode);
330+
fmt_syms(update_mode);
340331
if let Err(e) = fmt_conf(update_mode.is_check()) {
341332
e.display();
342333
process::exit(1);

clippy_dev/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn main() {
2626
allow_staged,
2727
allow_no_vcs,
2828
} => dogfood::dogfood(fix, allow_dirty, allow_staged, allow_no_vcs),
29-
DevCommand::Fmt { check } => fmt::run(&clippy, utils::UpdateMode::from_check(check)),
29+
DevCommand::Fmt { check } => fmt::run(utils::UpdateMode::from_check(check)),
3030
DevCommand::UpdateLints { check } => update_lints::update(utils::UpdateMode::from_check(check)),
3131
DevCommand::NewLint {
3232
pass,

clippy_dev/src/rename_lint.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use crate::update_lints::{RenamedLint, find_lint_decls, generate_lint_files, read_deprecated_lints};
22
use crate::utils::{
3-
FileUpdater, RustSearcher, Token, UpdateMode, UpdateStatus, Version, delete_dir_if_exists, delete_file_if_exists,
4-
try_rename_dir, try_rename_file,
3+
ErrAction, FileUpdater, RustSearcher, Token, UpdateMode, UpdateStatus, Version, delete_dir_if_exists,
4+
delete_file_if_exists, expect_action, try_rename_dir, try_rename_file, walk_dir_no_dot_or_target,
55
};
66
use rustc_lexer::TokenKind;
77
use std::ffi::OsString;
88
use std::fs;
99
use std::path::Path;
10-
use walkdir::WalkDir;
1110

1211
/// Runs the `rename_lint` command.
1312
///
@@ -133,17 +132,10 @@ pub fn rename(clippy_version: Version, old_name: &str, new_name: &str, uplift: b
133132
}
134133

135134
let mut update_fn = file_update_fn(old_name, new_name, mod_edit);
136-
for file in WalkDir::new(".").into_iter().filter_entry(|e| {
137-
// Skip traversing some of the larger directories.
138-
e.path()
139-
.as_os_str()
140-
.as_encoded_bytes()
141-
.get(2..)
142-
.is_none_or(|x| x != "target".as_bytes() && x != ".git".as_bytes())
143-
}) {
144-
let file = file.expect("error reading clippy directory");
145-
if file.path().as_os_str().as_encoded_bytes().ends_with(b".rs") {
146-
updater.update_file(file.path(), &mut update_fn);
135+
for e in walk_dir_no_dot_or_target() {
136+
let e = expect_action(e, ErrAction::Read, ".");
137+
if e.path().as_os_str().as_encoded_bytes().ends_with(b".rs") {
138+
updater.update_file(e.path(), &mut update_fn);
147139
}
148140
}
149141
generate_lint_files(UpdateMode::Change, &lints, &deprecated_lints, &renamed_lints);

0 commit comments

Comments
 (0)