Skip to content

Commit 80d00be

Browse files
committed
More fixes
1 parent b9036a4 commit 80d00be

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

clippy_dev/src/update_lints.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,13 @@ pub fn rename(old_name: &str, new_name: &str, uplift: bool) {
245245
new_name
246246
);
247247
} else {
248-
// Rename the lint struct and the containing module if it shares the lint name across all files.
248+
// Rename the lint struct and source files sharing a name with the lint.
249249
let lint = &mut lints[old_lint_index];
250250
let old_name_upper = old_name.to_uppercase();
251251
let new_name_upper = new_name.to_uppercase();
252+
lint.name = new_name.into();
252253

254+
// Rename test files. only rename `.stderr` and `.fixed` files if the new test name doesn't exist.
253255
if try_rename_file(
254256
Path::new(&format!("tests/ui/{}.rs", old_name)),
255257
Path::new(&format!("tests/ui/{}.rs", new_name)),
@@ -264,30 +266,41 @@ pub fn rename(old_name: &str, new_name: &str, uplift: bool) {
264266
);
265267
}
266268

269+
// Try to rename the file containing the lint if the file name matches the lint's name.
267270
let replacements;
268-
let replacements = if lint.module == lint.name
271+
let replacements = if lint.module == old_name
269272
&& try_rename_file(
270273
Path::new(&format!("clippy_lints/src/{}.rs", old_name)),
271274
Path::new(&format!("clippy_lints/src/{}.rs", new_name)),
272275
) {
273-
lint.module = new_name.into();
276+
// Edit the module name in the lint list. Note there could be multiple lints.
277+
for lint in lints.iter_mut().filter(|l| l.module == old_name) {
278+
lint.module = new_name.into();
279+
}
274280
replacements = [(&*old_name_upper, &*new_name_upper), (old_name, new_name)];
275281
replacements.as_slice()
276282
} else if !lint.module.contains("::")
283+
// Catch cases like `methods/lint_name.rs` where the lint is stored in `methods/mod.rs`
277284
&& try_rename_file(
278285
Path::new(&format!("clippy_lints/src/{}/{}.rs", lint.module, old_name)),
279286
Path::new(&format!("clippy_lints/src/{}/{}.rs", lint.module, new_name)),
280287
)
281288
{
289+
// Edit the module name in the lint list. Note there could be multiple lints, or none.
290+
let renamed_mod = format!("{}::{}", lint.module, old_name);
291+
for lint in lints.iter_mut().filter(|l| l.module == renamed_mod) {
292+
lint.module = format!("{}::{}", lint.module, new_name);
293+
}
282294
replacements = [(&*old_name_upper, &*new_name_upper), (old_name, new_name)];
283295
replacements.as_slice()
284296
} else {
285297
replacements = [(&*old_name_upper, &*new_name_upper), ("", "")];
286298
&replacements[0..1]
287299
};
288-
lint.name = new_name.into();
289300

290-
for (_, file) in clippy_lints_src_files() {
301+
// Don't change `clippy_utils/src/renamed_lints.rs` here as it would try to edit the lint being
302+
// renamed.
303+
for (_, file) in clippy_lints_src_files().filter(|(rel_path, _)| rel_path != OsStr::new("renamed_lints.rs")) {
291304
rewrite_file(file.path(), |s| replace_ident_like(s, replacements));
292305
}
293306

0 commit comments

Comments
 (0)