diff --git a/Cargo.lock b/Cargo.lock index ee75fe7271..2befa241c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1021,7 +1021,7 @@ dependencies = [ "mime 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "mime_guess 2.0.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", "native-tls 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)", "serde_urlencoded 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1064,7 +1064,7 @@ dependencies = [ "rustup-utils 1.16.0", "same-file 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1221,8 +1221,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde" -version = "1.0.79" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "serde_derive" @@ -1241,7 +1244,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1251,7 +1254,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "dtoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1584,7 +1587,7 @@ name = "toml" version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1925,7 +1928,7 @@ dependencies = [ "checksum security-framework-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab01dfbe5756785b5b4d46e0289e5a18071dfa9a7c2b24213ea00b9ef9b665bf" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -"checksum serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)" = "84257ccd054dc351472528c8587b4de2dbf0dc0fe2e634030c1a90bfdacebaa9" +"checksum serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)" = "2e20fde37801e83c891a2dc4ebd3b81f0da4d1fb67a9e0a2a3b921e2536a58ee" "checksum serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)" = "31569d901045afbff7a9479f793177fe9259819aff10ab4f89ef69bbc5f567fe" "checksum serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)" = "43344e7ce05d0d8280c5940cabb4964bea626aa58b1ec0e8c73fa2a8512a38ce" "checksum serde_urlencoded 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "aaed41d9fb1e2f587201b863356590c90c1157495d811430a0c0325fe8169650" diff --git a/Cargo.toml b/Cargo.toml index 53f9874536..ac6aa1f47d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,7 +46,7 @@ regex = "1.0.1" remove_dir_all = "0.5.1" same-file = "1.0" scopeguard = "0.3" -serde = "1.0" +serde = { version = "1.0.87", features = ['derive'] } serde_derive = "1.0" serde_json = "1.0" sha2 = "0.7.0" diff --git a/src/download/src/errors.rs b/src/download/src/errors.rs index f1a228a1c3..1f8f4be2b5 100644 --- a/src/download/src/errors.rs +++ b/src/download/src/errors.rs @@ -1,3 +1,7 @@ +use error_chain::error_chain; +use error_chain::error_chain_processing; +use error_chain::{impl_error_chain_kind, impl_error_chain_processed, impl_extract_backtrace}; + error_chain! { links { } diff --git a/src/download/src/lib.rs b/src/download/src/lib.rs index 9c99277a44..5c24862384 100644 --- a/src/download/src/lib.rs +++ b/src/download/src/lib.rs @@ -1,15 +1,5 @@ //! Easy file downloading -#[macro_use] -extern crate error_chain; -extern crate url; - -#[cfg(feature = "reqwest-backend")] -#[macro_use] -extern crate lazy_static; -#[cfg(feature = "reqwest-backend")] -extern crate reqwest; - use std::path::Path; use url::Url; @@ -35,7 +25,7 @@ fn download_with_backend( backend: Backend, url: &Url, resume_from: u64, - callback: &Fn(Event) -> Result<()>, + callback: &dyn Fn(Event<'_>) -> Result<()>, ) -> Result<()> { match backend { Backend::Curl => curl::download(url, resume_from, callback), @@ -48,7 +38,7 @@ pub fn download_to_path_with_backend( url: &Url, path: &Path, resume_from_partial: bool, - callback: Option<&Fn(Event) -> Result<()>>, + callback: Option<&dyn Fn(Event<'_>) -> Result<()>>, ) -> Result<()> { use std::cell::RefCell; use std::fs::OpenOptions; @@ -133,7 +123,7 @@ pub fn download_to_path_with_backend( #[cfg(feature = "curl-backend")] pub mod curl { - extern crate curl; + use curl; use self::curl::easy::Easy; use super::Event; @@ -143,7 +133,11 @@ pub mod curl { use std::time::Duration; use url::Url; - pub fn download(url: &Url, resume_from: u64, callback: &Fn(Event) -> Result<()>) -> Result<()> { + pub fn download( + url: &Url, + resume_from: u64, + callback: &dyn Fn(Event<'_>) -> Result<()>, + ) -> Result<()> { // Fetch either a cached libcurl handle (which will preserve open // connections) or create a new one if it isn't listed. // @@ -239,7 +233,7 @@ pub mod curl { .response_code() .chain_err(|| "failed to get response code")?; match code { - 0 | 200...299 => {} + 0 | 200..=299 => {} _ => { return Err(ErrorKind::HttpStatus(code).into()); } @@ -252,16 +246,19 @@ pub mod curl { #[cfg(feature = "reqwest-backend")] pub mod reqwest_be { - extern crate env_proxy; - use super::Event; use crate::errors::*; + use lazy_static::lazy_static; use reqwest::{header, Client, Proxy, Response}; use std::io; use std::time::Duration; use url::Url; - pub fn download(url: &Url, resume_from: u64, callback: &Fn(Event) -> Result<()>) -> Result<()> { + pub fn download( + url: &Url, + resume_from: u64, + callback: &dyn Fn(Event<'_>) -> Result<()>, + ) -> Result<()> { // Short-circuit reqwest for the "file:" URL scheme if download_from_file_url(url, resume_from, callback)? { return Ok(()); @@ -316,7 +313,7 @@ pub mod reqwest_be { } fn env_proxy(url: &Url) -> Option { - env_proxy::for_url(url).to_url() + ::env_proxy::for_url(url).to_url() } fn request(url: &Url, resume_from: u64) -> ::reqwest::Result { @@ -332,7 +329,7 @@ pub mod reqwest_be { fn download_from_file_url( url: &Url, resume_from: u64, - callback: &Fn(Event) -> Result<()>, + callback: &dyn Fn(Event<'_>) -> Result<()>, ) -> Result { use std::fs; use std::io; diff --git a/src/download/tests/download-curl-resume.rs b/src/download/tests/download-curl-resume.rs index a31b3c672f..a61defd804 100644 --- a/src/download/tests/download-curl-resume.rs +++ b/src/download/tests/download-curl-resume.rs @@ -1,8 +1,5 @@ #![cfg(feature = "curl-backend")] -extern crate download; -extern crate url; - use std::sync::Mutex; use url::Url; diff --git a/src/download/tests/download-reqwest-resume.rs b/src/download/tests/download-reqwest-resume.rs index 6967b9c6b5..38feb6ad34 100644 --- a/src/download/tests/download-reqwest-resume.rs +++ b/src/download/tests/download-reqwest-resume.rs @@ -1,8 +1,5 @@ #![cfg(feature = "reqwest-backend")] -extern crate download; -extern crate url; - use std::sync::Mutex; use url::Url; diff --git a/src/download/tests/support/mod.rs b/src/download/tests/support/mod.rs index 143ce2b508..256f3772cb 100644 --- a/src/download/tests/support/mod.rs +++ b/src/download/tests/support/mod.rs @@ -1,14 +1,10 @@ -extern crate futures; -extern crate hyper; -extern crate tempdir; - use std::fs::{self, File}; use std::io::{self, Read}; use std::net::SocketAddr; use std::path::Path; -use self::futures::sync::oneshot; -use self::tempdir::TempDir; +use futures::sync::oneshot; +use tempdir::TempDir; pub fn tmp_dir() -> TempDir { TempDir::new("rustup-download-test-").expect("creating tempdir for test") @@ -37,7 +33,7 @@ pub fn write_file(path: &Path, contents: &str) { } pub fn serve_file(contents: Vec) -> SocketAddr { - use self::futures::Future; + use futures::Future; use std::thread; let addr = ([127, 0, 0, 1], 0).into(); diff --git a/src/rustup-cli/common.rs b/src/rustup-cli/common.rs index 0b167ccef4..8b0eb5169a 100644 --- a/src/rustup-cli/common.rs +++ b/src/rustup-cli/common.rs @@ -4,10 +4,9 @@ use crate::errors::*; use crate::self_update; use crate::term2; use rustup::telemetry_analysis::TelemetryAnalysis; -use rustup::{self, Cfg, Notification, Toolchain, UpdateStatus}; +use rustup::{Cfg, Notification, Toolchain, UpdateStatus}; use rustup_utils::notify::NotificationLevel; use rustup_utils::utils; -use std; use std::io::{BufRead, BufReader, Write}; use std::path::Path; use std::process::{Command, Stdio}; @@ -109,7 +108,7 @@ pub fn set_globals(verbose: bool) -> Result { let download_tracker = RefCell::new(DownloadTracker::new()); - Ok(Cfg::from_env(Arc::new(move |n: Notification| { + Ok(Cfg::from_env(Arc::new(move |n: Notification<'_>| { if download_tracker.borrow_mut().handle_notification(&n) { return; } @@ -243,7 +242,7 @@ where Ok(()) } -pub fn rustc_version(toolchain: &Toolchain) -> String { +pub fn rustc_version(toolchain: &Toolchain<'_>) -> String { if toolchain.exists() { let rustc_path = toolchain.binary_file("rustc"); if utils::is_file(&rustc_path) { @@ -294,7 +293,7 @@ pub fn rustc_version(toolchain: &Toolchain) -> String { } } -pub fn list_targets(toolchain: &Toolchain) -> Result<()> { +pub fn list_targets(toolchain: &Toolchain<'_>) -> Result<()> { let mut t = term2::stdout(); for component in toolchain.list_components()? { if component.component.short_name_in_manifest() == "rust-std" { @@ -320,7 +319,7 @@ pub fn list_targets(toolchain: &Toolchain) -> Result<()> { Ok(()) } -pub fn list_components(toolchain: &Toolchain) -> Result<()> { +pub fn list_components(toolchain: &Toolchain<'_>) -> Result<()> { let mut t = term2::stdout(); for component in toolchain.list_components()? { let name = component.name; diff --git a/src/rustup-cli/download_tracker.rs b/src/rustup-cli/download_tracker.rs index 8ef9f3c096..510c8e0561 100644 --- a/src/rustup-cli/download_tracker.rs +++ b/src/rustup-cli/download_tracker.rs @@ -4,7 +4,6 @@ use rustup_utils::tty; use rustup_utils::Notification as Un; use std::collections::VecDeque; use std::fmt; -use term; use time::precise_time_s; /// Keep track of this many past download amounts @@ -50,7 +49,7 @@ impl DownloadTracker { } } - pub fn handle_notification(&mut self, n: &Notification) -> bool { + pub fn handle_notification(&mut self, n: &Notification<'_>) -> bool { match *n { Notification::Install(In::Utils(Un::DownloadContentLengthReceived(content_len))) => { self.content_length_received(content_len); @@ -170,7 +169,7 @@ impl DownloadTracker { struct HumanReadable(f64); impl fmt::Display for HumanReadable { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if f.alternate() { // repurposing the alternate mode for ETA let sec = self.0; diff --git a/src/rustup-cli/errors.rs b/src/rustup-cli/errors.rs index 38e7ecc1dd..79a0ad461d 100644 --- a/src/rustup-cli/errors.rs +++ b/src/rustup-cli/errors.rs @@ -3,9 +3,10 @@ use std::io; use std::path::PathBuf; -use rustup; -use rustup_dist::{self, temp}; -use rustup_utils; +use error_chain::error_chain; +use error_chain::error_chain_processing; +use error_chain::{impl_error_chain_kind, impl_error_chain_processed, impl_extract_backtrace}; +use rustup_dist::temp; error_chain! { links { diff --git a/src/rustup-cli/job.rs b/src/rustup-cli/job.rs index b47c582e91..d5a16b2679 100644 --- a/src/rustup-cli/job.rs +++ b/src/rustup-cli/job.rs @@ -34,18 +34,16 @@ mod imp { #[cfg(windows)] mod imp { - extern crate winapi; - use std::io; use std::mem; use std::ptr; - use self::winapi::shared::minwindef::*; - use self::winapi::um::handleapi::*; - use self::winapi::um::jobapi2::*; - use self::winapi::um::processthreadsapi::*; - use self::winapi::um::winnt::HANDLE; - use self::winapi::um::winnt::*; + use winapi::shared::minwindef::*; + use winapi::um::handleapi::*; + use winapi::um::jobapi2::*; + use winapi::um::processthreadsapi::*; + use winapi::um::winnt::HANDLE; + use winapi::um::winnt::*; pub struct Setup { job: Handle, diff --git a/src/rustup-cli/log.rs b/src/rustup-cli/log.rs index 016f9c8ebe..2b8b0f0391 100644 --- a/src/rustup-cli/log.rs +++ b/src/rustup-cli/log.rs @@ -20,7 +20,7 @@ macro_rules! debug { ( $ ( $ arg : tt ) * ) => ( $crate::log::debug_fmt ( format_args ! ( $ ( $ arg ) * ) ) ) } -pub fn warn_fmt(args: fmt::Arguments) { +pub fn warn_fmt(args: fmt::Arguments<'_>) { let mut t = term2::stderr(); let _ = t.fg(term2::color::BRIGHT_YELLOW); let _ = t.attr(term2::Attr::Bold); @@ -30,7 +30,7 @@ pub fn warn_fmt(args: fmt::Arguments) { let _ = write!(t, "\n"); } -pub fn err_fmt(args: fmt::Arguments) { +pub fn err_fmt(args: fmt::Arguments<'_>) { let mut t = term2::stderr(); let _ = t.fg(term2::color::BRIGHT_RED); let _ = t.attr(term2::Attr::Bold); @@ -40,7 +40,7 @@ pub fn err_fmt(args: fmt::Arguments) { let _ = write!(t, "\n"); } -pub fn info_fmt(args: fmt::Arguments) { +pub fn info_fmt(args: fmt::Arguments<'_>) { let mut t = term2::stderr(); let _ = t.attr(term2::Attr::Bold); let _ = write!(t, "info: "); @@ -49,7 +49,7 @@ pub fn info_fmt(args: fmt::Arguments) { let _ = write!(t, "\n"); } -pub fn verbose_fmt(args: fmt::Arguments) { +pub fn verbose_fmt(args: fmt::Arguments<'_>) { let mut t = term2::stderr(); let _ = t.fg(term2::color::BRIGHT_MAGENTA); let _ = t.attr(term2::Attr::Bold); @@ -59,7 +59,7 @@ pub fn verbose_fmt(args: fmt::Arguments) { let _ = write!(t, "\n"); } -pub fn debug_fmt(args: fmt::Arguments) { +pub fn debug_fmt(args: fmt::Arguments<'_>) { if std::env::var("RUSTUP_DEBUG").is_ok() { let mut t = term2::stderr(); let _ = t.fg(term2::color::BRIGHT_BLUE); diff --git a/src/rustup-cli/main.rs b/src/rustup-cli/main.rs index ad2fb7b1cd..f1533e89f4 100644 --- a/src/rustup-cli/main.rs +++ b/src/rustup-cli/main.rs @@ -14,34 +14,6 @@ #![recursion_limit = "1024"] -#[macro_use] -extern crate error_chain; -extern crate rustup_dist; -extern crate rustup_utils; - -extern crate clap; -extern crate itertools; -extern crate markdown; -extern crate rand; -extern crate regex; -extern crate rustup; -extern crate same_file; -extern crate scopeguard; -extern crate sha2; -extern crate tempdir; -extern crate term; -extern crate time; -extern crate toml; -extern crate wait_timeout; - -#[cfg(windows)] -extern crate gcc; -extern crate libc; -#[cfg(windows)] -extern crate winapi; -#[cfg(windows)] -extern crate winreg; - #[macro_use] mod log; mod common; diff --git a/src/rustup-cli/rustup_mode.rs b/src/rustup-cli/rustup_mode.rs index afdfca8740..17a38ddbf4 100644 --- a/src/rustup-cli/rustup_mode.rs +++ b/src/rustup-cli/rustup_mode.rs @@ -483,7 +483,7 @@ pub fn cli() -> App<'static, 'static> { ) } -fn maybe_upgrade_data(cfg: &Cfg, m: &ArgMatches) -> Result { +fn maybe_upgrade_data(cfg: &Cfg, m: &ArgMatches<'_>) -> Result { match m.subcommand() { ("self", Some(c)) => match c.subcommand() { ("upgrade-data", Some(_)) => { @@ -571,7 +571,7 @@ fn default_bare_triple_check(cfg: &Cfg, name: &str) -> Result<()> { Ok(()) } -fn default_(cfg: &Cfg, m: &ArgMatches) -> Result<()> { +fn default_(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { let ref toolchain = m.value_of("toolchain").expect(""); default_bare_triple_check(cfg, toolchain)?; let ref toolchain = cfg.get_toolchain(toolchain, false)?; @@ -594,7 +594,7 @@ fn default_(cfg: &Cfg, m: &ArgMatches) -> Result<()> { Ok(()) } -fn update(cfg: &Cfg, m: &ArgMatches) -> Result<()> { +fn update(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { let self_update = !m.is_present("no-self-update") && !self_update::NEVER_SELF_UPDATE; if let Some(names) = m.values_of("toolchain") { for name in names { @@ -624,7 +624,7 @@ fn update(cfg: &Cfg, m: &ArgMatches) -> Result<()> { Ok(()) } -fn run(cfg: &Cfg, m: &ArgMatches) -> Result<()> { +fn run(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { let ref toolchain = m.value_of("toolchain").expect(""); let args = m.values_of("command").unwrap(); let args: Vec<_> = args.collect(); @@ -635,7 +635,7 @@ fn run(cfg: &Cfg, m: &ArgMatches) -> Result<()> { process::exit(c) } -fn which(cfg: &Cfg, m: &ArgMatches) -> Result<()> { +fn which(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { let binary = m.value_of("command").expect(""); let binary_path = cfg @@ -790,13 +790,13 @@ fn show_active_toolchain(cfg: &Cfg) -> Result<()> { Ok(()) } -fn target_list(cfg: &Cfg, m: &ArgMatches) -> Result<()> { +fn target_list(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { let toolchain = explicit_or_dir_toolchain(cfg, m)?; common::list_targets(&toolchain) } -fn target_add(cfg: &Cfg, m: &ArgMatches) -> Result<()> { +fn target_add(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { let toolchain = explicit_or_dir_toolchain(cfg, m)?; for target in m.values_of("target").expect("") { @@ -809,7 +809,7 @@ fn target_add(cfg: &Cfg, m: &ArgMatches) -> Result<()> { Ok(()) } -fn target_remove(cfg: &Cfg, m: &ArgMatches) -> Result<()> { +fn target_remove(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { let toolchain = explicit_or_dir_toolchain(cfg, m)?; for target in m.values_of("target").expect("") { @@ -822,13 +822,13 @@ fn target_remove(cfg: &Cfg, m: &ArgMatches) -> Result<()> { Ok(()) } -fn component_list(cfg: &Cfg, m: &ArgMatches) -> Result<()> { +fn component_list(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { let toolchain = explicit_or_dir_toolchain(cfg, m)?; common::list_components(&toolchain) } -fn component_add(cfg: &Cfg, m: &ArgMatches) -> Result<()> { +fn component_add(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { let toolchain = explicit_or_dir_toolchain(cfg, m)?; let target = m .value_of("target") @@ -850,7 +850,7 @@ fn component_add(cfg: &Cfg, m: &ArgMatches) -> Result<()> { Ok(()) } -fn component_remove(cfg: &Cfg, m: &ArgMatches) -> Result<()> { +fn component_remove(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { let toolchain = explicit_or_dir_toolchain(cfg, m)?; let target = m .value_of("target") @@ -872,7 +872,7 @@ fn component_remove(cfg: &Cfg, m: &ArgMatches) -> Result<()> { Ok(()) } -fn explicit_or_dir_toolchain<'a>(cfg: &'a Cfg, m: &ArgMatches) -> Result> { +fn explicit_or_dir_toolchain<'a>(cfg: &'a Cfg, m: &ArgMatches<'_>) -> Result> { let toolchain = m.value_of("toolchain"); if let Some(toolchain) = toolchain { let toolchain = cfg.get_toolchain(toolchain, false)?; @@ -885,7 +885,7 @@ fn explicit_or_dir_toolchain<'a>(cfg: &'a Cfg, m: &ArgMatches) -> Result Result<()> { +fn toolchain_link(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { let ref toolchain = m.value_of("toolchain").expect(""); let ref path = m.value_of("path").expect(""); let toolchain = cfg.get_toolchain(toolchain, true)?; @@ -893,7 +893,7 @@ fn toolchain_link(cfg: &Cfg, m: &ArgMatches) -> Result<()> { Ok(toolchain.install_from_dir(Path::new(path), true)?) } -fn toolchain_remove(cfg: &Cfg, m: &ArgMatches) -> Result<()> { +fn toolchain_remove(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { for toolchain in m.values_of("toolchain").expect("") { let toolchain = cfg.get_toolchain(toolchain, false)?; toolchain.remove()?; @@ -901,7 +901,7 @@ fn toolchain_remove(cfg: &Cfg, m: &ArgMatches) -> Result<()> { Ok(()) } -fn override_add(cfg: &Cfg, m: &ArgMatches) -> Result<()> { +fn override_add(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { let ref toolchain = m.value_of("toolchain").expect(""); let toolchain = cfg.get_toolchain(toolchain, false)?; @@ -923,7 +923,7 @@ fn override_add(cfg: &Cfg, m: &ArgMatches) -> Result<()> { Ok(()) } -fn override_remove(cfg: &Cfg, m: &ArgMatches) -> Result<()> { +fn override_remove(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { let paths = if m.is_present("nonexistent") { let list: Vec<_> = cfg.settings_file.with(|s| { Ok(s.overrides @@ -987,7 +987,7 @@ const DOCS_DATA: &[(&'static str, &'static str, &'static str,)] = &[ ("unstable-book", "The Unstable Book", "unstable-book/index.html"), ]; -fn doc(cfg: &Cfg, m: &ArgMatches) -> Result<()> { +fn doc(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { let toolchain = explicit_or_dir_toolchain(cfg, m)?; let doc_url = if let Some((_, _, path)) = DOCS_DATA @@ -1008,7 +1008,7 @@ fn doc(cfg: &Cfg, m: &ArgMatches) -> Result<()> { } } -fn man(cfg: &Cfg, m: &ArgMatches) -> Result<()> { +fn man(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { let manpage = m.value_of("command").expect(""); let toolchain = explicit_or_dir_toolchain(cfg, m)?; let mut man_path = toolchain.path().to_path_buf(); @@ -1024,7 +1024,7 @@ fn man(cfg: &Cfg, m: &ArgMatches) -> Result<()> { Ok(()) } -fn self_uninstall(m: &ArgMatches) -> Result<()> { +fn self_uninstall(m: &ArgMatches<'_>) -> Result<()> { let no_prompt = m.is_present("no-prompt"); self_update::uninstall(no_prompt) @@ -1042,7 +1042,7 @@ fn analyze_telemetry(cfg: &Cfg) -> Result<()> { common::show_telemetry(analysis) } -fn set_default_host_triple(cfg: &Cfg, m: &ArgMatches) -> Result<()> { +fn set_default_host_triple(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { cfg.set_default_host_triple(m.value_of("host_triple").expect(""))?; Ok(()) } diff --git a/src/rustup-cli/self_update.rs b/src/rustup-cli/self_update.rs index a630b7a248..be741e4556 100644 --- a/src/rustup-cli/self_update.rs +++ b/src/rustup-cli/self_update.rs @@ -481,7 +481,7 @@ fn do_pre_install_options_sanity_checks(opts: &InstallOpts) -> Result<()> { ); Ok(()) })() - .map_err(|e: Box| { + .map_err(|e: Box| { format!( "Pre-checks for host and toolchain failed: {}\n\ If you are unsure of suitable values, the 'stable' toolchain is the default.\n\ @@ -500,7 +500,7 @@ fn do_pre_install_options_sanity_checks(opts: &InstallOpts) -> Result<()> { fn do_anti_sudo_check(no_prompt: bool) -> Result<()> { #[cfg(unix)] pub fn home_mismatch() -> bool { - extern crate libc as c; + use libc as c; use std::env; use std::ffi::CStr; diff --git a/src/rustup-cli/term2.rs b/src/rustup-cli/term2.rs index 7933885f32..15a7fccf44 100644 --- a/src/rustup-cli/term2.rs +++ b/src/rustup-cli/term2.rs @@ -6,7 +6,6 @@ use markdown::tokenize; use markdown::{Block, ListItem, Span}; use rustup_utils::tty; use std::io; -use term; pub use term::color; pub use term::Attr; @@ -43,7 +42,7 @@ impl Isatty for io::Stderr { } } -pub struct Terminal(Option + Send>>) +pub struct Terminal(Option + Send>>) where T: Instantiable + Isatty + io::Write; pub type StdoutTerminal = Terminal; @@ -58,7 +57,7 @@ pub fn stderr() -> StderrTerminal { } // Handles the wrapping of text written to the console -struct LineWrapper<'a, T: io::Write + 'a> { +struct LineWrapper<'a, T: io::Write> { indent: u32, margin: u32, pos: u32, @@ -136,7 +135,7 @@ impl<'a, T: io::Write + 'a> LineWrapper<'a, T> { } // Handles the formatting of text -struct LineFormatter<'a, T: Instantiable + Isatty + io::Write + 'a> { +struct LineFormatter<'a, T: Instantiable + Isatty + io::Write> { wrapper: LineWrapper<'a, Terminal>, attrs: Vec, } diff --git a/src/rustup-dist/src/component/components.rs b/src/rustup-dist/src/component/components.rs index a2f6eafae2..7132012767 100644 --- a/src/rustup-dist/src/component/components.rs +++ b/src/rustup-dist/src/component/components.rs @@ -45,7 +45,7 @@ impl Components { Ok(None) } } - fn write_version(&self, tx: &mut Transaction) -> Result<()> { + fn write_version(&self, tx: &mut Transaction<'_>) -> Result<()> { tx.modify_file(self.prefix.rel_manifest_file(VERSION_FILE))?; utils::write_file( VERSION_FILE, diff --git a/src/rustup-dist/src/component/package.rs b/src/rustup-dist/src/component/package.rs index cbd0223819..752d069f7c 100644 --- a/src/rustup-dist/src/component/package.rs +++ b/src/rustup-dist/src/component/package.rs @@ -2,10 +2,6 @@ //! for installing from a directory or tarball to an installation //! prefix, represented by a `Components` instance. -extern crate flate2; -extern crate tar; -extern crate xz2; - use crate::component::components::*; use crate::component::transaction::*; diff --git a/src/rustup-dist/src/component/transaction.rs b/src/rustup-dist/src/component/transaction.rs index ad42a05cc2..bf204e2c1f 100644 --- a/src/rustup-dist/src/component/transaction.rs +++ b/src/rustup-dist/src/component/transaction.rs @@ -35,7 +35,7 @@ pub struct Transaction<'a> { prefix: InstallPrefix, changes: Vec>, temp_cfg: &'a temp::Cfg, - notify_handler: &'a Fn(Notification), + notify_handler: &'a dyn Fn(Notification<'_>), committed: bool, } @@ -43,7 +43,7 @@ impl<'a> Transaction<'a> { pub fn new( prefix: InstallPrefix, temp_cfg: &'a temp::Cfg, - notify_handler: &'a Fn(Notification), + notify_handler: &'a dyn Fn(Notification<'_>), ) -> Self { Transaction { prefix: prefix, @@ -136,7 +136,7 @@ impl<'a> Transaction<'a> { pub fn temp(&self) -> &'a temp::Cfg { self.temp_cfg } - pub fn notify_handler(&self) -> &'a Fn(Notification) { + pub fn notify_handler(&self) -> &'a dyn Fn(Notification<'_>) { self.notify_handler } } diff --git a/src/rustup-dist/src/config.rs b/src/rustup-dist/src/config.rs index 20c8edcad8..fb464b5c0c 100644 --- a/src/rustup-dist/src/config.rs +++ b/src/rustup-dist/src/config.rs @@ -1,5 +1,3 @@ -use toml; - use super::manifest::Component; use crate::errors::*; use rustup_utils::toml_utils::*; diff --git a/src/rustup-dist/src/dist.rs b/src/rustup-dist/src/dist.rs index 5f1c860401..db991aa130 100644 --- a/src/rustup-dist/src/dist.rs +++ b/src/rustup-dist/src/dist.rs @@ -6,7 +6,7 @@ use crate::manifestation::{Changes, Manifestation, UpdateStatus}; use crate::notifications::*; use crate::prefix::InstallPrefix; use crate::temp; -use rustup_utils::{self, utils}; +use rustup_utils::utils; use std::env; use std::fmt; @@ -449,13 +449,13 @@ impl<'a> Manifest<'a> { } impl fmt::Display for TargetTriple { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.fmt(f) } } impl fmt::Display for PartialToolchainDesc { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", &self.channel)?; if let Some(ref date) = self.date { @@ -476,7 +476,7 @@ impl fmt::Display for PartialToolchainDesc { } impl fmt::Display for ToolchainDesc { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", &self.channel)?; if let Some(ref date) = self.date { diff --git a/src/rustup-dist/src/download.rs b/src/rustup-dist/src/download.rs index ce48f2a56e..3a52bbbb79 100644 --- a/src/rustup-dist/src/download.rs +++ b/src/rustup-dist/src/download.rs @@ -16,7 +16,7 @@ pub struct DownloadCfg<'a> { pub dist_root: &'a str, pub temp_cfg: &'a temp::Cfg, pub download_dir: &'a PathBuf, - pub notify_handler: &'a Fn(Notification), + pub notify_handler: &'a dyn Fn(Notification<'_>), } pub struct File { diff --git a/src/rustup-dist/src/errors.rs b/src/rustup-dist/src/errors.rs index e513c10fb5..7dbbf8092b 100644 --- a/src/rustup-dist/src/errors.rs +++ b/src/rustup-dist/src/errors.rs @@ -1,9 +1,10 @@ use crate::manifest::{Component, Manifest}; use crate::temp; -use rustup_utils; +use error_chain::error_chain; +use error_chain::error_chain_processing; +use error_chain::{impl_error_chain_kind, impl_error_chain_processed, impl_extract_backtrace}; use std::io::{self, Write}; use std::path::PathBuf; -use toml; pub const TOOLSTATE_MSG: &str = "if you require these components, please install and use the latest successful build version, \ diff --git a/src/rustup-dist/src/lib.rs b/src/rustup-dist/src/lib.rs index b7ee50654e..aa70f9ddfe 100644 --- a/src/rustup-dist/src/lib.rs +++ b/src/rustup-dist/src/lib.rs @@ -1,24 +1,5 @@ #![recursion_limit = "1024"] -#[macro_use] -extern crate error_chain; -extern crate flate2; -extern crate itertools; -extern crate regex; -extern crate rustup_utils; -extern crate sha2; -extern crate tar; -extern crate toml; -extern crate url; -extern crate walkdir; - -#[cfg(not(windows))] -extern crate libc; -#[cfg(windows)] -extern crate winapi; -#[cfg(windows)] -extern crate winreg; - pub use crate::errors::*; pub use crate::notifications::Notification; diff --git a/src/rustup-dist/src/manifest.rs b/src/rustup-dist/src/manifest.rs index fa177c7619..d8f1effc0f 100644 --- a/src/rustup-dist/src/manifest.rs +++ b/src/rustup-dist/src/manifest.rs @@ -12,7 +12,6 @@ use crate::errors::*; use rustup_utils::toml_utils::*; -use toml; use crate::dist::TargetTriple; use std::collections::HashMap; diff --git a/src/rustup-dist/src/manifestation.rs b/src/rustup-dist/src/manifestation.rs index df9589f908..f37d4e2117 100644 --- a/src/rustup-dist/src/manifestation.rs +++ b/src/rustup-dist/src/manifestation.rs @@ -109,8 +109,8 @@ impl Manifestation { new_manifest: &Manifest, changes: Changes, force_update: bool, - download_cfg: &DownloadCfg, - notify_handler: &Fn(Notification), + download_cfg: &DownloadCfg<'_>, + notify_handler: &dyn Fn(Notification<'_>), ) -> Result { // Some vars we're going to need a few times let temp_cfg = download_cfg.temp_cfg; @@ -200,12 +200,12 @@ impl Manifestation { let gz; let xz; - let notification_converter = |notification: rustup_utils::Notification| { + let notification_converter = |notification: rustup_utils::Notification<'_>| { notify_handler(Notification::Utils(notification)); }; let reader = utils::FileReaderWithProgress::new_file(&installer_file, ¬ification_converter)?; - let package: &Package = match format { + let package: &dyn Package = match format { Format::Gz => { gz = TarGzPackage::new(reader, temp_cfg)?; &gz @@ -256,7 +256,7 @@ impl Manifestation { &self, manifest: &Manifest, temp_cfg: &temp::Cfg, - notify_handler: &Fn(Notification), + notify_handler: &dyn Fn(Notification<'_>), ) -> Result<()> { let prefix = self.installation.prefix(); @@ -282,7 +282,7 @@ impl Manifestation { component: &Component, manifest: &Manifest, mut tx: Transaction<'a>, - notify_handler: &Fn(Notification), + notify_handler: &dyn Fn(Notification<'_>), ) -> Result> { // For historical reasons, the rust-installer component // names are not the same as the dist manifest component @@ -334,7 +334,7 @@ impl Manifestation { new_manifest: &[String], update_hash: Option<&Path>, temp_cfg: &temp::Cfg, - notify_handler: &Fn(Notification), + notify_handler: &dyn Fn(Notification<'_>), ) -> Result> { // If there's already a v2 installation then something has gone wrong if self.read_config()?.is_some() { @@ -447,7 +447,7 @@ impl Update { manifestation: &Manifestation, new_manifest: &Manifest, changes: Changes, - notify_handler: &Fn(Notification), + notify_handler: &dyn Fn(Notification<'_>), ) -> Result { // Load the configuration and list of installed components. let config = manifestation.read_config()?; @@ -527,7 +527,7 @@ impl Update { rust_target_package: &TargetedPackage, new_manifest: &Manifest, changes: &Changes, - notify_handler: &Fn(Notification), + notify_handler: &dyn Fn(Notification<'_>), ) { // Add components required by the package, according to the // manifest diff --git a/src/rustup-dist/src/notifications.rs b/src/rustup-dist/src/notifications.rs index b9f5c01203..e253e9a60a 100644 --- a/src/rustup-dist/src/notifications.rs +++ b/src/rustup-dist/src/notifications.rs @@ -1,7 +1,6 @@ use crate::dist::TargetTriple; use crate::errors::*; use crate::temp; -use rustup_utils; use rustup_utils::notify::NotificationLevel; use std::fmt::{self, Display}; use std::path::Path; @@ -76,7 +75,7 @@ impl<'a> Notification<'a> { } impl<'a> Display for Notification<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> ::std::result::Result<(), fmt::Error> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> ::std::result::Result<(), fmt::Error> { use self::Notification::*; match *self { Temp(ref n) => n.fmt(f), diff --git a/src/rustup-dist/src/temp.rs b/src/rustup-dist/src/temp.rs index 1bf0328e3b..75a0a39b4a 100644 --- a/src/rustup-dist/src/temp.rs +++ b/src/rustup-dist/src/temp.rs @@ -1,5 +1,3 @@ -extern crate remove_dir_all; - use rustup_utils::raw; use std::error; use std::fmt::{self, Display}; @@ -31,7 +29,7 @@ pub enum Notification<'a> { pub struct Cfg { root_directory: PathBuf, pub dist_server: String, - notify_handler: Box, + notify_handler: Box)>, } #[derive(Debug)] @@ -63,7 +61,7 @@ impl<'a> Notification<'a> { } impl<'a> Display for Notification<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> ::std::result::Result<(), fmt::Error> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> ::std::result::Result<(), fmt::Error> { use self::Notification::*; match *self { CreatingRoot(path) => write!(f, "creating temp root: {}", path.display()), @@ -97,7 +95,7 @@ impl error::Error for Error { } } - fn cause(&self) -> Option<&error::Error> { + fn cause(&self) -> Option<&dyn error::Error> { use self::Error::*; match *self { CreatingRoot { ref error, .. } @@ -108,7 +106,7 @@ impl error::Error for Error { } impl Display for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> ::std::result::Result<(), fmt::Error> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> ::std::result::Result<(), fmt::Error> { use self::Error::*; match *self { CreatingRoot { ref path, error: _ } => { @@ -128,7 +126,7 @@ impl Cfg { pub fn new( root_directory: PathBuf, dist_server: &str, - notify_handler: Box, + notify_handler: Box)>, ) -> Self { Cfg { root_directory: root_directory, @@ -147,7 +145,7 @@ impl Cfg { }) } - pub fn new_directory(&self) -> Result { + pub fn new_directory(&self) -> Result> { self.create_root()?; loop { @@ -171,11 +169,11 @@ impl Cfg { } } - pub fn new_file(&self) -> Result { + pub fn new_file(&self) -> Result> { self.new_file_with_ext("", "") } - pub fn new_file_with_ext(&self, prefix: &str, ext: &str) -> Result { + pub fn new_file_with_ext(&self, prefix: &str, ext: &str) -> Result> { self.create_root()?; loop { @@ -201,7 +199,7 @@ impl Cfg { } impl fmt::Debug for Cfg { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Cfg") .field("root_directory", &self.root_directory) .field("notify_handler", &"...") diff --git a/src/rustup-dist/tests/dist.rs b/src/rustup-dist/tests/dist.rs index f12994a78d..192096bca9 100644 --- a/src/rustup-dist/tests/dist.rs +++ b/src/rustup-dist/tests/dist.rs @@ -1,17 +1,6 @@ // Tests of installation and updates from a v2 Rust distribution // server (mocked on the file system) -extern crate flate2; -extern crate itertools; -extern crate rustup_dist; -extern crate rustup_mock; -extern crate rustup_utils; -extern crate tar; -extern crate tempdir; -extern crate toml; -extern crate url; -extern crate walkdir; - use rustup_dist::dist::{TargetTriple, ToolchainDesc, DEFAULT_DIST_SERVER}; use rustup_dist::download::DownloadCfg; use rustup_dist::errors::Result; @@ -37,7 +26,7 @@ use tempdir::TempDir; // Creates a mock dist server populated with some test data pub fn create_mock_dist_server( path: &Path, - edit: Option<&Fn(&str, &mut [MockPackage])>, + edit: Option<&dyn Fn(&str, &mut [MockPackage])>, ) -> MockDistServer { MockDistServer { path: path.to_owned(), @@ -51,7 +40,7 @@ pub fn create_mock_dist_server( pub fn create_mock_channel( channel: &str, date: &str, - edit: Option<&Fn(&str, &mut [MockPackage])>, + edit: Option<&dyn Fn(&str, &mut [MockPackage])>, ) -> MockChannel { // Put the date in the files so they can be differentiated let contents = Arc::new(date.as_bytes().to_vec()); @@ -386,7 +375,7 @@ fn update_from_dist( prefix: &InstallPrefix, add: &[Component], remove: &[Component], - download_cfg: &DownloadCfg, + download_cfg: &DownloadCfg<'_>, temp_cfg: &temp::Cfg, ) -> Result { update_from_dist_( @@ -407,7 +396,7 @@ fn update_from_dist_( prefix: &InstallPrefix, add: &[Component], remove: &[Component], - download_cfg: &DownloadCfg, + download_cfg: &DownloadCfg<'_>, temp_cfg: &temp::Cfg, force_update: bool, ) -> Result { @@ -449,7 +438,7 @@ fn uninstall( toolchain: &ToolchainDesc, prefix: &InstallPrefix, temp_cfg: &temp::Cfg, - notify_handler: &Fn(Notification), + notify_handler: &dyn Fn(Notification<'_>), ) -> Result<()> { let trip = toolchain.target.clone(); let manifestation = Manifestation::open(prefix.clone(), trip)?; @@ -461,9 +450,9 @@ fn uninstall( } fn setup( - edit: Option<&Fn(&str, &mut [MockPackage])>, + edit: Option<&dyn Fn(&str, &mut [MockPackage])>, enable_xz: bool, - f: &Fn(&Url, &ToolchainDesc, &InstallPrefix, &DownloadCfg, &temp::Cfg), + f: &dyn Fn(&Url, &ToolchainDesc, &InstallPrefix, &DownloadCfg<'_>, &temp::Cfg), ) { let dist_tempdir = TempDir::new("rustup").unwrap(); let mock_dist_server = create_mock_dist_server(dist_tempdir.path(), edit); @@ -475,7 +464,7 @@ fn setup_from_dist_server( server: MockDistServer, url: &Url, enable_xz: bool, - f: &Fn(&Url, &ToolchainDesc, &InstallPrefix, &DownloadCfg, &temp::Cfg), + f: &dyn Fn(&Url, &ToolchainDesc, &InstallPrefix, &DownloadCfg<'_>, &temp::Cfg), ) { server.write(&[ManifestVersion::V2], enable_xz); diff --git a/src/rustup-dist/tests/install.rs b/src/rustup-dist/tests/install.rs index 426ab16c73..8fb9caf244 100644 --- a/src/rustup-dist/tests/install.rs +++ b/src/rustup-dist/tests/install.rs @@ -1,8 +1,3 @@ -extern crate rustup_dist; -extern crate rustup_mock; -extern crate rustup_utils; -extern crate tempdir; - use rustup_dist::component::Components; use rustup_dist::component::Transaction; use rustup_dist::component::{DirectoryPackage, Package}; @@ -120,7 +115,7 @@ fn basic_install() { DEFAULT_DIST_SERVER, Box::new(|_| ()), ); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); let components = Components::open(prefix.clone()).unwrap(); @@ -166,7 +161,7 @@ fn multiple_component_install() { DEFAULT_DIST_SERVER, Box::new(|_| ()), ); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); let components = Components::open(prefix.clone()).unwrap(); @@ -216,7 +211,7 @@ fn uninstall() { DEFAULT_DIST_SERVER, Box::new(|_| ()), ); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); let components = Components::open(prefix.clone()).unwrap(); @@ -228,7 +223,7 @@ fn uninstall() { tx.commit(); // Now uninstall - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); for component in components.list().unwrap() { tx = component.uninstall(tx).unwrap(); @@ -273,7 +268,7 @@ fn component_bad_version() { DEFAULT_DIST_SERVER, Box::new(|_| ()), ); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); let components = Components::open(prefix.clone()).unwrap(); @@ -334,7 +329,7 @@ fn unix_permissions() { DEFAULT_DIST_SERVER, Box::new(|_| ()), ); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); let components = Components::open(prefix.clone()).unwrap(); @@ -419,7 +414,7 @@ fn install_to_prefix_that_does_not_exist() { DEFAULT_DIST_SERVER, Box::new(|_| ()), ); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); let components = Components::open(prefix.clone()).unwrap(); diff --git a/src/rustup-dist/tests/manifest.rs b/src/rustup-dist/tests/manifest.rs index b3b4290d1f..2a84a4c7cb 100644 --- a/src/rustup-dist/tests/manifest.rs +++ b/src/rustup-dist/tests/manifest.rs @@ -1,5 +1,3 @@ -extern crate rustup_dist; - use rustup_dist::dist::TargetTriple; use rustup_dist::manifest::Manifest; use rustup_dist::ErrorKind; diff --git a/src/rustup-dist/tests/transactions.rs b/src/rustup-dist/tests/transactions.rs index 15bf782d5f..dd35167c53 100644 --- a/src/rustup-dist/tests/transactions.rs +++ b/src/rustup-dist/tests/transactions.rs @@ -1,7 +1,3 @@ -extern crate rustup_dist; -extern crate rustup_utils; -extern crate tempdir; - use rustup_dist::component::Transaction; use rustup_dist::dist::DEFAULT_DIST_SERVER; use rustup_dist::prefix::InstallPrefix; @@ -28,7 +24,7 @@ fn add_file() { Box::new(|_| ()), ); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); let mut file = tx.add_file("c", PathBuf::from("foo/bar")).unwrap(); @@ -56,7 +52,7 @@ fn add_file_then_rollback() { Box::new(|_| ()), ); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); tx.add_file("c", PathBuf::from("foo/bar")).unwrap(); @@ -78,7 +74,7 @@ fn add_file_that_exists() { let prefix = InstallPrefix::from(prefixdir.path().to_owned()); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); fs::create_dir_all(&prefixdir.path().join("foo")).unwrap(); @@ -109,7 +105,7 @@ fn copy_file() { let prefix = InstallPrefix::from(prefixdir.path().to_owned()); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); let srcpath = srcdir.path().join("bar"); @@ -136,7 +132,7 @@ fn copy_file_then_rollback() { let prefix = InstallPrefix::from(prefixdir.path().to_owned()); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); let srcpath = srcdir.path().join("bar"); @@ -163,7 +159,7 @@ fn copy_file_that_exists() { let prefix = InstallPrefix::from(prefixdir.path().to_owned()); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); let srcpath = srcdir.path().join("bar"); @@ -199,7 +195,7 @@ fn copy_dir() { let prefix = InstallPrefix::from(prefixdir.path().to_owned()); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); let srcpath1 = srcdir.path().join("foo"); @@ -233,7 +229,7 @@ fn copy_dir_then_rollback() { let prefix = InstallPrefix::from(prefixdir.path().to_owned()); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); let srcpath1 = srcdir.path().join("foo"); @@ -267,7 +263,7 @@ fn copy_dir_that_exists() { let prefix = InstallPrefix::from(prefixdir.path().to_owned()); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); fs::create_dir_all(prefix.path().join("a")).unwrap(); @@ -298,7 +294,7 @@ fn remove_file() { let prefix = InstallPrefix::from(prefixdir.path().to_owned()); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); let filepath = prefixdir.path().join("foo"); @@ -323,7 +319,7 @@ fn remove_file_then_rollback() { let prefix = InstallPrefix::from(prefixdir.path().to_owned()); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); let filepath = prefixdir.path().join("foo"); @@ -348,7 +344,7 @@ fn remove_file_that_not_exists() { let prefix = InstallPrefix::from(prefixdir.path().to_owned()); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); let err = tx.remove_file("c", PathBuf::from("foo")).unwrap_err(); @@ -375,7 +371,7 @@ fn remove_dir() { let prefix = InstallPrefix::from(prefixdir.path().to_owned()); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); let filepath = prefixdir.path().join("foo/bar"); @@ -401,7 +397,7 @@ fn remove_dir_then_rollback() { let prefix = InstallPrefix::from(prefixdir.path().to_owned()); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); let filepath = prefixdir.path().join("foo/bar"); @@ -427,7 +423,7 @@ fn remove_dir_that_not_exists() { let prefix = InstallPrefix::from(prefixdir.path().to_owned()); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); let err = tx.remove_dir("c", PathBuf::from("foo")).unwrap_err(); @@ -454,7 +450,7 @@ fn write_file() { let prefix = InstallPrefix::from(prefixdir.path().to_owned()); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); let content = "hi".to_string(); @@ -481,7 +477,7 @@ fn write_file_then_rollback() { let prefix = InstallPrefix::from(prefixdir.path().to_owned()); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); let content = "hi".to_string(); @@ -505,7 +501,7 @@ fn write_file_that_exists() { let prefix = InstallPrefix::from(prefixdir.path().to_owned()); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); let content = "hi".to_string(); @@ -538,7 +534,7 @@ fn modify_file_that_not_exists() { let prefix = InstallPrefix::from(prefixdir.path().to_owned()); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); tx.modify_file(PathBuf::from("foo/bar")).unwrap(); @@ -562,7 +558,7 @@ fn modify_file_that_exists() { let prefix = InstallPrefix::from(prefixdir.path().to_owned()); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); let ref path = prefix.path().join("foo"); @@ -586,7 +582,7 @@ fn modify_file_that_not_exists_then_rollback() { let prefix = InstallPrefix::from(prefixdir.path().to_owned()); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); tx.modify_file(PathBuf::from("foo/bar")).unwrap(); @@ -608,7 +604,7 @@ fn modify_file_that_exists_then_rollback() { let prefix = InstallPrefix::from(prefixdir.path().to_owned()); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); let ref path = prefix.path().join("foo"); @@ -635,7 +631,7 @@ fn modify_twice_then_rollback() { let prefix = InstallPrefix::from(prefixdir.path().to_owned()); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); let ref path = prefix.path().join("foo"); @@ -662,7 +658,7 @@ fn do_multiple_op_transaction(rollback: bool) { let prefix = InstallPrefix::from(prefixdir.path().to_owned()); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); // copy_file @@ -763,7 +759,7 @@ fn rollback_failure_keeps_going() { let prefix = InstallPrefix::from(prefixdir.path().to_owned()); - let notify = |_: Notification| (); + let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); write!(&mut tx.add_file("", PathBuf::from("foo")).unwrap(), "").unwrap(); diff --git a/src/rustup-mock/src/clitools.rs b/src/rustup-mock/src/clitools.rs index 78151effa0..e158204aff 100644 --- a/src/rustup-mock/src/clitools.rs +++ b/src/rustup-mock/src/clitools.rs @@ -6,6 +6,7 @@ use crate::dist::{ MockTargetedPackage, }; use crate::{MockComponentBuilder, MockFile, MockInstallerBuilder}; +use lazy_static::lazy_static; use std::cell::RefCell; use std::collections::HashMap; use std::env; @@ -66,7 +67,7 @@ pub static MULTI_ARCH1: &'static str = "i686-unknown-linux-gnu"; /// Run this to create the test environment containing rustup, and /// a mock dist server. -pub fn setup(s: Scenario, f: &Fn(&mut Config)) { +pub fn setup(s: Scenario, f: &dyn Fn(&mut Config)) { // Unset env variables that will break our testing env::remove_var("RUSTUP_TOOLCHAIN"); env::remove_var("SHELL"); @@ -155,7 +156,7 @@ impl Config { self._change_dir(path, &mut f) } - fn _change_dir(&self, path: &Path, f: &mut FnMut()) { + fn _change_dir(&self, path: &Path, f: &mut dyn FnMut()) { let prev = mem::replace(&mut *self.workdir.borrow_mut(), path.to_owned()); f(); *self.workdir.borrow_mut() = prev; diff --git a/src/rustup-mock/src/dist.rs b/src/rustup-mock/src/dist.rs index 821ebc653d..0bada25e5a 100644 --- a/src/rustup-mock/src/dist.rs +++ b/src/rustup-mock/src/dist.rs @@ -2,19 +2,15 @@ //! distribution server, with v1 and v2 manifests. use crate::MockInstallerBuilder; -use flate2; +use lazy_static::lazy_static; use sha2::{Digest, Sha256}; use std::collections::HashMap; use std::fs::{self, File}; use std::io::{Read, Write}; use std::path::{Path, PathBuf}; use std::sync::Mutex; -use tar; use tempdir::TempDir; -use toml; use url::Url; -use walkdir; -use xz2; use crate::clitools::hard_link; @@ -427,7 +423,7 @@ fn create_tarball(relpath: &Path, src: &Path, dst: &Path) { let outfile = File::create(dst).unwrap(); let mut gzwriter; let mut xzwriter; - let writer: &mut Write = match &dst.to_string_lossy() { + let writer: &mut dyn Write = match &dst.to_string_lossy() { s if s.ends_with(".tar.gz") => { gzwriter = flate2::write::GzEncoder::new(outfile, flate2::Compression::none()); &mut gzwriter diff --git a/src/rustup-mock/src/lib.rs b/src/rustup-mock/src/lib.rs index 00f6ff59a8..31457f4317 100644 --- a/src/rustup-mock/src/lib.rs +++ b/src/rustup-mock/src/lib.rs @@ -1,22 +1,5 @@ //! Mocks for testing -extern crate flate2; -#[macro_use] -extern crate lazy_static; -extern crate sha2; -extern crate tar; -extern crate tempdir; -extern crate toml; -extern crate url; -extern crate wait_timeout; -extern crate walkdir; -extern crate xz2; - -#[cfg(windows)] -extern crate winapi; -#[cfg(windows)] -extern crate winreg; - pub mod clitools; pub mod dist; diff --git a/src/rustup-utils/src/errors.rs b/src/rustup-utils/src/errors.rs index 38ed04d1dc..cb20c8952d 100644 --- a/src/rustup-utils/src/errors.rs +++ b/src/rustup-utils/src/errors.rs @@ -1,4 +1,6 @@ -use download; +use error_chain::error_chain; +use error_chain::error_chain_processing; +use error_chain::{impl_error_chain_kind, impl_error_chain_processed, impl_extract_backtrace}; use std::ffi::OsString; use std::path::PathBuf; use url::Url; diff --git a/src/rustup-utils/src/lib.rs b/src/rustup-utils/src/lib.rs index 9038c44058..3ff5e740c0 100644 --- a/src/rustup-utils/src/lib.rs +++ b/src/rustup-utils/src/lib.rs @@ -1,23 +1,5 @@ #![recursion_limit = "1024"] // for error_chain! -extern crate download; -#[macro_use] -extern crate error_chain; -extern crate rand; -extern crate scopeguard; -extern crate semver; -extern crate sha2; -extern crate toml; -extern crate url; - -#[cfg(windows)] -extern crate winapi; -#[cfg(windows)] -extern crate winreg; - -#[cfg(unix)] -extern crate libc; - pub mod errors; pub mod notifications; pub mod raw; diff --git a/src/rustup-utils/src/notifications.rs b/src/rustup-utils/src/notifications.rs index b6590c89fc..0241d30267 100644 --- a/src/rustup-utils/src/notifications.rs +++ b/src/rustup-utils/src/notifications.rs @@ -45,7 +45,7 @@ impl<'a> Notification<'a> { } impl<'a> Display for Notification<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> ::std::result::Result<(), fmt::Error> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> ::std::result::Result<(), fmt::Error> { use self::Notification::*; match *self { CreatingDirectory(name, path) => { diff --git a/src/rustup-utils/src/raw.rs b/src/rustup-utils/src/raw.rs index fcff9d6533..244f14bd3b 100644 --- a/src/rustup-utils/src/raw.rs +++ b/src/rustup-utils/src/raw.rs @@ -1,5 +1,3 @@ -extern crate remove_dir_all; - use std::char::from_u32; use std::env; use std::error; @@ -278,7 +276,7 @@ impl error::Error for CommandError { } } - fn cause(&self) -> Option<&error::Error> { + fn cause(&self) -> Option<&dyn error::Error> { use self::CommandError::*; match *self { Io(ref e) => Some(e), @@ -288,7 +286,7 @@ impl error::Error for CommandError { } impl fmt::Display for CommandError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { CommandError::Io(ref e) => write!(f, "Io: {}", e), CommandError::Status(ref s) => write!(f, "Status: {}", s), diff --git a/src/rustup-utils/src/toml_utils.rs b/src/rustup-utils/src/toml_utils.rs index 4b6f4ffa84..6929f8e6b4 100644 --- a/src/rustup-utils/src/toml_utils.rs +++ b/src/rustup-utils/src/toml_utils.rs @@ -1,5 +1,4 @@ use crate::errors::*; -use toml; pub fn get_value(table: &mut toml::value::Table, key: &str, path: &str) -> Result { table diff --git a/src/rustup-utils/src/utils.rs b/src/rustup-utils/src/utils.rs index 1a711cdf1f..3266b5763c 100644 --- a/src/rustup-utils/src/utils.rs +++ b/src/rustup-utils/src/utils.rs @@ -11,10 +11,9 @@ use std::path::{Path, PathBuf}; use std::process::Command; use std::sync::atomic::{AtomicBool, Ordering, ATOMIC_BOOL_INIT}; use url::Url; + #[cfg(windows)] use winapi::shared::minwindef::DWORD; -#[cfg(windows)] -use winreg; pub use crate::raw::{ find_cmd, has_cmd, if_not_empty, is_directory, is_file, path_exists, prefix_arg, random_string, @@ -25,7 +24,7 @@ pub struct ExitCode(pub i32); pub fn ensure_dir_exists( name: &'static str, path: &Path, - notify_handler: &Fn(Notification), + notify_handler: &dyn Fn(Notification<'_>), ) -> Result { raw::ensure_dir_exists(path, |p| { notify_handler(Notification::CreatingDirectory(name, p)) @@ -103,7 +102,7 @@ pub fn match_file Option>( }) } -pub fn canonicalize_path(path: &Path, notify_handler: &Fn(Notification)) -> PathBuf { +pub fn canonicalize_path(path: &Path, notify_handler: &dyn Fn(Notification<'_>)) -> PathBuf { fs::canonicalize(path).unwrap_or_else(|_| { notify_handler(Notification::NoCanonicalPath(path)); PathBuf::from(path) @@ -121,7 +120,7 @@ pub fn download_file( url: &Url, path: &Path, hasher: Option<&mut Sha256>, - notify_handler: &Fn(Notification), + notify_handler: &dyn Fn(Notification<'_>), ) -> Result<()> { download_file_with_resume(&url, &path, hasher, false, ¬ify_handler) } @@ -131,14 +130,14 @@ pub fn download_file_with_resume( path: &Path, hasher: Option<&mut Sha256>, resume_from_partial: bool, - notify_handler: &Fn(Notification), + notify_handler: &dyn Fn(Notification<'_>), ) -> Result<()> { use download::ErrorKind as DEK; match download_file_(url, path, hasher, resume_from_partial, notify_handler) { Ok(_) => Ok(()), Err(e) => { let is_client_error = match e.kind() { - &ErrorKind::Download(DEK::HttpStatus(400...499)) => true, + &ErrorKind::Download(DEK::HttpStatus(400..=499)) => true, &ErrorKind::Download(DEK::FileNotFound) => true, _ => false, }; @@ -166,7 +165,7 @@ fn download_file_( path: &Path, hasher: Option<&mut Sha256>, resume_from_partial: bool, - notify_handler: &Fn(Notification), + notify_handler: &dyn Fn(Notification<'_>), ) -> Result<()> { use download::download_to_path_with_backend; use download::{self, Backend, Event}; @@ -179,7 +178,7 @@ fn download_file_( // This callback will write the download to disk and optionally // hash the contents, then forward the notification up the stack - let callback: &Fn(Event) -> download::Result<()> = &|msg| { + let callback: &dyn Fn(Event<'_>) -> download::Result<()> = &|msg| { match msg { Event::DownloadDataReceived(data) => { if let Some(ref mut h) = *hasher.borrow_mut() { @@ -257,7 +256,11 @@ pub fn assert_is_directory(path: &Path) -> Result<()> { } } -pub fn symlink_dir(src: &Path, dest: &Path, notify_handler: &Fn(Notification)) -> Result<()> { +pub fn symlink_dir( + src: &Path, + dest: &Path, + notify_handler: &dyn Fn(Notification<'_>), +) -> Result<()> { notify_handler(Notification::LinkingDirectory(src, dest)); raw::symlink_dir(src, dest).chain_err(|| ErrorKind::LinkingDirectory { src: PathBuf::from(src), @@ -297,7 +300,7 @@ pub fn symlink_file(src: &Path, dest: &Path) -> Result<()> { .into()) } -pub fn copy_dir(src: &Path, dest: &Path, notify_handler: &Fn(Notification)) -> Result<()> { +pub fn copy_dir(src: &Path, dest: &Path, notify_handler: &dyn Fn(Notification<'_>)) -> Result<()> { notify_handler(Notification::CopyingDirectory(src, dest)); raw::copy_dir(src, dest).chain_err(|| ErrorKind::CopyingDirectory { src: PathBuf::from(src), @@ -325,7 +328,7 @@ pub fn copy_file(src: &Path, dest: &Path) -> Result<()> { pub fn remove_dir( name: &'static str, path: &Path, - notify_handler: &Fn(Notification), + notify_handler: &dyn Fn(Notification<'_>), ) -> Result<()> { notify_handler(Notification::RemovingDirectory(name, path)); raw::remove_dir(path).chain_err(|| ErrorKind::RemovingDirectory { @@ -856,14 +859,14 @@ fn rename(name: &'static str, src: &Path, dest: &Path) -> Result<()> { pub struct FileReaderWithProgress<'a> { fh: std::fs::File, - notify_handler: &'a Fn(Notification), + notify_handler: &'a dyn Fn(Notification<'_>), sent_start: bool, nbytes: u64, flen: u64, } impl<'a> FileReaderWithProgress<'a> { - pub fn new_file(path: &Path, notify_handler: &'a Fn(Notification)) -> Result { + pub fn new_file(path: &Path, notify_handler: &'a dyn Fn(Notification<'_>)) -> Result { let fh = match std::fs::File::open(path) { Ok(fh) => fh, Err(_) => Err(ErrorKind::ReadingFile { diff --git a/src/rustup/command.rs b/src/rustup/command.rs index 71fbe5c9da..1cc2586bf8 100644 --- a/src/rustup/command.rs +++ b/src/rustup/command.rs @@ -10,7 +10,7 @@ use crate::errors::*; use crate::notifications::*; use crate::telemetry::{Telemetry, TelemetryEvent}; use crate::Cfg; -use rustup_utils::{self, utils::ExitCode}; +use rustup_utils::utils::ExitCode; pub fn run_command_for_dir>( cmd: Command, diff --git a/src/rustup/config.rs b/src/rustup/config.rs index 414a4881d7..da38bdae9e 100644 --- a/src/rustup/config.rs +++ b/src/rustup/config.rs @@ -22,7 +22,7 @@ pub enum OverrideReason { } impl Display for OverrideReason { - fn fmt(&self, f: &mut fmt::Formatter) -> ::std::result::Result<(), fmt::Error> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> ::std::result::Result<(), fmt::Error> { match *self { OverrideReason::Environment => write!(f, "environment override by RUSTUP_TOOLCHAIN"), OverrideReason::OverrideDB(ref path) => { @@ -46,11 +46,11 @@ pub struct Cfg { pub env_override: Option, pub dist_root_url: String, pub dist_root_server: String, - pub notify_handler: Arc, + pub notify_handler: Arc)>, } impl Cfg { - pub fn from_env(notify_handler: Arc) -> Result { + pub fn from_env(notify_handler: Arc)>) -> Result { // Set up the rustup home directory let rustup_dir = utils::rustup_home()?; @@ -131,7 +131,7 @@ impl Cfg { Ok(()) } - pub fn get_toolchain(&self, name: &str, create_parent: bool) -> Result { + pub fn get_toolchain(&self, name: &str, create_parent: bool) -> Result> { if create_parent { utils::ensure_dir_exists("toolchains", &self.toolchains_dir, &|n| { (self.notify_handler)(n.into()) @@ -141,7 +141,7 @@ impl Cfg { Toolchain::from(self, name) } - pub fn verify_toolchain(&self, name: &str) -> Result { + pub fn verify_toolchain(&self, name: &str) -> Result> { let toolchain = self.get_toolchain(name, false)?; toolchain.verify()?; Ok(toolchain) @@ -217,7 +217,7 @@ impl Cfg { } } - pub fn find_default(&self) -> Result> { + pub fn find_default(&self) -> Result>> { let opt_name = self .settings_file .with(|s| Ok(s.default_toolchain.clone()))?; @@ -233,7 +233,7 @@ impl Cfg { } } - pub fn find_override(&self, path: &Path) -> Result> { + pub fn find_override(&self, path: &Path) -> Result, OverrideReason)>> { let mut override_ = None; // First check RUSTUP_TOOLCHAIN @@ -337,7 +337,7 @@ impl Cfg { pub fn find_override_toolchain_or_default( &self, path: &Path, - ) -> Result)>> { + ) -> Result, Option)>> { Ok( if let Some((toolchain, reason)) = self.find_override(path)? { Some((toolchain, Some(reason))) @@ -411,7 +411,10 @@ impl Cfg { }) } - pub fn toolchain_for_dir(&self, path: &Path) -> Result<(Toolchain, Option)> { + pub fn toolchain_for_dir( + &self, + path: &Path, + ) -> Result<(Toolchain<'_>, Option)> { self.find_override_toolchain_or_default(path) .and_then(|r| r.ok_or("no default toolchain configured".into())) } @@ -448,7 +451,7 @@ impl Cfg { // try to find a different cargo. fn maybe_do_cargo_fallback( &self, - toolchain: &Toolchain, + toolchain: &Toolchain<'_>, binary: &str, ) -> Result> { if !toolchain.is_custom() { diff --git a/src/rustup/errors.rs b/src/rustup/errors.rs index 48e569c967..733f0623d4 100644 --- a/src/rustup/errors.rs +++ b/src/rustup/errors.rs @@ -1,7 +1,8 @@ use crate::component_for_bin; -use rustup_dist::{self, temp}; -use rustup_utils; -use toml; +use error_chain::error_chain; +use error_chain::error_chain_processing; +use error_chain::{impl_error_chain_kind, impl_error_chain_processed, impl_extract_backtrace}; +use rustup_dist::temp; error_chain! { links { diff --git a/src/rustup/install.rs b/src/rustup/install.rs index 16e18f1c8d..f45aa0057f 100644 --- a/src/rustup/install.rs +++ b/src/rustup/install.rs @@ -26,7 +26,7 @@ pub enum InstallMethod<'a> { } impl<'a> InstallMethod<'a> { - pub fn run(self, path: &Path, notify_handler: &Fn(Notification)) -> Result { + pub fn run(self, path: &Path, notify_handler: &dyn Fn(Notification<'_>)) -> Result { if path.exists() { // Don't uninstall first for Dist method match self { @@ -79,7 +79,7 @@ impl<'a> InstallMethod<'a> { src: &Path, path: &Path, temp_cfg: &temp::Cfg, - notify_handler: &Fn(Notification), + notify_handler: &dyn Fn(Notification<'_>), ) -> Result<()> { notify_handler(Notification::Extracting(src, path)); @@ -99,7 +99,7 @@ impl<'a> InstallMethod<'a> { } } -pub fn uninstall(path: &Path, notify_handler: &Fn(Notification)) -> Result<()> { +pub fn uninstall(path: &Path, notify_handler: &dyn Fn(Notification<'_>)) -> Result<()> { Ok(utils::remove_dir("install", path, &|n| { notify_handler(n.into()) })?) diff --git a/src/rustup/lib.rs b/src/rustup/lib.rs index e3891d17a3..4fff9d6eef 100644 --- a/src/rustup/lib.rs +++ b/src/rustup/lib.rs @@ -1,21 +1,5 @@ #![recursion_limit = "1024"] -#[macro_use] -extern crate error_chain; -extern crate itertools; -#[cfg(unix)] -extern crate libc; -extern crate regex; -extern crate rustup_dist; -extern crate rustup_utils; -#[macro_use] -extern crate serde_derive; -extern crate serde_json; -extern crate tempfile; -extern crate time; -extern crate toml; -extern crate url; - pub use crate::config::*; pub use crate::errors::*; pub use crate::notifications::*; diff --git a/src/rustup/notifications.rs b/src/rustup/notifications.rs index 7812ca7d3e..82c427652a 100644 --- a/src/rustup/notifications.rs +++ b/src/rustup/notifications.rs @@ -3,8 +3,7 @@ use std::path::{Path, PathBuf}; use crate::errors::*; -use rustup_dist::{self, temp}; -use rustup_utils; +use rustup_dist::temp; use rustup_utils::notify::NotificationLevel; #[derive(Debug)] @@ -85,7 +84,7 @@ impl<'a> Notification<'a> { } impl<'a> Display for Notification<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> ::std::result::Result<(), fmt::Error> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> ::std::result::Result<(), fmt::Error> { use self::Notification::*; match *self { Install(ref n) => n.fmt(f), diff --git a/src/rustup/settings.rs b/src/rustup/settings.rs index f88862347c..3051ea88c8 100644 --- a/src/rustup/settings.rs +++ b/src/rustup/settings.rs @@ -6,7 +6,6 @@ use std::cell::RefCell; use std::collections::BTreeMap; use std::path::{Path, PathBuf}; use std::str::FromStr; -use toml; pub const SUPPORTED_METADATA_VERSIONS: [&'static str; 2] = ["2", "12"]; pub const DEFAULT_METADATA_VERSION: &'static str = "12"; @@ -143,7 +142,7 @@ impl Default for Settings { } impl Settings { - fn path_to_key(path: &Path, notify_handler: &Fn(Notification)) -> String { + fn path_to_key(path: &Path, notify_handler: &dyn Fn(Notification<'_>)) -> String { if path.exists() { utils::canonicalize_path(path, &|n| notify_handler(n.into())) .display() @@ -153,7 +152,11 @@ impl Settings { } } - pub fn remove_override(&mut self, path: &Path, notify_handler: &Fn(Notification)) -> bool { + pub fn remove_override( + &mut self, + path: &Path, + notify_handler: &dyn Fn(Notification<'_>), + ) -> bool { let key = Self::path_to_key(path, notify_handler); self.overrides.remove(&key).is_some() } @@ -162,14 +165,18 @@ impl Settings { &mut self, path: &Path, toolchain: String, - notify_handler: &Fn(Notification), + notify_handler: &dyn Fn(Notification<'_>), ) { let key = Self::path_to_key(path, notify_handler); notify_handler(Notification::SetOverrideToolchain(path, &toolchain)); self.overrides.insert(key, toolchain); } - pub fn dir_override(&self, dir: &Path, notify_handler: &Fn(Notification)) -> Option { + pub fn dir_override( + &self, + dir: &Path, + notify_handler: &dyn Fn(Notification<'_>), + ) -> Option { let key = Self::path_to_key(dir, notify_handler); self.overrides.get(&key).map(|s| s.clone()) } diff --git a/src/rustup/telemetry.rs b/src/rustup/telemetry.rs index 6536d660bc..591be9c29d 100644 --- a/src/rustup/telemetry.rs +++ b/src/rustup/telemetry.rs @@ -1,7 +1,6 @@ use crate::errors::*; use rustup_utils::{raw, utils}; -use serde_json; -use time; +use serde::{Deserialize, Serialize}; use std::fs; use std::path::PathBuf; diff --git a/src/rustup/telemetry_analysis.rs b/src/rustup/telemetry_analysis.rs index 2e985f4295..acc4597378 100644 --- a/src/rustup/telemetry_analysis.rs +++ b/src/rustup/telemetry_analysis.rs @@ -6,7 +6,6 @@ use std::io::BufReader; use std::path::PathBuf; use itertools::Itertools; -use serde_json; use crate::errors::*; use crate::telemetry::{LogMessage, TelemetryEvent}; @@ -39,7 +38,7 @@ impl RustcStatistics { } impl fmt::Display for RustcStatistics { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut errors: String = String::new(); if !self.error_codes_with_counts.is_empty() { @@ -90,7 +89,7 @@ impl fmt::Display for RustcStatistics { } impl fmt::Display for TelemetryAnalysis { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, r" diff --git a/src/rustup/toolchain.rs b/src/rustup/toolchain.rs index 3cb1e5610f..87e508d04b 100644 --- a/src/rustup/toolchain.rs +++ b/src/rustup/toolchain.rs @@ -5,7 +5,6 @@ use crate::install::{self, InstallMethod}; use crate::notifications::*; use crate::telemetry; use crate::telemetry::{Telemetry, TelemetryEvent}; -use rustup_dist; use rustup_dist::dist::ToolchainDesc; use rustup_dist::download::DownloadCfg; use rustup_dist::manifest::Component; @@ -28,7 +27,7 @@ pub struct Toolchain<'a> { name: String, path: PathBuf, telemetry: telemetry::Telemetry, - dist_handler: Box, + dist_handler: Box) + 'a>, } /// Used by the `list_component` function @@ -103,7 +102,7 @@ impl<'a> Toolchain<'a> { } Ok(result?) } - fn install(&self, install_method: InstallMethod) -> Result { + fn install(&self, install_method: InstallMethod<'_>) -> Result { assert!(self.is_valid_install_method(install_method)); let exists = self.exists(); if exists { @@ -129,7 +128,7 @@ impl<'a> Toolchain<'a> { Ok(status) } - fn install_if_not_installed(&self, install_method: InstallMethod) -> Result { + fn install_if_not_installed(&self, install_method: InstallMethod<'_>) -> Result { assert!(self.is_valid_install_method(install_method)); (self.cfg.notify_handler)(Notification::LookingForToolchain(&self.name)); if !self.exists() { @@ -139,7 +138,7 @@ impl<'a> Toolchain<'a> { Ok(UpdateStatus::Unchanged) } } - fn is_valid_install_method(&self, install_method: InstallMethod) -> bool { + fn is_valid_install_method(&self, install_method: InstallMethod<'_>) -> bool { match install_method { InstallMethod::Copy(_) | InstallMethod::Link(_) | InstallMethod::Installer(..) => { self.is_custom() @@ -155,7 +154,7 @@ impl<'a> Toolchain<'a> { } } - fn download_cfg(&self) -> DownloadCfg { + fn download_cfg(&self) -> DownloadCfg<'_> { DownloadCfg { dist_root: &self.cfg.dist_root_url, temp_cfg: &self.cfg.temp_cfg, @@ -361,7 +360,7 @@ impl<'a> Toolchain<'a> { pub fn create_fallback_command>( &self, binary: T, - primary_toolchain: &Toolchain, + primary_toolchain: &Toolchain<'_>, ) -> Result { // With the hacks below this only works for cargo atm assert!(binary.as_ref() == "cargo" || binary.as_ref() == "cargo.exe"); diff --git a/tests/cli-exact.rs b/tests/cli-exact.rs index c8b5e399f8..850396c35d 100644 --- a/tests/cli-exact.rs +++ b/tests/cli-exact.rs @@ -1,11 +1,6 @@ //! Yet more cli test cases. These are testing that the output //! is exactly as expected. -extern crate rustup_dist; -extern crate rustup_mock; -extern crate rustup_utils; -extern crate tempdir; - use rustup_mock::clitools::{ self, expect_err_ex, expect_ok, expect_ok_ex, this_host_triple, Config, Scenario, }; @@ -16,7 +11,7 @@ macro_rules! for_host { }; } -fn setup(f: &Fn(&mut Config)) { +fn setup(f: &dyn Fn(&mut Config)) { clitools::setup(Scenario::SimpleV2, f); } diff --git a/tests/cli-inst-interactive.rs b/tests/cli-inst-interactive.rs index 3b52015522..a6a3403787 100644 --- a/tests/cli-inst-interactive.rs +++ b/tests/cli-inst-interactive.rs @@ -1,18 +1,13 @@ //! Tests of the interactive console installer -#[macro_use] -extern crate lazy_static; -extern crate rustup_mock; -extern crate rustup_utils; -extern crate scopeguard; - +use lazy_static::lazy_static; use rustup_mock::clitools::{self, expect_stdout_ok, Config, SanitizedOutput, Scenario}; use rustup_mock::{get_path, restore_path}; use std::io::Write; use std::process::Stdio; use std::sync::Mutex; -pub fn setup(f: &Fn(&Config)) { +pub fn setup(f: &dyn Fn(&Config)) { clitools::setup(Scenario::SimpleV2, &|config| { // Lock protects environment variables lazy_static! { diff --git a/tests/cli-misc.rs b/tests/cli-misc.rs index d51ee4ad8c..94fdcb9124 100644 --- a/tests/cli-misc.rs +++ b/tests/cli-misc.rs @@ -1,12 +1,6 @@ //! Test cases of the rustup command that do not depend on the //! dist server, mostly derived from multirust/test-v2.sh -extern crate rustup_dist; -extern crate rustup_mock; -extern crate rustup_utils; -extern crate tempdir; -extern crate time; - use rustup_dist::errors::TOOLSTATE_MSG; use rustup_mock::clitools::{ self, expect_err, expect_ok, expect_ok_ex, expect_stderr_ok, expect_stdout_ok, @@ -27,7 +21,7 @@ macro_rules! for_host { }; } -pub fn setup(f: &Fn(&mut Config)) { +pub fn setup(f: &dyn Fn(&mut Config)) { clitools::setup(Scenario::SimpleV2, f); } diff --git a/tests/cli-rustup.rs b/tests/cli-rustup.rs index 8a4aafd762..63dbfec7f8 100644 --- a/tests/cli-rustup.rs +++ b/tests/cli-rustup.rs @@ -1,10 +1,5 @@ //! Test cases for new rustup UI -extern crate rustup_dist; -extern crate rustup_mock; -extern crate rustup_utils; -extern crate tempdir; - use rustup_mock::clitools::{ self, expect_err, expect_ok, expect_ok_ex, expect_stderr_ok, expect_stdout_ok, run, set_current_dist_date, this_host_triple, Config, Scenario, @@ -21,7 +16,7 @@ macro_rules! for_host { }; } -pub fn setup(f: &Fn(&Config)) { +pub fn setup(f: &dyn Fn(&Config)) { clitools::setup(Scenario::ArchivesV2, &|config| { f(config); }); diff --git a/tests/cli-self-upd.rs b/tests/cli-self-upd.rs index f222520d2e..7cecf69dd2 100644 --- a/tests/cli-self-upd.rs +++ b/tests/cli-self-upd.rs @@ -4,19 +4,7 @@ // The `self update` and `self uninstall` commands just call `msiexec`. #![cfg(not(feature = "msi-installed"))] -#[macro_use] -extern crate lazy_static; -extern crate remove_dir_all; -extern crate rustup_mock; -extern crate rustup_utils; -extern crate scopeguard; -extern crate tempdir; - -#[cfg(windows)] -extern crate winapi; -#[cfg(windows)] -extern crate winreg; - +use lazy_static::lazy_static; use remove_dir_all::remove_dir_all; use rustup_mock::clitools::{ self, expect_err, expect_err_ex, expect_ok, expect_ok_contains, expect_ok_ex, expect_stderr_ok, @@ -41,7 +29,7 @@ macro_rules! for_host { const TEST_VERSION: &'static str = "1.1.1"; -pub fn setup(f: &Fn(&Config)) { +pub fn setup(f: &dyn Fn(&Config)) { clitools::setup(Scenario::SimpleV2, &|config| { // Lock protects environment variables lazy_static! { @@ -58,7 +46,7 @@ pub fn setup(f: &Fn(&Config)) { }); } -pub fn update_setup(f: &Fn(&Config, &Path)) { +pub fn update_setup(f: &dyn Fn(&Config, &Path)) { setup(&|config| { // Create a mock self-update server let ref self_dist_tmp = TempDir::new("self_dist").unwrap(); diff --git a/tests/cli-v1.rs b/tests/cli-v1.rs index 0876f8dfa3..03592ea4dc 100644 --- a/tests/cli-v1.rs +++ b/tests/cli-v1.rs @@ -1,11 +1,6 @@ //! Test cases of the rustup command, using v1 manifests, mostly //! derived from multirust/test-v2.sh -extern crate rustup_dist; -extern crate rustup_mock; -extern crate rustup_utils; -extern crate tempdir; - use rustup_mock::clitools::{ self, expect_err, expect_ok, expect_stderr_ok, expect_stdout_ok, set_current_dist_date, this_host_triple, Config, Scenario, @@ -19,7 +14,7 @@ macro_rules! for_host { }; } -pub fn setup(f: &Fn(&mut Config)) { +pub fn setup(f: &dyn Fn(&mut Config)) { clitools::setup(Scenario::SimpleV1, f); } diff --git a/tests/cli-v2.rs b/tests/cli-v2.rs index 47a49f3181..0d893ac59b 100644 --- a/tests/cli-v2.rs +++ b/tests/cli-v2.rs @@ -1,11 +1,6 @@ //! Test cases of the rustup command, using v2 manifests, mostly //! derived from multirust/test-v2.sh -extern crate rustup_dist; -extern crate rustup_mock; -extern crate rustup_utils; -extern crate tempdir; - use rustup_mock::clitools::{ self, expect_err, expect_not_stdout_ok, expect_ok, expect_stderr_ok, expect_stdout_ok, set_current_dist_date, this_host_triple, Config, Scenario, @@ -21,7 +16,7 @@ macro_rules! for_host { }; } -pub fn setup(f: &Fn(&mut Config)) { +pub fn setup(f: &dyn Fn(&mut Config)) { clitools::setup(Scenario::SimpleV2, f); }