Skip to content

Commit

Permalink
Merge pull request #1585 from kinnison/kinnison/cargo-fmt
Browse files Browse the repository at this point in the history
Reformat the entire codebase using `cargo fmt`
  • Loading branch information
nrc authored Dec 26, 2018
2 parents 31935e5 + 7a8c953 commit 61f57bb
Show file tree
Hide file tree
Showing 57 changed files with 1,064 additions and 1,002 deletions.
19 changes: 10 additions & 9 deletions src/download/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ extern crate lazy_static;
#[cfg(feature = "reqwest-backend")]
extern crate reqwest;

use url::Url;
use std::path::Path;
use url::Url;

mod errors;
pub use crate::errors::*;
Expand Down Expand Up @@ -122,7 +122,7 @@ pub fn download_to_path_with_backend(

Ok(())
}()
.map_err(|e| {
.map_err(|e| {
// TODO is there any point clearing up here? What kind of errors will leave us with an unusable partial?
e
})
Expand All @@ -136,12 +136,12 @@ pub mod curl {
extern crate curl;

use self::curl::easy::Easy;
use super::Event;
use crate::errors::*;
use std::cell::RefCell;
use std::str;
use std::time::Duration;
use url::Url;
use super::Event;

pub fn download(url: &Url, resume_from: u64, callback: &Fn(Event) -> Result<()>) -> Result<()> {
// Fetch either a cached libcurl handle (which will preserve open
Expand Down Expand Up @@ -254,12 +254,12 @@ pub mod curl {
pub mod reqwest_be {
extern crate env_proxy;

use super::Event;
use crate::errors::*;
use reqwest::{header, Client, Proxy, Response};
use std::io;
use std::time::Duration;
use crate::errors::*;
use url::Url;
use super::Event;
use reqwest::{header, Client, Proxy, Response};

pub fn download(url: &Url, resume_from: u64, callback: &Fn(Event) -> Result<()>) -> Result<()> {
// Short-circuit reqwest for the "file:" URL scheme
Expand Down Expand Up @@ -339,7 +339,8 @@ pub mod reqwest_be {

// The file scheme is mostly for use by tests to mock the dist server
if url.scheme() == "file" {
let src = url.to_file_path()
let src = url
.to_file_path()
.map_err(|_| Error::from(format!("bogus file url: '{}'", url)))?;
if !src.is_file() {
// Because some of rustup's logic depends on checking
Expand Down Expand Up @@ -372,9 +373,9 @@ pub mod reqwest_be {
#[cfg(not(feature = "curl-backend"))]
pub mod curl {

use super::Event;
use errors::*;
use url::Url;
use super::Event;

pub fn download(
_url: &Url,
Expand All @@ -388,9 +389,9 @@ pub mod curl {
#[cfg(not(feature = "reqwest-backend"))]
pub mod reqwest_be {

use super::Event;
use errors::*;
use url::Url;
use super::Event;

pub fn download(
_url: &Url,
Expand Down
11 changes: 7 additions & 4 deletions src/download/tests/download-curl-resume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,17 @@ fn callback_gets_all_data_as_if_the_download_happened_all_at_once() {
assert!(flag.is_none());
*flag = Some(len);
}
Event::DownloadDataReceived(data) => for b in data.iter() {
received_in_callback.lock().unwrap().push(b.clone());
},
Event::DownloadDataReceived(data) => {
for b in data.iter() {
received_in_callback.lock().unwrap().push(b.clone());
}
}
}

Ok(())
}),
).expect("Test download failed");
)
.expect("Test download failed");

assert!(*callback_partial.lock().unwrap());
assert_eq!(*callback_len.lock().unwrap(), Some(5));
Expand Down
11 changes: 7 additions & 4 deletions src/download/tests/download-reqwest-resume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,17 @@ fn callback_gets_all_data_as_if_the_download_happened_all_at_once() {
assert!(flag.is_none());
*flag = Some(len);
}
Event::DownloadDataReceived(data) => for b in data.iter() {
received_in_callback.lock().unwrap().push(b.clone());
},
Event::DownloadDataReceived(data) => {
for b in data.iter() {
received_in_callback.lock().unwrap().push(b.clone());
}
}
}

Ok(())
}),
).expect("Test download failed");
)
.expect("Test download failed");

assert!(*callback_partial.lock().unwrap());
assert_eq!(*callback_len.lock().unwrap(), Some(5));
Expand Down
26 changes: 12 additions & 14 deletions src/rustup-cli/common.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
//! Just a dumping ground for cli stuff

use rustup::{self, Cfg, Notification, Toolchain, UpdateStatus};
use rustup::telemetry_analysis::TelemetryAnalysis;
use crate::errors::*;
use rustup_utils::utils;
use rustup_utils::notify::NotificationLevel;
use crate::self_update;
use crate::term2;
use rustup::telemetry_analysis::TelemetryAnalysis;
use rustup::{self, Cfg, Notification, Toolchain, UpdateStatus};
use rustup_utils::notify::NotificationLevel;
use rustup_utils::utils;
use std;
use std::io::{BufRead, BufReader, Write};
use std::process::{Command, Stdio};
use std::path::Path;
use std::{cmp, iter};
use std::process::{Command, Stdio};
use std::sync::Arc;
use std::time::Duration;
use std;
use crate::term2;
use std::{cmp, iter};
use wait_timeout::ChildExt;

pub fn confirm(question: &str, default: bool) -> Result<bool> {
Expand Down Expand Up @@ -178,7 +178,8 @@ fn show_channel_updates(
let mut t = term2::stdout();

let data: Vec<_> = data.collect();
let max_width = data.iter()
let max_width = data
.iter()
.fold(0, |a, &(_, _, width, _, _)| cmp::max(a, width));

for (name, banner, width, color, version) in data {
Expand Down Expand Up @@ -365,11 +366,8 @@ pub fn list_overrides(cfg: &Cfg) -> Result<()> {
}
println!(
"{:<40}\t{:<20}",
utils::format_path_for_display(&k) + if dir_exists {
""
} else {
" (not a directory)"
},
utils::format_path_for_display(&k)
+ if dir_exists { "" } else { " (not a directory)" },
v
)
}
Expand Down
11 changes: 6 additions & 5 deletions src/rustup-cli/download_tracker.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use rustup::Notification;
use rustup_dist::Notification as In;
use rustup_utils::tty;
use rustup_utils::Notification as Un;
use std::collections::VecDeque;
use std::fmt;
use term;
use time::precise_time_s;
use rustup::Notification;
use rustup_dist::Notification as In;
use rustup_utils::Notification as Un;
use rustup_utils::tty;

/// Keep track of this many past download amounts
const DOWNLOAD_TRACK_COUNT: usize = 5;
Expand Down Expand Up @@ -123,7 +123,8 @@ impl DownloadTracker {
/// Display the tracked download information to the terminal.
fn display(&mut self) {
let total_h = HumanReadable(self.total_downloaded as f64);
let sum = self.downloaded_last_few_secs
let sum = self
.downloaded_last_few_secs
.iter()
.fold(0., |a, &v| a + v as f64);
let len = self.downloaded_last_few_secs.len();
Expand Down
2 changes: 1 addition & 1 deletion src/rustup-cli/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ mod imp {
use self::winapi::um::handleapi::*;
use self::winapi::um::jobapi2::*;
use self::winapi::um::processthreadsapi::*;
use self::winapi::um::winnt::*;
use self::winapi::um::winnt::HANDLE;
use self::winapi::um::winnt::*;

pub struct Setup {
job: Handle,
Expand Down
22 changes: 12 additions & 10 deletions src/rustup-cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ extern crate winreg;
mod log;
mod common;
mod download_tracker;
mod errors;
mod help;
mod job;
mod proxy_mode;
mod setup_mode;
mod rustup_mode;
mod self_update;
mod job;
mod setup_mode;
mod term2;
mod errors;
mod help;

use crate::errors::*;
use rustup::env_var::RUST_RECURSION_COUNT_MAX;
use rustup_dist::dist::TargetTriple;
use std::alloc::System;
use std::env;
use std::path::PathBuf;
use crate::errors::*;
use rustup_dist::dist::TargetTriple;
use rustup::env_var::RUST_RECURSION_COUNT_MAX;

// Always use the system allocator, to reduce binary size.
#[global_allocator]
Expand All @@ -83,14 +83,16 @@ fn run_rustup() -> Result<()> {

// The name of arg0 determines how the program is going to behave
let arg0 = env::args().next().map(PathBuf::from);
let name = arg0.as_ref()
let name = arg0
.as_ref()
.and_then(|a| a.file_stem())
.and_then(|a| a.to_str());

match name {
Some("rustup") => rustup_mode::main(),
Some(n)
if n.starts_with("multirust-setup") || n.starts_with("rustup-setup")
if n.starts_with("multirust-setup")
|| n.starts_with("rustup-setup")
|| n.starts_with("rustup-init") =>
{
// NB: The above check is only for the prefix of the file
Expand Down Expand Up @@ -171,8 +173,8 @@ fn make_environment_compatible() {
// REG_SZ type, when it should be REG_EXPAND_SZ. Silently fix it.
#[cfg(windows)]
fn fix_windows_reg_key() {
use winreg::RegKey;
use winreg::enums::{RegType, HKEY_CURRENT_USER, KEY_READ, KEY_WRITE};
use winreg::RegKey;

let root = RegKey::predef(HKEY_CURRENT_USER);
let env = root.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE);
Expand Down
16 changes: 11 additions & 5 deletions src/rustup-cli/proxy_mode.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::common::set_globals;
use rustup::Cfg;
use crate::errors::*;
use rustup_utils::utils::{self, ExitCode};
use crate::job;
use rustup::command::run_command_for_dir;
use rustup::Cfg;
use rustup_utils::utils::{self, ExitCode};
use std::env;
use std::ffi::OsString;
use std::path::PathBuf;
use std::process;
use crate::job;

pub fn main() -> Result<()> {
crate::self_update::cleanup_self_updater()?;
Expand All @@ -18,7 +18,8 @@ pub fn main() -> Result<()> {
let mut args = env::args();

let arg0 = args.next().map(PathBuf::from);
let arg0 = arg0.as_ref()
let arg0 = arg0
.as_ref()
.and_then(|a| a.file_name())
.and_then(|a| a.to_str());
let ref arg0 = arg0.ok_or(ErrorKind::NoExeName)?;
Expand Down Expand Up @@ -48,7 +49,12 @@ pub fn main() -> Result<()> {
process::exit(c)
}

fn direct_proxy(cfg: &Cfg, arg0: &str, toolchain: Option<&str>, args: &[OsString]) -> Result<ExitCode> {
fn direct_proxy(
cfg: &Cfg,
arg0: &str,
toolchain: Option<&str>,
args: &[OsString],
) -> Result<ExitCode> {
let cmd = match toolchain {
None => cfg.create_command_for_dir(&utils::current_dir()?, arg0)?,
Some(tc) => cfg.create_command_for_toolchain(tc, false, arg0)?,
Expand Down
Loading

0 comments on commit 61f57bb

Please sign in to comment.