Skip to content

Commit c48592e

Browse files
authored
Use extend when creating the lint pass constructors (#15994)
Alternative to part of #14509. changelog: none
2 parents f1c7461 + 2027c0e commit c48592e

File tree

2 files changed

+414
-382
lines changed

2 files changed

+414
-382
lines changed

clippy_dev/src/new_lint.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,19 @@ fn add_lint(lint: &LintData<'_>, enable_msrv: bool) -> io::Result<()> {
157157
let path = "clippy_lints/src/lib.rs";
158158
let mut lib_rs = fs::read_to_string(path).context("reading")?;
159159

160-
let comment_start = lib_rs.find("// add lints here,").expect("Couldn't find comment");
161-
let ctor_arg = if lint.pass == Pass::Late { "_" } else { "" };
162-
let lint_pass = lint.pass;
160+
let (comment, ctor_arg) = if lint.pass == Pass::Late {
161+
("// add late passes here", "_")
162+
} else {
163+
("// add early passes here", "")
164+
};
165+
let comment_start = lib_rs.find(comment).expect("Couldn't find comment");
163166
let module_name = lint.name;
164167
let camel_name = to_camel_case(lint.name);
165168

166169
let new_lint = if enable_msrv {
167-
format!(
168-
"store.register_{lint_pass}_pass(move |{ctor_arg}| Box::new({module_name}::{camel_name}::new(conf)));\n ",
169-
)
170+
format!("Box::new(move |{ctor_arg}| Box::new({module_name}::{camel_name}::new(conf))),\n ",)
170171
} else {
171-
format!("store.register_{lint_pass}_pass(|{ctor_arg}| Box::new({module_name}::{camel_name}));\n ",)
172+
format!("Box::new(|{ctor_arg}| Box::new({module_name}::{camel_name})),\n ",)
172173
};
173174

174175
lib_rs.insert_str(comment_start, &new_lint);

0 commit comments

Comments
 (0)