Skip to content

Commit c80ca2c

Browse files
committed
Auto merge of #8997 - Jarcho:clap_deprecate, r=flip1995
Fix `clap` deprecation warnings Clap `3.2.0` deprecated a few functions used by lintcheck. changelog: None
2 parents 17b7ab0 + cccc750 commit c80ca2c

File tree

5 files changed

+120
-167
lines changed

5 files changed

+120
-167
lines changed

clippy_dev/src/lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn exit_if_err(status: io::Result<ExitStatus>) {
1313
}
1414
}
1515

16-
pub fn run<'a>(path: &str, args: impl Iterator<Item = &'a str>) {
16+
pub fn run<'a>(path: &str, args: impl Iterator<Item = &'a String>) {
1717
let is_file = match fs::metadata(path) {
1818
Ok(metadata) => metadata.is_file(),
1919
Err(e) => {

clippy_dev/src/main.rs

+88-124
Original file line numberDiff line numberDiff line change
@@ -2,63 +2,63 @@
22
// warn on lints, that are included in `rust-lang/rust`s bootstrap
33
#![warn(rust_2018_idioms, unused_lifetimes)]
44

5-
use clap::{Arg, ArgMatches, Command};
5+
use clap::{Arg, ArgAction, ArgMatches, Command, PossibleValue};
66
use clippy_dev::{bless, fmt, lint, new_lint, serve, setup, update_lints};
77
use indoc::indoc;
88
fn main() {
99
let matches = get_clap_config();
1010

1111
match matches.subcommand() {
1212
Some(("bless", matches)) => {
13-
bless::bless(matches.is_present("ignore-timestamp"));
13+
bless::bless(matches.contains_id("ignore-timestamp"));
1414
},
1515
Some(("fmt", matches)) => {
16-
fmt::run(matches.is_present("check"), matches.is_present("verbose"));
16+
fmt::run(matches.contains_id("check"), matches.contains_id("verbose"));
1717
},
1818
Some(("update_lints", matches)) => {
19-
if matches.is_present("print-only") {
19+
if matches.contains_id("print-only") {
2020
update_lints::print_lints();
21-
} else if matches.is_present("check") {
21+
} else if matches.contains_id("check") {
2222
update_lints::update(update_lints::UpdateMode::Check);
2323
} else {
2424
update_lints::update(update_lints::UpdateMode::Change);
2525
}
2626
},
2727
Some(("new_lint", matches)) => {
2828
match new_lint::create(
29-
matches.value_of("pass"),
30-
matches.value_of("name"),
31-
matches.value_of("category"),
32-
matches.is_present("msrv"),
29+
matches.get_one::<String>("pass"),
30+
matches.get_one::<String>("name"),
31+
matches.get_one::<String>("category"),
32+
matches.contains_id("msrv"),
3333
) {
3434
Ok(_) => update_lints::update(update_lints::UpdateMode::Change),
3535
Err(e) => eprintln!("Unable to create lint: {}", e),
3636
}
3737
},
3838
Some(("setup", sub_command)) => match sub_command.subcommand() {
3939
Some(("intellij", matches)) => {
40-
if matches.is_present("remove") {
40+
if matches.contains_id("remove") {
4141
setup::intellij::remove_rustc_src();
4242
} else {
4343
setup::intellij::setup_rustc_src(
4444
matches
45-
.value_of("rustc-repo-path")
45+
.get_one::<String>("rustc-repo-path")
4646
.expect("this field is mandatory and therefore always valid"),
4747
);
4848
}
4949
},
5050
Some(("git-hook", matches)) => {
51-
if matches.is_present("remove") {
51+
if matches.contains_id("remove") {
5252
setup::git_hook::remove_hook();
5353
} else {
54-
setup::git_hook::install_hook(matches.is_present("force-override"));
54+
setup::git_hook::install_hook(matches.contains_id("force-override"));
5555
}
5656
},
5757
Some(("vscode-tasks", matches)) => {
58-
if matches.is_present("remove") {
58+
if matches.contains_id("remove") {
5959
setup::vscode::remove_tasks();
6060
} else {
61-
setup::vscode::install_tasks(matches.is_present("force-override"));
61+
setup::vscode::install_tasks(matches.contains_id("force-override"));
6262
}
6363
},
6464
_ => {},
@@ -70,19 +70,19 @@ fn main() {
7070
_ => {},
7171
},
7272
Some(("serve", matches)) => {
73-
let port = matches.value_of("port").unwrap().parse().unwrap();
74-
let lint = matches.value_of("lint");
73+
let port = *matches.get_one::<u16>("port").unwrap();
74+
let lint = matches.get_one::<String>("lint");
7575
serve::run(port, lint);
7676
},
7777
Some(("lint", matches)) => {
78-
let path = matches.value_of("path").unwrap();
79-
let args = matches.values_of("args").into_iter().flatten();
78+
let path = matches.get_one::<String>("path").unwrap();
79+
let args = matches.get_many::<String>("args").into_iter().flatten();
8080
lint::run(path, args);
8181
},
8282
Some(("rename_lint", matches)) => {
83-
let old_name = matches.value_of("old_name").unwrap();
84-
let new_name = matches.value_of("new_name").unwrap_or(old_name);
85-
let uplift = matches.is_present("uplift");
83+
let old_name = matches.get_one::<String>("old_name").unwrap();
84+
let new_name = matches.get_one::<String>("new_name").unwrap_or(old_name);
85+
let uplift = matches.contains_id("uplift");
8686
update_lints::rename(old_name, new_name, uplift);
8787
},
8888
_ => {},
@@ -92,98 +92,86 @@ fn main() {
9292
fn get_clap_config() -> ArgMatches {
9393
Command::new("Clippy developer tooling")
9494
.arg_required_else_help(true)
95-
.subcommand(
95+
.subcommands([
9696
Command::new("bless").about("bless the test output changes").arg(
9797
Arg::new("ignore-timestamp")
9898
.long("ignore-timestamp")
9999
.help("Include files updated before clippy was built"),
100100
),
101-
)
102-
.subcommand(
103101
Command::new("fmt")
104102
.about("Run rustfmt on all projects and tests")
105-
.arg(Arg::new("check").long("check").help("Use the rustfmt --check option"))
106-
.arg(Arg::new("verbose").short('v').long("verbose").help("Echo commands run")),
107-
)
108-
.subcommand(
103+
.args([
104+
Arg::new("check").long("check").help("Use the rustfmt --check option"),
105+
Arg::new("verbose").short('v').long("verbose").help("Echo commands run"),
106+
]),
109107
Command::new("update_lints")
110108
.about("Updates lint registration and information from the source code")
111109
.long_about(
112110
"Makes sure that:\n \
113-
* the lint count in README.md is correct\n \
114-
* the changelog contains markdown link references at the bottom\n \
115-
* all lint groups include the correct lints\n \
116-
* lint modules in `clippy_lints/*` are visible in `src/lib.rs` via `pub mod`\n \
117-
* all lints are registered in the lint store",
111+
* the lint count in README.md is correct\n \
112+
* the changelog contains markdown link references at the bottom\n \
113+
* all lint groups include the correct lints\n \
114+
* lint modules in `clippy_lints/*` are visible in `src/lib.rs` via `pub mod`\n \
115+
* all lints are registered in the lint store",
118116
)
119-
.arg(Arg::new("print-only").long("print-only").help(
120-
"Print a table of lints to STDOUT. \
121-
This does not include deprecated and internal lints. \
122-
(Does not modify any files)",
123-
))
124-
.arg(
117+
.args([
118+
Arg::new("print-only").long("print-only").help(
119+
"Print a table of lints to STDOUT. \
120+
This does not include deprecated and internal lints. \
121+
(Does not modify any files)",
122+
),
125123
Arg::new("check")
126124
.long("check")
127125
.help("Checks that `cargo dev update_lints` has been run. Used on CI."),
128-
),
129-
)
130-
.subcommand(
126+
]),
131127
Command::new("new_lint")
132128
.about("Create new lint and run `cargo dev update_lints`")
133-
.arg(
129+
.args([
134130
Arg::new("pass")
135131
.short('p')
136132
.long("pass")
137133
.help("Specify whether the lint runs during the early or late pass")
138134
.takes_value(true)
139-
.possible_values(&["early", "late"])
135+
.value_parser([PossibleValue::new("early"), PossibleValue::new("late")])
140136
.required(true),
141-
)
142-
.arg(
143137
Arg::new("name")
144138
.short('n')
145139
.long("name")
146140
.help("Name of the new lint in snake case, ex: fn_too_long")
147141
.takes_value(true)
148142
.required(true),
149-
)
150-
.arg(
151143
Arg::new("category")
152144
.short('c')
153145
.long("category")
154146
.help("What category the lint belongs to")
155147
.default_value("nursery")
156-
.possible_values(&[
157-
"style",
158-
"correctness",
159-
"suspicious",
160-
"complexity",
161-
"perf",
162-
"pedantic",
163-
"restriction",
164-
"cargo",
165-
"nursery",
166-
"internal",
167-
"internal_warn",
148+
.value_parser([
149+
PossibleValue::new("style"),
150+
PossibleValue::new("correctness"),
151+
PossibleValue::new("suspicious"),
152+
PossibleValue::new("complexity"),
153+
PossibleValue::new("perf"),
154+
PossibleValue::new("pedantic"),
155+
PossibleValue::new("restriction"),
156+
PossibleValue::new("cargo"),
157+
PossibleValue::new("nursery"),
158+
PossibleValue::new("internal"),
159+
PossibleValue::new("internal_warn"),
168160
])
169161
.takes_value(true),
170-
)
171-
.arg(Arg::new("msrv").long("msrv").help("Add MSRV config code to the lint")),
172-
)
173-
.subcommand(
162+
Arg::new("msrv").long("msrv").help("Add MSRV config code to the lint"),
163+
]),
174164
Command::new("setup")
175165
.about("Support for setting up your personal development environment")
176166
.arg_required_else_help(true)
177-
.subcommand(
167+
.subcommands([
178168
Command::new("intellij")
179169
.about("Alter dependencies so Intellij Rust can find rustc internals")
180-
.arg(
170+
.args([
181171
Arg::new("remove")
182172
.long("remove")
183173
.help("Remove the dependencies added with 'cargo dev setup intellij'")
184174
.required(false),
185-
)
186-
.arg(
187175
Arg::new("rustc-repo-path")
188176
.long("repo-path")
189177
.short('r')
@@ -192,67 +180,53 @@ fn get_clap_config() -> ArgMatches {
192180
.value_name("path")
193181
.conflicts_with("remove")
194182
.required(true),
195-
),
196-
)
197-
.subcommand(
183+
]),
198184
Command::new("git-hook")
199185
.about("Add a pre-commit git hook that formats your code to make it look pretty")
200-
.arg(
186+
.args([
201187
Arg::new("remove")
202188
.long("remove")
203189
.help("Remove the pre-commit hook added with 'cargo dev setup git-hook'")
204190
.required(false),
205-
)
206-
.arg(
207191
Arg::new("force-override")
208192
.long("force-override")
209193
.short('f')
210194
.help("Forces the override of an existing git pre-commit hook")
211195
.required(false),
212-
),
213-
)
214-
.subcommand(
196+
]),
215197
Command::new("vscode-tasks")
216198
.about("Add several tasks to vscode for formatting, validation and testing")
217-
.arg(
199+
.args([
218200
Arg::new("remove")
219201
.long("remove")
220202
.help("Remove the tasks added with 'cargo dev setup vscode-tasks'")
221203
.required(false),
222-
)
223-
.arg(
224204
Arg::new("force-override")
225205
.long("force-override")
226206
.short('f')
227207
.help("Forces the override of existing vscode tasks")
228208
.required(false),
229-
),
230-
),
231-
)
232-
.subcommand(
209+
]),
210+
]),
233211
Command::new("remove")
234212
.about("Support for undoing changes done by the setup command")
235213
.arg_required_else_help(true)
236-
.subcommand(Command::new("git-hook").about("Remove any existing pre-commit git hook"))
237-
.subcommand(Command::new("vscode-tasks").about("Remove any existing vscode tasks"))
238-
.subcommand(
214+
.subcommands([
215+
Command::new("git-hook").about("Remove any existing pre-commit git hook"),
216+
Command::new("vscode-tasks").about("Remove any existing vscode tasks"),
239217
Command::new("intellij").about("Removes rustc source paths added via `cargo dev setup intellij`"),
240-
),
241-
)
242-
.subcommand(
218+
]),
243219
Command::new("serve")
244220
.about("Launch a local 'ALL the Clippy Lints' website in a browser")
245-
.arg(
221+
.args([
246222
Arg::new("port")
247223
.long("port")
248224
.short('p')
249225
.help("Local port for the http server")
250226
.default_value("8000")
251-
.validator_os(serve::validate_port),
252-
)
253-
.arg(Arg::new("lint").help("Which lint's page to load initially (optional)")),
254-
)
255-
.subcommand(
227+
.value_parser(clap::value_parser!(u16)),
228+
Arg::new("lint").help("Which lint's page to load initially (optional)"),
229+
]),
256230
Command::new("lint")
257231
.about("Manually run clippy on a file or package")
258232
.after_help(indoc! {"
@@ -271,37 +245,27 @@ fn get_clap_config() -> ArgMatches {
271245
cargo dev lint file.rs -- -W clippy::pedantic
272246
cargo dev lint ~/my-project -- -- -W clippy::pedantic
273247
"})
274-
.arg(
248+
.args([
275249
Arg::new("path")
276250
.required(true)
277251
.help("The path to a file or package directory to lint"),
278-
)
279-
.arg(
280252
Arg::new("args")
281-
.multiple_occurrences(true)
253+
.action(ArgAction::Append)
282254
.help("Pass extra arguments to cargo/clippy-driver"),
283-
),
284-
)
285-
.subcommand(
286-
Command::new("rename_lint")
287-
.about("Renames the given lint")
288-
.arg(
289-
Arg::new("old_name")
290-
.index(1)
291-
.required(true)
292-
.help("The name of the lint to rename"),
293-
)
294-
.arg(
295-
Arg::new("new_name")
296-
.index(2)
297-
.required_unless_present("uplift")
298-
.help("The new name of the lint"),
299-
)
300-
.arg(
301-
Arg::new("uplift")
302-
.long("uplift")
303-
.help("This lint will be uplifted into rustc"),
304-
),
305-
)
255+
]),
256+
Command::new("rename_lint").about("Renames the given lint").args([
257+
Arg::new("old_name")
258+
.index(1)
259+
.required(true)
260+
.help("The name of the lint to rename"),
261+
Arg::new("new_name")
262+
.index(2)
263+
.required_unless_present("uplift")
264+
.help("The new name of the lint"),
265+
Arg::new("uplift")
266+
.long("uplift")
267+
.help("This lint will be uplifted into rustc"),
268+
]),
269+
])
306270
.get_matches()
307271
}

clippy_dev/src/new_lint.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ impl<T> Context for io::Result<T> {
3434
/// # Errors
3535
///
3636
/// This function errors out if the files couldn't be created or written to.
37-
pub fn create(pass: Option<&str>, lint_name: Option<&str>, category: Option<&str>, msrv: bool) -> io::Result<()> {
37+
pub fn create(
38+
pass: Option<&String>,
39+
lint_name: Option<&String>,
40+
category: Option<&String>,
41+
msrv: bool,
42+
) -> io::Result<()> {
3843
let lint = LintData {
3944
pass: pass.expect("`pass` argument is validated by clap"),
4045
name: lint_name.expect("`name` argument is validated by clap"),

0 commit comments

Comments
 (0)