Skip to content
Open
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
54 changes: 53 additions & 1 deletion clippy_dev/src/deprecate_lint.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::parse::{DeprecatedLint, Lint, ParseCx};
use crate::parse::{DeprecatedLint, Lint, ParseCx, RenamedLint};
use crate::update_lints::generate_lint_files;
use crate::utils::{UpdateMode, Version};
use std::ffi::OsStr;
Expand Down Expand Up @@ -61,6 +61,58 @@ pub fn deprecate<'cx>(cx: ParseCx<'cx>, clippy_version: Version, name: &'cx str,
}
}

pub fn uplift<'cx, 'env: 'cx>(cx: ParseCx<'cx>, clippy_version: Version, old_name: &'env str, new_name: &'env str) {
let mut lints = cx.find_lint_decls();
let (deprecated_lints, mut renamed_lints) = cx.read_deprecated_lints();

let Some(lint) = lints.iter().find(|l| l.name == old_name) else {
eprintln!("error: failed to find lint `{old_name}`");
return;
};

let old_name_prefixed = cx.str_buf.with(|buf| {
buf.extend(["clippy::", old_name]);
cx.arena.alloc_str(buf)
});
for lint in &mut renamed_lints {
if lint.new_name == old_name_prefixed {
lint.new_name = new_name;
}
}
match renamed_lints.binary_search_by(|x| x.old_name.cmp(old_name_prefixed)) {
Ok(_) => {
println!("`{old_name}` is already deprecated");
return;
},
Err(idx) => renamed_lints.insert(
idx,
RenamedLint {
old_name: old_name_prefixed,
new_name,
version: cx.str_buf.alloc_display(cx.arena, clippy_version.rust_display()),
},
),
}

let mod_path = {
let mut mod_path = PathBuf::from(format!("clippy_lints/src/{}", lint.module));
if mod_path.is_dir() {
mod_path = mod_path.join("mod");
}

mod_path.set_extension("rs");
mod_path
};

if remove_lint_declaration(old_name, &mod_path, &mut lints).unwrap_or(false) {
generate_lint_files(UpdateMode::Change, &lints, &deprecated_lints, &renamed_lints);
println!("info: `{old_name}` has successfully been uplifted");
println!("note: you must run `cargo uitest` to update the test results");
} else {
eprintln!("error: lint not found");
}
}

fn remove_lint_declaration(name: &str, path: &Path, lints: &mut Vec<Lint<'_>>) -> io::Result<bool> {
fn remove_lint(name: &str, lints: &mut Vec<Lint<'_>>) {
lints.iter().position(|l| l.name == name).map(|pos| lints.remove(pos));
Expand Down
Loading