Skip to content

Commit 0e42ba9

Browse files
committed
Permit specifying a non-default edition when linting file
`cargo dev lint /tmp/file.rs -- --edition 2021` will select edition 2021.
1 parent 8a9d550 commit 0e42ba9

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

clippy_dev/src/lint.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::utils::{cargo_clippy_path, exit_if_err};
22
use std::process::{self, Command};
33
use std::{env, fs};
44

5-
pub fn run<'a>(path: &str, args: impl Iterator<Item = &'a String>) {
5+
pub fn run<'a>(path: &str, edition: &str, args: impl Iterator<Item = &'a String>) {
66
let is_file = match fs::metadata(path) {
77
Ok(metadata) => metadata.is_file(),
88
Err(e) => {
@@ -17,7 +17,7 @@ pub fn run<'a>(path: &str, args: impl Iterator<Item = &'a String>) {
1717
.args(["run", "--bin", "clippy-driver", "--"])
1818
.args(["-L", "./target/debug"])
1919
.args(["-Z", "no-codegen"])
20-
.args(["--edition", "2024"])
20+
.args(["--edition", edition])
2121
.arg(path)
2222
.args(args)
2323
// Prevent rustc from creating `rustc-ice-*` files the console output is enough.

clippy_dev/src/main.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn main() {
6868
RemoveSubcommand::VscodeTasks => setup::vscode::remove_tasks(),
6969
},
7070
DevCommand::Serve { port, lint } => serve::run(port, lint),
71-
DevCommand::Lint { path, args } => lint::run(&path, args.iter()),
71+
DevCommand::Lint { path, edition, args } => lint::run(&path, &edition, args.iter()),
7272
DevCommand::RenameLint {
7373
old_name,
7474
new_name,
@@ -206,6 +206,9 @@ enum DevCommand {
206206
/// cargo dev lint file.rs -- -W clippy::pedantic {n}
207207
/// cargo dev lint ~/my-project -- -- -W clippy::pedantic
208208
Lint {
209+
/// The Rust edition to use
210+
#[arg(long, default_value = "2024")]
211+
edition: String,
209212
/// The path to a file or package directory to lint
210213
path: String,
211214
/// Pass extra arguments to cargo/clippy-driver

0 commit comments

Comments
 (0)