Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions clippy_dev/src/edit_lints.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::parse::cursor::{self, Capture, Cursor};
use crate::parse::{ActiveLint, DeprecatedLint, Lint, LintData, LintName, ParseCx, RenamedLint};
use crate::update_lints::generate_lint_files;
use crate::utils::{
ErrAction, FileUpdater, UpdateMode, UpdateStatus, Version, delete_dir_if_exists, delete_file_if_exists,
expect_action, try_rename_dir, try_rename_file, walk_dir_no_dot_or_target,
Expand Down Expand Up @@ -40,7 +39,7 @@ pub fn deprecate<'cx, 'env: 'cx>(cx: ParseCx<'cx>, clippy_version: Version, name
};

remove_lint_declaration(name, &prev_lint, &data, &mut FileUpdater::default());
generate_lint_files(UpdateMode::Change, &data);
data.gen_decls(UpdateMode::Change);
println!("info: `{name}` has successfully been deprecated");
println!("note: you must run `cargo uitest` to update the test results");
}
Expand Down Expand Up @@ -74,7 +73,7 @@ pub fn uplift<'cx, 'env: 'cx>(cx: ParseCx<'cx>, clippy_version: Version, old_nam
updater.update_file(e.path(), &mut update_fn);
}
}
generate_lint_files(UpdateMode::Change, &data);
data.gen_decls(UpdateMode::Change);
println!("info: `{old_name}` has successfully been uplifted as `{new_name}`");
println!("note: you must run `cargo uitest` to update the test results");
}
Expand Down Expand Up @@ -151,7 +150,7 @@ pub fn rename<'cx, 'env: 'cx>(cx: ParseCx<'cx>, clippy_version: Version, old_nam
updater.update_file(e.path(), &mut update_fn);
}
}
generate_lint_files(UpdateMode::Change, &data);
data.gen_decls(UpdateMode::Change);

println!("Renamed `{old_name}` to `{new_name}`");
println!("All code referencing the old name has been updated");
Expand All @@ -172,11 +171,11 @@ fn remove_lint_declaration(name: &str, lint: &ActiveLint<'_>, data: &LintData<'_
delete_file_if_exists(lint.path.as_ref())
} else {
updater.update_file(&lint.path, &mut |_, src, dst| -> UpdateStatus {
let mut start = &src[..lint.declaration_range.start];
let mut start = &src[..lint.declaration_range.start as usize];
if start.ends_with("\n\n") {
start = &start[..start.len() - 1];
}
let mut end = &src[lint.declaration_range.end..];
let mut end = &src[lint.declaration_range.end as usize..];
if end.starts_with("\n\n") {
end = &end[1..];
}
Expand Down
30 changes: 29 additions & 1 deletion clippy_dev/src/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use crate::generate::gen_sorted_lints_file;
use crate::new_parse_cx;
use crate::parse::VecBuf;
use crate::utils::{
ErrAction, FileUpdater, UpdateMode, UpdateStatus, expect_action, run_with_output, split_args_for_threads,
walk_dir_no_dot_or_target,
Expand Down Expand Up @@ -326,10 +329,35 @@ fn run_rustfmt(update_mode: UpdateMode) {

// the "main" function of cargo dev fmt
pub fn run(update_mode: UpdateMode) {
run_rustfmt(update_mode);
fmt_syms(update_mode);
if let Err(e) = fmt_conf(update_mode.is_check()) {
e.display();
process::exit(1);
}

new_parse_cx(|cx| {
let mut data = cx.parse_lint_decls();
let (mut lints, passes) = data.split_by_lint_file();
let mut updater = FileUpdater::default();
let mut ranges = VecBuf::with_capacity(256);

for passes in passes {
let path = passes[0].path.clone();
let mut lints = lints.remove(&*path);
let lints = lints.as_deref_mut().unwrap_or_default();
updater.update_file_checked("cargo dev fmt", update_mode, &path, &mut |_, src, dst| {
gen_sorted_lints_file(src, dst, lints, passes, &mut ranges);
UpdateStatus::from_changed(src != dst)
});
}

for (&path, lints) in &mut lints {
updater.update_file_checked("cargo dev fmt", update_mode, path, &mut |_, src, dst| {
gen_sorted_lints_file(src, dst, lints, &mut [], &mut ranges);
UpdateStatus::from_changed(src != dst)
});
}
});

run_rustfmt(update_mode);
}
Loading