Skip to content

Commit f5e4a01

Browse files
committed
Update dev new_lint to add passes to each array.
1 parent 7176f3a commit f5e4a01

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
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);

clippy_lints/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ pub fn register_lint_passes(store: &mut rustc_lint::LintStore, conf: &'static Co
511511
Box::new(|| Box::new(byte_char_slices::ByteCharSlice)),
512512
Box::new(|| Box::new(cfg_not_test::CfgNotTest)),
513513
Box::new(|| Box::new(empty_line_after::EmptyLineAfter::new())),
514+
// add early passes here, used by `cargo dev new_lint`
514515
];
515516
store.early_passes.extend(early_lints);
516517

@@ -847,7 +848,7 @@ pub fn register_lint_passes(store: &mut rustc_lint::LintStore, conf: &'static Co
847848
Box::new(|_| Box::new(toplevel_ref_arg::ToplevelRefArg)),
848849
Box::new(|_| Box::new(volatile_composites::VolatileComposites)),
849850
Box::new(|_| Box::new(replace_box::ReplaceBox)),
851+
// add late passes here, used by `cargo dev new_lint`
850852
];
851853
store.late_passes.extend(late_lints);
852-
// add lints here, do not remove this comment, it's used in `new_lint`
853854
}

0 commit comments

Comments
 (0)