Skip to content

Commit 4ee141e

Browse files
authored
Merge pull request #2457 from rbtcollins/clippy
Fix all outstanding lints and document expectations
2 parents d3bb61a + 9e260c4 commit 4ee141e

17 files changed

+87
-60
lines changed

CONTRIBUTING.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
1. Fork it!
44
2. Create your feature branch: `git checkout -b my-new-feature`
5-
3. Commit your changes: `git commit -am 'Add some feature'`
6-
4. Push to the branch: `git push origin my-new-feature`
7-
5. Submit a pull request :D
5+
3. Test it: `cargo test`
6+
4. Lint it: `cargo +nightly clippy --all-targets -- -D warnings`
7+
5. Commit your changes: `git commit -am 'Add some feature'`
8+
6. Push to the branch: `git push origin my-new-feature`
9+
7. Submit a pull request :D
810

911
For developing on `rustup` itself, you may want to install into a temporary
1012
directory, with a series of commands similar to this:
@@ -60,6 +62,34 @@ The `rustup::currentprocess` module abstracts the global state that is
6062
`std::env::current_dir` and `std::process::exit` permitting threaded tests of
6163
the CLI logic; use `process()` rather than those APIs directly.
6264

65+
### Clippy lints
66+
67+
We do not enforce lint status in the checks done by GitHub Actions, because
68+
clippy is a moving target that can make it hard to merge for little benefit.
69+
70+
We do ask that contributors keep the clippy status clean themselves.
71+
72+
Minimally, run `cargo +nightly clippy --all-targets -- -D warnings` before
73+
submitting code.
74+
75+
Regular contributors or contributors to particularly OS-specific code should
76+
also make sure that their clippy checking is done on at least Linux and Windows,
77+
as OS-conditional code is a common source of unused imports and other small
78+
lints, which can build up over time.
79+
80+
For developers using BSD/Linux/Mac OS, there are Windows VM's suitable for such
81+
development tasks for use with virtualbox and other hypervisors are downloadable
82+
from
83+
[Microsoft](https://developer.microsoft.com/en-us/windows/downloads/virtual-machines/).
84+
Similarly, there are many Linux and Unix operating systems images available for
85+
developers whose usual operating system is Windows. Currently Rustup has no Mac
86+
OS specific code, so there should be no need to worry about Mac VM images.
87+
88+
Clippy is also run in GitHub Actions, in the 'General Checks / Checks` build
89+
task, but not currently run per-platform, which means there is no way to find
90+
out the status of clippy per platform without running it on that platform as a
91+
developer.
92+
6393
## Version numbers
6494

6595
If you ever see a released version of rustup which has `::` in its version string

src/cli/common.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ fn show_channel_updates(
183183
) -> Result<()> {
184184
let data = toolchains.into_iter().map(|(name, result)| {
185185
let toolchain = cfg.get_toolchain(&name, false).unwrap();
186-
let mut version: String = toolchain.rustc_version().into();
186+
let mut version: String = toolchain.rustc_version();
187187

188188
let banner;
189189
let color;
@@ -486,12 +486,12 @@ pub fn list_toolchains(cfg: &Cfg, verbose: bool) -> Result<utils::ExitCode> {
486486
String::new()
487487
};
488488
for toolchain in toolchains {
489-
let if_default = if def_toolchain_name == &*toolchain {
489+
let if_default = if def_toolchain_name == *toolchain {
490490
" (default)"
491491
} else {
492492
""
493493
};
494-
let if_override = if ovr_toolchain_name == &*toolchain {
494+
let if_override = if ovr_toolchain_name == *toolchain {
495495
" (override)"
496496
} else {
497497
""

src/cli/self_update.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,7 @@ info: default host triple is {0}
11491149
vars,
11501150
..Default::default()
11511151
});
1152-
currentprocess::with(tp.clone(), || -> anyhow::Result<()> {
1152+
currentprocess::with(tp, || -> anyhow::Result<()> {
11531153
super::install_bins().unwrap();
11541154
Ok(())
11551155
})

src/cli/self_update/windows.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ fn get_windows_path_var() -> Result<Option<String>> {
214214
} else {
215215
warn!("the registry key HKEY_CURRENT_USER\\Environment\\PATH does not contain valid Unicode. \
216216
Not modifying the PATH variable");
217-
return Ok(None);
217+
Ok(None)
218218
}
219219
}
220220
Err(ref e) if e.kind() == io::ErrorKind::NotFound => Ok(Some(String::new())),
@@ -230,7 +230,7 @@ fn _add_to_path(old_path: &str, path_str: String) -> Option<String> {
230230
} else if old_path.contains(&path_str) {
231231
None
232232
} else {
233-
let mut new_path = path_str.clone();
233+
let mut new_path = path_str;
234234
new_path.push_str(";");
235235
new_path.push_str(&old_path);
236236
Some(new_path)
@@ -471,8 +471,11 @@ mod tests {
471471
.unwrap();
472472
environment.delete_value("PATH").unwrap();
473473

474-
assert_eq!((), super::_apply_new_path(Some("foo".into())).unwrap());
475-
474+
{
475+
// Can't compare the Results as Eq isn't derived; thanks error-chain.
476+
#![allow(clippy::unit_cmp)]
477+
assert_eq!((), super::_apply_new_path(Some("foo".into())).unwrap());
478+
}
476479
let root = RegKey::predef(HKEY_CURRENT_USER);
477480
let environment = root
478481
.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE)
@@ -506,8 +509,11 @@ mod tests {
506509
)
507510
.unwrap();
508511

509-
assert_eq!((), super::_apply_new_path(Some("".into())).unwrap());
510-
512+
{
513+
// Can't compare the Results as Eq isn't derived; thanks error-chain.
514+
#![allow(clippy::unit_cmp)]
515+
assert_eq!((), super::_apply_new_path(Some("".into())).unwrap());
516+
}
511517
let reg_value = environment.get_raw_value("PATH");
512518
match reg_value {
513519
Ok(_) => panic!("key not deleted"),

src/cli/setup_mode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub fn main() -> Result<utils::ExitCode> {
101101
writeln!(process().stdout().lock(), "{}", e.message)?;
102102
return Ok(utils::ExitCode(0));
103103
}
104-
Err(e) => Err(e)?,
104+
Err(e) => return Err(e.into()),
105105
};
106106
let no_prompt = matches.is_present("no-prompt");
107107
let verbose = matches.is_present("verbose");

src/cli/term2.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,26 +76,26 @@ mod termhack {
7676
/// opened.
7777
#[allow(unused)]
7878
pub fn stdout(terminfo: Option<TermInfo>) -> Option<Box<StdoutTerminal>> {
79-
make_terminal(terminfo, || io::stdout())
79+
make_terminal(terminfo, io::stdout)
8080
}
8181

8282
/// Return a Terminal wrapping stderr, or None if a terminal couldn't be
8383
/// opened.
8484
#[allow(unused)]
8585
pub fn stderr(terminfo: Option<TermInfo>) -> Option<Box<StderrTerminal>> {
86-
make_terminal(terminfo, || io::stderr())
86+
make_terminal(terminfo, io::stderr)
8787
}
8888

8989
/// Return a Terminal wrapping stdout.
9090
#[allow(unused)]
9191
pub fn stdout_with_fallback(terminfo: Option<TermInfo>) -> Box<StdoutTerminal> {
92-
make_terminal_with_fallback(terminfo, || io::stdout())
92+
make_terminal_with_fallback(terminfo, io::stdout)
9393
}
9494

9595
/// Return a Terminal wrapping stderr.
9696
#[allow(unused)]
9797
pub fn stderr_with_fallback(terminfo: Option<TermInfo>) -> Box<StderrTerminal> {
98-
make_terminal_with_fallback(terminfo, || io::stderr())
98+
make_terminal_with_fallback(terminfo, io::stderr)
9999
}
100100
}
101101

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ impl Cfg {
585585
let contents = contents.as_ref();
586586

587587
match contents.lines().count() {
588-
0 => return Err(ErrorKind::EmptyOverrideFile.into()),
588+
0 => Err(ErrorKind::EmptyOverrideFile.into()),
589589
1 => {
590590
let channel = contents.trim();
591591

src/currentprocess.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ where
147147
});
148148

149149
PROCESS.with(|p| {
150-
if let Some(_) = *p.borrow() {
151-
panic!("current process already set {}");
150+
if let Some(old_p) = &*p.borrow() {
151+
panic!("current process already set {:?}", old_p);
152152
}
153153
*p.borrow_mut() = Some(process);
154154
let result = f();

src/dist/manifest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ impl TargetedPackage {
440440
if !extensions.is_empty() {
441441
result.insert("extensions".to_owned(), toml::Value::Array(extensions));
442442
}
443-
if let Some(bins) = self.bins.clone() {
443+
if let Some(bins) = self.bins {
444444
result.insert("hash".to_owned(), toml::Value::String(bins.hash));
445445
result.insert("url".to_owned(), toml::Value::String(bins.url));
446446
if let (Some(xz_hash), Some(xz_url)) = (bins.xz_hash, bins.xz_url) {

src/dist/notifications.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl<'a> Display for Notification<'a> {
182182
.iter()
183183
.map(|component| {
184184
if component.target.as_ref() != Some(&toolchain.target) {
185-
component.name_in_manifest().to_owned()
185+
component.name_in_manifest()
186186
} else {
187187
component.short_name_in_manifest().to_owned()
188188
}

0 commit comments

Comments
 (0)