Skip to content

Commit 30da772

Browse files
committed
fix clippy help text, check for clippy-driver
1 parent a05afe4 commit 30da772

File tree

4 files changed

+42
-23
lines changed

4 files changed

+42
-23
lines changed

src/bin/cargo/commands/clippy.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub fn cli() -> App {
66
subcommand("clippy-preview")
77
// subcommand aliases are handled in aliased_command()
88
// .alias("c")
9-
.about("Check a local package and all of its dependencies for errors")
9+
.about("Checks a package to catch common mistakes and improve your Rust code.")
1010
.arg_package_spec(
1111
"Package(s) to check",
1212
"Check all packages in the workspace",
@@ -49,6 +49,18 @@ the `--release` flag will use the `release` profile instead.
4949
5050
The `--profile test` flag can be used to check unit tests with the
5151
`#[cfg(test)]` attribute.
52+
53+
To allow or deny a lint from the command line you can use `cargo clippy --`
54+
with:
55+
56+
-W --warn OPT Set lint warnings
57+
-A --allow OPT Set lint allowed
58+
-D --deny OPT Set lint denied
59+
-F --forbid OPT Set lint forbidden
60+
61+
You can use tool lints to allow or deny lints from your code, eg.:
62+
63+
#[allow(clippy::needless_lifetimes)]
5264
",
5365
)
5466
}

src/bin/cargo/main.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
use std::collections::BTreeSet;
88
use std::env;
99
use std::fs;
10-
use std::path::{Path, PathBuf};
10+
use std::path::PathBuf;
1111

1212
use cargo::core::shell::Shell;
13+
use cargo::util::paths::is_executable;
1314
use cargo::util::{self, command_prelude, lev_distance, CargoResult, CliResult, Config};
1415
use cargo::util::{CliError, ProcessError};
1516

@@ -164,20 +165,6 @@ fn execute_external_subcommand(config: &Config, cmd: &str, args: &[&str]) -> Cli
164165
Err(CliError::new(err, 101))
165166
}
166167

167-
#[cfg(unix)]
168-
fn is_executable<P: AsRef<Path>>(path: P) -> bool {
169-
use std::os::unix::prelude::*;
170-
fs::metadata(path)
171-
.map(|metadata| metadata.is_file() && metadata.permissions().mode() & 0o111 != 0)
172-
.unwrap_or(false)
173-
}
174-
#[cfg(windows)]
175-
fn is_executable<P: AsRef<Path>>(path: P) -> bool {
176-
fs::metadata(path)
177-
.map(|metadata| metadata.is_file())
178-
.unwrap_or(false)
179-
}
180-
181168
fn search_directories(config: &Config) -> Vec<PathBuf> {
182169
let mut dirs = vec![config.home().clone().into_path_unlocked().join("bin")];
183170
if let Some(val) = env::var_os("PATH") {

src/cargo/util/config.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use serde::Deserialize;
2020
use serde::{de, de::IntoDeserializer};
2121
use url::Url;
2222

23+
use self::ConfigValue as CV;
2324
use crate::core::profiles::ConfigProfiles;
2425
use crate::core::shell::Verbosity;
2526
use crate::core::{CliUnstable, Shell, SourceId, Workspace};
@@ -30,7 +31,6 @@ use crate::util::Filesystem;
3031
use crate::util::Rustc;
3132
use crate::util::ToUrl;
3233
use crate::util::{paths, validate_package_name};
33-
use self::ConfigValue as CV;
3434

3535
/// Configuration information for cargo. This is not specific to a build, it is information
3636
/// relating to cargo itself.
@@ -206,7 +206,16 @@ impl Config {
206206
.into_path_unlocked()
207207
});
208208
let wrapper = if self.clippy_override {
209-
Some(self.get_tool("clippy-driver")?)
209+
let tool = self.get_tool("clippy-driver")?;
210+
let tool = paths::resolve_executable(&tool).map_err(|e| {
211+
failure::format_err!("{}: please run `rustup component add clippy`", e)
212+
})?;
213+
if !paths::is_executable(&tool) {
214+
return Err(failure::format_err!(
215+
"found file for `clippy-driver` but its not an executable. what the heck is going on !? please run `rustup component add clippy`"
216+
));
217+
}
218+
Some(tool)
210219
} else {
211220
self.maybe_get_tool("rustc-wrapper")?
212221
};
@@ -407,6 +416,7 @@ impl Config {
407416
match self.get_env(key)? {
408417
Some(v) => Ok(Some(v)),
409418
None => {
419+
// println!("{:#?}", self);
410420
let config_key = key.to_config();
411421
let o_cv = self.get_cv(&config_key)?;
412422
match o_cv {
@@ -756,17 +766,14 @@ impl Config {
756766
} else {
757767
PathBuf::from(tool_path)
758768
};
759-
println!("some tool {}", tool);
760769
return Ok(Some(path));
761770
}
762771

763772
let var = format!("build.{}", tool);
764773
if let Some(tool_path) = self.get_path(&var)? {
765-
println!("some tool {}", tool);
766774
return Ok(Some(tool_path.val));
767775
}
768776

769-
println!("NO TOOL {}", tool);
770777
Ok(None)
771778
}
772779

@@ -940,8 +947,7 @@ impl ConfigError {
940947
}
941948
}
942949

943-
impl std::error::Error for ConfigError {
944-
}
950+
impl std::error::Error for ConfigError {}
945951

946952
// Future note: currently, we cannot override `Fail::cause` (due to
947953
// specialization) so we have no way to return the underlying causes. In the

src/cargo/util/paths.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ pub fn normalize_path(path: &Path) -> PathBuf {
8989
ret
9090
}
9191

92+
#[cfg(unix)]
93+
pub fn is_executable<P: AsRef<Path>>(path: P) -> bool {
94+
use std::os::unix::prelude::*;
95+
fs::metadata(path)
96+
.map(|metadata| metadata.is_file() && metadata.permissions().mode() & 0o111 != 0)
97+
.unwrap_or(false)
98+
}
99+
#[cfg(windows)]
100+
pub fn is_executable<P: AsRef<Path>>(path: P) -> bool {
101+
fs::metadata(path)
102+
.map(|metadata| metadata.is_file())
103+
.unwrap_or(false)
104+
}
105+
92106
pub fn resolve_executable(exec: &Path) -> CargoResult<PathBuf> {
93107
if exec.components().count() == 1 {
94108
let paths = env::var_os("PATH").ok_or_else(|| failure::format_err!("no PATH"))?;

0 commit comments

Comments
 (0)