Skip to content

Commit 00a00eb

Browse files
clippy_dev: Sort lint and lint pass declarations (parsing revamp part 5/N) (#15979)
Based on #15978 This will prevent some pointless merge conflict when multiple people add lints to the same lint pass (e.g. methods). changelog: None
2 parents 5a8a577 + e16c838 commit 00a00eb

File tree

231 files changed

+8804
-8225
lines changed

Some content is hidden

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

231 files changed

+8804
-8225
lines changed

clippy_dev/src/edit_lints.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::parse::cursor::{self, Capture, Cursor};
22
use crate::parse::{ActiveLint, DeprecatedLint, Lint, LintData, LintName, ParseCx, RenamedLint};
3-
use crate::update_lints::generate_lint_files;
43
use crate::utils::{
54
ErrAction, FileUpdater, UpdateMode, UpdateStatus, Version, delete_dir_if_exists, delete_file_if_exists,
65
expect_action, try_rename_dir, try_rename_file, walk_dir_no_dot_or_target,
@@ -40,7 +39,7 @@ pub fn deprecate<'cx, 'env: 'cx>(cx: ParseCx<'cx>, clippy_version: Version, name
4039
};
4140

4241
remove_lint_declaration(name, &prev_lint, &data, &mut FileUpdater::default());
43-
generate_lint_files(UpdateMode::Change, &data);
42+
data.gen_decls(UpdateMode::Change);
4443
println!("info: `{name}` has successfully been deprecated");
4544
println!("note: you must run `cargo uitest` to update the test results");
4645
}
@@ -74,7 +73,7 @@ pub fn uplift<'cx, 'env: 'cx>(cx: ParseCx<'cx>, clippy_version: Version, old_nam
7473
updater.update_file(e.path(), &mut update_fn);
7574
}
7675
}
77-
generate_lint_files(UpdateMode::Change, &data);
76+
data.gen_decls(UpdateMode::Change);
7877
println!("info: `{old_name}` has successfully been uplifted as `{new_name}`");
7978
println!("note: you must run `cargo uitest` to update the test results");
8079
}
@@ -151,7 +150,7 @@ pub fn rename<'cx, 'env: 'cx>(cx: ParseCx<'cx>, clippy_version: Version, old_nam
151150
updater.update_file(e.path(), &mut update_fn);
152151
}
153152
}
154-
generate_lint_files(UpdateMode::Change, &data);
153+
data.gen_decls(UpdateMode::Change);
155154

156155
println!("Renamed `{old_name}` to `{new_name}`");
157156
println!("All code referencing the old name has been updated");
@@ -172,11 +171,11 @@ fn remove_lint_declaration(name: &str, lint: &ActiveLint<'_>, data: &LintData<'_
172171
delete_file_if_exists(lint.path.as_ref())
173172
} else {
174173
updater.update_file(&lint.path, &mut |_, src, dst| -> UpdateStatus {
175-
let mut start = &src[..lint.declaration_range.start];
174+
let mut start = &src[..lint.declaration_range.start as usize];
176175
if start.ends_with("\n\n") {
177176
start = &start[..start.len() - 1];
178177
}
179-
let mut end = &src[lint.declaration_range.end..];
178+
let mut end = &src[lint.declaration_range.end as usize..];
180179
if end.starts_with("\n\n") {
181180
end = &end[1..];
182181
}

clippy_dev/src/fmt.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
use crate::generate::gen_sorted_lints_file;
2+
use crate::new_parse_cx;
3+
use crate::parse::VecBuf;
14
use crate::utils::{
25
ErrAction, FileUpdater, UpdateMode, UpdateStatus, expect_action, run_with_output, split_args_for_threads,
36
walk_dir_no_dot_or_target,
@@ -326,10 +329,35 @@ fn run_rustfmt(update_mode: UpdateMode) {
326329

327330
// the "main" function of cargo dev fmt
328331
pub fn run(update_mode: UpdateMode) {
329-
run_rustfmt(update_mode);
330332
fmt_syms(update_mode);
331333
if let Err(e) = fmt_conf(update_mode.is_check()) {
332334
e.display();
333335
process::exit(1);
334336
}
337+
338+
new_parse_cx(|cx| {
339+
let mut data = cx.parse_lint_decls();
340+
let (mut lints, passes) = data.split_by_lint_file();
341+
let mut updater = FileUpdater::default();
342+
let mut ranges = VecBuf::with_capacity(256);
343+
344+
for passes in passes {
345+
let path = passes[0].path.clone();
346+
let mut lints = lints.remove(&*path);
347+
let lints = lints.as_deref_mut().unwrap_or_default();
348+
updater.update_file_checked("cargo dev fmt", update_mode, &path, &mut |_, src, dst| {
349+
gen_sorted_lints_file(src, dst, lints, passes, &mut ranges);
350+
UpdateStatus::from_changed(src != dst)
351+
});
352+
}
353+
354+
for (&path, lints) in &mut lints {
355+
updater.update_file_checked("cargo dev fmt", update_mode, path, &mut |_, src, dst| {
356+
gen_sorted_lints_file(src, dst, lints, &mut [], &mut ranges);
357+
UpdateStatus::from_changed(src != dst)
358+
});
359+
}
360+
});
361+
362+
run_rustfmt(update_mode);
335363
}

0 commit comments

Comments
 (0)