Skip to content

Commit 9f73a90

Browse files
committed
do not run clippy for cargo clippy -- -W help #6122
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
1 parent c9fdeef commit 9f73a90

File tree

3 files changed

+133
-123
lines changed

3 files changed

+133
-123
lines changed

clippy_lints/src/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub fn lit_to_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
155155
match *lit {
156156
LitKind::Str(ref is, _) => Constant::Str(is.to_string()),
157157
LitKind::Byte(b) => Constant::Int(u128::from(b)),
158-
LitKind::ByteStr(ref s) => Constant::Binary(Lrc::from(s.as_slice())),
158+
LitKind::ByteStr(ref s) => Constant::Binary(Lrc::from(&s[..])),
159159
LitKind::Char(c) => Constant::Char(c),
160160
LitKind::Int(n, _) => Constant::Int(n),
161161
LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty {

src/driver.rs

-121
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
// FIXME: switch to something more ergonomic here, once available.
99
// (Currently there is no way to opt into sysroot crates without `extern crate`.)
10-
extern crate rustc_data_structures;
1110
extern crate rustc_driver;
1211
extern crate rustc_errors;
1312
extern crate rustc_interface;
@@ -25,8 +24,6 @@ use std::panic;
2524
use std::path::{Path, PathBuf};
2625
use std::process::{exit, Command};
2726

28-
mod lintlist;
29-
3027
/// If a command-line option matches `find_arg`, then apply the predicate `pred` on its value. If
3128
/// true, then return it. The parameter is assumed to be either `--arg=value` or `--arg value`.
3229
fn arg_value<'a, T: Deref<Target = str>>(
@@ -91,113 +88,6 @@ impl rustc_driver::Callbacks for ClippyCallbacks {
9188
}
9289
}
9390

94-
#[allow(clippy::find_map, clippy::filter_map)]
95-
fn describe_lints() {
96-
use lintlist::{Level, Lint, ALL_LINTS, LINT_LEVELS};
97-
use rustc_data_structures::fx::FxHashSet;
98-
99-
println!(
100-
"
101-
Available lint options:
102-
-W <foo> Warn about <foo>
103-
-A <foo> Allow <foo>
104-
-D <foo> Deny <foo>
105-
-F <foo> Forbid <foo> (deny <foo> and all attempts to override)
106-
107-
"
108-
);
109-
110-
let lint_level = |lint: &Lint| {
111-
LINT_LEVELS
112-
.iter()
113-
.find(|level_mapping| level_mapping.0 == lint.group)
114-
.map(|(_, level)| match level {
115-
Level::Allow => "allow",
116-
Level::Warn => "warn",
117-
Level::Deny => "deny",
118-
})
119-
.unwrap()
120-
};
121-
122-
let mut lints: Vec<_> = ALL_LINTS.iter().collect();
123-
// The sort doesn't case-fold but it's doubtful we care.
124-
lints.sort_by_cached_key(|x: &&Lint| (lint_level(x), x.name));
125-
126-
let max_lint_name_len = lints
127-
.iter()
128-
.map(|lint| lint.name.len())
129-
.map(|len| len + "clippy::".len())
130-
.max()
131-
.unwrap_or(0);
132-
133-
let padded = |x: &str| {
134-
let mut s = " ".repeat(max_lint_name_len - x.chars().count());
135-
s.push_str(x);
136-
s
137-
};
138-
139-
let scoped = |x: &str| format!("clippy::{}", x);
140-
141-
let lint_groups: FxHashSet<_> = lints.iter().map(|lint| lint.group).collect();
142-
143-
println!("Lint checks provided by clippy:\n");
144-
println!(" {} {:7.7} meaning", padded("name"), "default");
145-
println!(" {} {:7.7} -------", padded("----"), "-------");
146-
147-
let print_lints = |lints: &[&Lint]| {
148-
for lint in lints {
149-
let name = lint.name.replace("_", "-");
150-
println!(
151-
" {} {:7.7} {}",
152-
padded(&scoped(&name)),
153-
lint_level(lint),
154-
lint.desc
155-
);
156-
}
157-
println!("\n");
158-
};
159-
160-
print_lints(&lints);
161-
162-
let max_group_name_len = std::cmp::max(
163-
"clippy::all".len(),
164-
lint_groups
165-
.iter()
166-
.map(|group| group.len())
167-
.map(|len| len + "clippy::".len())
168-
.max()
169-
.unwrap_or(0),
170-
);
171-
172-
let padded_group = |x: &str| {
173-
let mut s = " ".repeat(max_group_name_len - x.chars().count());
174-
s.push_str(x);
175-
s
176-
};
177-
178-
println!("Lint groups provided by clippy:\n");
179-
println!(" {} sub-lints", padded_group("name"));
180-
println!(" {} ---------", padded_group("----"));
181-
println!(" {} the set of all clippy lints", padded_group("clippy::all"));
182-
183-
let print_lint_groups = || {
184-
for group in lint_groups {
185-
let name = group.to_lowercase().replace("_", "-");
186-
let desc = lints
187-
.iter()
188-
.filter(|&lint| lint.group == group)
189-
.map(|lint| lint.name)
190-
.map(|name| name.replace("_", "-"))
191-
.collect::<Vec<String>>()
192-
.join(", ");
193-
println!(" {} {}", padded_group(&scoped(&name)), desc);
194-
}
195-
println!("\n");
196-
};
197-
198-
print_lint_groups();
199-
}
200-
20191
fn display_help() {
20292
println!(
20393
"\
@@ -380,17 +270,6 @@ pub fn main() {
380270
exit(0);
381271
}
382272

383-
let should_describe_lints = || {
384-
let args: Vec<_> = env::args().collect();
385-
args.windows(2)
386-
.any(|args| args[1] == "help" && matches!(args[0].as_str(), "-W" | "-A" | "-D" | "-F"))
387-
};
388-
389-
if !wrapper_mode && should_describe_lints() {
390-
describe_lints();
391-
exit(0);
392-
}
393-
394273
// this conditional check for the --sysroot flag is there so users can call
395274
// `clippy_driver` directly
396275
// without having to pass --sysroot or anything

src/main.rs

+132-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
#![warn(rust_2018_idioms, unused_lifetimes)]
44

55
use rustc_tools_util::VersionInfo;
6-
use std::env;
6+
use std::{collections::HashSet, env, path::Path};
77
use std::ffi::OsString;
88
use std::path::PathBuf;
99
use std::process::{self, Command};
1010

11+
mod lintlist;
12+
1113
const CARGO_CLIPPY_HELP: &str = r#"Checks a package to catch common mistakes and improve your Rust code.
1214
1315
Usage:
@@ -53,6 +55,28 @@ pub fn main() {
5355
return;
5456
}
5557

58+
let mut orig_args: Vec<String> = env::args().collect();
59+
60+
// Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.
61+
// We're invoking the compiler programmatically, so we ignore this/
62+
let wrapper_mode = orig_args.get(1).map(Path::new).and_then(Path::file_stem) == Some("rustc".as_ref());
63+
64+
if wrapper_mode {
65+
// we still want to be able to invoke it normally though
66+
orig_args.remove(1);
67+
}
68+
69+
let should_describe_lints = || {
70+
let args: Vec<_> = env::args().collect();
71+
args.windows(2)
72+
.any(|args| args[1] == "help" && matches!(args[0].as_str(), "-W" | "-A" | "-D" | "-F"))
73+
};
74+
75+
if !wrapper_mode && should_describe_lints() {
76+
describe_lints();
77+
return;
78+
}
79+
5680
if let Err(code) = process(env::args().skip(2)) {
5781
process::exit(code);
5882
}
@@ -179,6 +203,113 @@ where
179203
}
180204
}
181205

206+
207+
#[allow(clippy::find_map, clippy::filter_map)]
208+
fn describe_lints() {
209+
use lintlist::{Level, Lint, ALL_LINTS, LINT_LEVELS};
210+
211+
println!(
212+
"
213+
Available lint options:
214+
-W <foo> Warn about <foo>
215+
-A <foo> Allow <foo>
216+
-D <foo> Deny <foo>
217+
-F <foo> Forbid <foo> (deny <foo> and all attempts to override)
218+
219+
"
220+
);
221+
222+
let lint_level = |lint: &Lint| {
223+
LINT_LEVELS
224+
.iter()
225+
.find(|level_mapping| level_mapping.0 == lint.group)
226+
.map(|(_, level)| match level {
227+
Level::Allow => "allow",
228+
Level::Warn => "warn",
229+
Level::Deny => "deny",
230+
})
231+
.unwrap()
232+
};
233+
234+
let mut lints: Vec<_> = ALL_LINTS.iter().collect();
235+
// The sort doesn't case-fold but it's doubtful we care.
236+
lints.sort_by_cached_key(|x: &&Lint| (lint_level(x), x.name));
237+
238+
let max_lint_name_len = lints
239+
.iter()
240+
.map(|lint| lint.name.len())
241+
.map(|len| len + "clippy::".len())
242+
.max()
243+
.unwrap_or(0);
244+
245+
let padded = |x: &str| {
246+
let mut s = " ".repeat(max_lint_name_len - x.chars().count());
247+
s.push_str(x);
248+
s
249+
};
250+
251+
let scoped = |x: &str| format!("clippy::{}", x);
252+
253+
let lint_groups: HashSet<_> = lints.iter().map(|lint| lint.group).collect();
254+
255+
println!("Lint checks provided by clippy:\n");
256+
println!(" {} {:7.7} meaning", padded("name"), "default");
257+
println!(" {} {:7.7} -------", padded("----"), "-------");
258+
259+
let print_lints = |lints: &[&Lint]| {
260+
for lint in lints {
261+
let name = lint.name.replace("_", "-");
262+
println!(
263+
" {} {:7.7} {}",
264+
padded(&scoped(&name)),
265+
lint_level(lint),
266+
lint.desc
267+
);
268+
}
269+
println!("\n");
270+
};
271+
272+
print_lints(&lints);
273+
274+
let max_group_name_len = std::cmp::max(
275+
"clippy::all".len(),
276+
lint_groups
277+
.iter()
278+
.map(|group| group.len())
279+
.map(|len| len + "clippy::".len())
280+
.max()
281+
.unwrap_or(0),
282+
);
283+
284+
let padded_group = |x: &str| {
285+
let mut s = " ".repeat(max_group_name_len - x.chars().count());
286+
s.push_str(x);
287+
s
288+
};
289+
290+
println!("Lint groups provided by clippy:\n");
291+
println!(" {} sub-lints", padded_group("name"));
292+
println!(" {} ---------", padded_group("----"));
293+
println!(" {} the set of all clippy lints", padded_group("clippy::all"));
294+
295+
let print_lint_groups = || {
296+
for group in lint_groups {
297+
let name = group.to_lowercase().replace("_", "-");
298+
let desc = lints
299+
.iter()
300+
.filter(|&lint| lint.group == group)
301+
.map(|lint| lint.name)
302+
.map(|name| name.replace("_", "-"))
303+
.collect::<Vec<String>>()
304+
.join(", ");
305+
println!(" {} {}", padded_group(&scoped(&name)), desc);
306+
}
307+
println!("\n");
308+
};
309+
310+
print_lint_groups();
311+
}
312+
182313
#[cfg(test)]
183314
mod tests {
184315
use super::ClippyCmd;

0 commit comments

Comments
 (0)