Skip to content

Commit 84860ee

Browse files
committed
Update dev new_lint to add passes to each array.
1 parent f984f27 commit 84860ee

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

clippy_dev/src/new_lint.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,21 @@ 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 {
167170
format!(
168-
"store.register_{lint_pass}_pass(move |{ctor_arg}| Box::new({module_name}::{camel_name}::new(conf)));\n ",
171+
"Box::new(move |{ctor_arg}| Box::new({module_name}::{camel_name}::new(conf))),\n ",
169172
)
170173
} else {
171-
format!("store.register_{lint_pass}_pass(|{ctor_arg}| Box::new({module_name}::{camel_name}));\n ",)
174+
format!("Box::new(|{ctor_arg}| Box::new({module_name}::{camel_name})),\n ",)
172175
};
173176

174177
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

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

0 commit comments

Comments
 (0)