From a83c30516d50e283b665a270ea73ac28c8fe5998 Mon Sep 17 00:00:00 2001 From: Daniel Levin Date: Tue, 14 Jan 2025 16:06:22 +0200 Subject: [PATCH] Use Rust 2021 edition. (#152) --- Cargo.toml | 1 + src/download/Cargo.toml | 1 + src/download/src/errors.rs | 2 + src/download/src/lib.rs | 29 +++---- src/elan-cli/common.rs | 11 ++- src/elan-cli/download_tracker.rs | 5 +- src/elan-cli/elan_mode.rs | 50 +++++++----- src/elan-cli/errors.rs | 3 +- src/elan-cli/job.rs | 2 - src/elan-cli/json_dump.rs | 37 ++++++--- src/elan-cli/log.rs | 10 +-- src/elan-cli/main.rs | 36 +-------- src/elan-cli/proxy_mode.rs | 8 +- src/elan-cli/self_update.rs | 43 +++++----- src/elan-cli/setup_mode.rs | 6 +- src/elan-cli/term2.rs | 5 +- src/elan-dist/Cargo.toml | 1 + src/elan-dist/src/component/package.rs | 7 +- src/elan-dist/src/config.rs | 2 +- src/elan-dist/src/dist.rs | 59 ++++++++------ src/elan-dist/src/download.rs | 8 +- src/elan-dist/src/errors.rs | 5 +- src/elan-dist/src/lib.rs | 26 +----- src/elan-dist/src/manifest.rs | 2 +- src/elan-dist/src/manifestation.rs | 23 +++--- src/elan-dist/src/notifications.rs | 15 ++-- src/elan-dist/src/temp.rs | 18 ++--- src/elan-utils/Cargo.toml | 1 + src/elan-utils/src/errors.rs | 3 +- src/elan-utils/src/lib.rs | 22 +---- src/elan-utils/src/notifications.rs | 8 +- src/elan-utils/src/raw.rs | 4 +- src/elan-utils/src/toml_utils.rs | 2 +- src/elan-utils/src/utils.rs | 46 ++++++----- src/elan/command.rs | 2 +- src/elan/config.rs | 52 +++++++----- src/elan/errors.rs | 4 +- src/elan/gc.rs | 28 +++++-- src/elan/install.rs | 8 +- src/elan/lib.rs | 19 +---- src/elan/notifications.rs | 22 ++--- src/elan/settings.rs | 20 +++-- src/elan/toolchain.rs | 106 ++++++++++++++++++------- 43 files changed, 397 insertions(+), 365 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f0c8976..129c4f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ name = "elan" version = "4.0.0-pre" authors = [ "Sebastian Ullrich " ] description = "Manage multiple Lean installations with ease" +edition = "2021" publish = false license = "MIT OR Apache-2.0" diff --git a/src/download/Cargo.toml b/src/download/Cargo.toml index ca4544f..51f44bd 100644 --- a/src/download/Cargo.toml +++ b/src/download/Cargo.toml @@ -3,6 +3,7 @@ name = "download" version = "0.4.0" authors = [ "Brian Anderson " ] +edition = "2021" license = "MIT/Apache-2.0" diff --git a/src/download/src/errors.rs b/src/download/src/errors.rs index f1a228a..14f337f 100644 --- a/src/download/src/errors.rs +++ b/src/download/src/errors.rs @@ -1,3 +1,5 @@ +use error_chain::error_chain; + error_chain! { links { } diff --git a/src/download/src/lib.rs b/src/download/src/lib.rs index 95c1291..972c463 100644 --- a/src/download/src/lib.rs +++ b/src/download/src/lib.rs @@ -1,14 +1,11 @@ //! Easy file downloading - -#[macro_use] -extern crate error_chain; -extern crate url; +#![deny(rust_2018_idioms)] use std::path::Path; use url::Url; mod errors; -pub use errors::*; +pub use crate::errors::*; #[derive(Debug, Copy, Clone)] pub enum Backend { @@ -26,7 +23,7 @@ pub enum Event<'a> { fn download_with_backend( backend: Backend, url: &Url, - callback: &dyn Fn(Event) -> Result<()>, + callback: &dyn Fn(Event<'_>) -> Result<()>, ) -> Result<()> { match backend { Backend::Curl => curl::download(url, callback), @@ -37,7 +34,7 @@ pub fn download_to_path_with_backend( backend: Backend, url: &Url, path: &Path, - callback: Option<&dyn Fn(Event) -> Result<()>>, + callback: Option<&dyn Fn(Event<'_>) -> Result<()>>, ) -> Result<()> { use std::cell::RefCell; use std::fs::OpenOptions; @@ -47,7 +44,7 @@ pub fn download_to_path_with_backend( let file = OpenOptions::new() .write(true) .create(true) - .open(&path) + .open(path) .chain_err(|| "error creating file for download")?; let file = RefCell::new(file); @@ -70,10 +67,6 @@ pub fn download_to_path_with_backend( Ok(()) }() - .map_err(|e| { - // TODO is there any point clearing up here? What kind of errors will leave us with an unusable partial? - e - }) } /// Download via libcurl; encrypt with the native (or OpenSSl) TLS @@ -81,11 +74,9 @@ pub fn download_to_path_with_backend( #[cfg(feature = "curl-backend")] pub mod curl { - extern crate curl; - - use self::curl::easy::Easy; use super::Event; - use errors::*; + use crate::errors::*; + use curl::easy::Easy; use std::cell::RefCell; use std::str; use std::time::Duration; @@ -93,7 +84,7 @@ pub mod curl { thread_local!(pub static EASY: RefCell = RefCell::new(Easy::new())); - pub fn download(url: &Url, callback: &dyn Fn(Event) -> Result<()>) -> Result<()> { + pub fn download(url: &Url, 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. // @@ -102,9 +93,7 @@ pub mod curl { EASY.with(|handle| { let mut handle = handle.borrow_mut(); - handle - .url(&url.to_string()) - .chain_err(|| "failed to set url")?; + handle.url(url.as_ref()).chain_err(|| "failed to set url")?; handle .follow_location(true) .chain_err(|| "failed to set follow redirects")?; diff --git a/src/elan-cli/common.rs b/src/elan-cli/common.rs index b53623b..3423142 100644 --- a/src/elan-cli/common.rs +++ b/src/elan-cli/common.rs @@ -1,17 +1,16 @@ //! Just a dumping ground for cli stuff +use crate::errors::*; +use crate::term2; use elan::{Cfg, Notification, Toolchain}; use elan_dist::dist::ToolchainDesc; use elan_utils::notify::NotificationLevel; use elan_utils::utils; -use errors::*; -use std; use std::io::{BufRead, BufReader, Write}; use std::path::Path; use std::process::{Command, Stdio}; use std::sync::Arc; use std::time::Duration; -use term2; use wait_timeout::ChildExt; pub fn confirm(question: &str, default: bool) -> Result { @@ -101,12 +100,12 @@ pub fn read_line() -> Result { } pub fn set_globals(verbose: bool) -> Result { - use download_tracker::DownloadTracker; + use crate::download_tracker::DownloadTracker; use std::cell::RefCell; 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; } @@ -153,7 +152,7 @@ pub fn show_channel_update(cfg: &Cfg, desc: &ToolchainDesc) -> Result<()> { Ok(()) } -pub fn lean_version(toolchain: &Toolchain) -> String { +pub fn lean_version(toolchain: &Toolchain<'_>) -> String { if toolchain.exists() { let lean_path = toolchain.binary_file("lean"); if utils::is_file(&lean_path) { diff --git a/src/elan-cli/download_tracker.rs b/src/elan-cli/download_tracker.rs index c1f13c0..f53578c 100644 --- a/src/elan-cli/download_tracker.rs +++ b/src/elan-cli/download_tracker.rs @@ -4,7 +4,6 @@ use elan_utils::tty; use elan_utils::Notification as Un; use std::collections::VecDeque; use std::fmt; -use term; use time::OffsetDateTime; /// Keep track of this many past download amounts @@ -53,7 +52,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); @@ -178,7 +177,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/elan-cli/elan_mode.rs b/src/elan-cli/elan_mode.rs index c883abb..e50ed8a 100644 --- a/src/elan-cli/elan_mode.rs +++ b/src/elan-cli/elan_mode.rs @@ -1,23 +1,23 @@ +use crate::common; +use crate::errors::*; +use crate::help::*; +use crate::self_update; +use crate::term2; use clap::{App, AppSettings, Arg, ArgMatches, Shell, SubCommand}; -use common; use elan::{command, gc, lookup_toolchain_desc, lookup_unresolved_toolchain_desc, Cfg, Toolchain}; use elan_dist::dist::ToolchainDesc; use elan_utils::utils; -use errors::*; -use help::*; -use self_update; use std::error::Error; use std::io::{self, Write}; use std::path::Path; use std::process::Command; -use term2; use serde_derive::Serialize; use crate::json_dump; pub fn main() -> Result<()> { - ::self_update::cleanup_self_updater()?; + crate::self_update::cleanup_self_updater()?; let matches = &cli().get_matches(); let verbose = matches.is_present("verbose"); @@ -59,7 +59,7 @@ pub fn main() -> Result<()> { &mut io::stdout(), ); } - }, + } ("dump-state", Some(m)) => dump_state(cfg, m)?, (_, _) => unreachable!(), } @@ -249,7 +249,7 @@ pub fn cli() -> App<'static, 'static> { ) } -fn default_(cfg: &Cfg, m: &ArgMatches) -> Result<()> { +fn default_(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { let name = m.value_of("toolchain").expect(""); // sanity-check let _ = lookup_unresolved_toolchain_desc(cfg, name)?; @@ -258,7 +258,7 @@ fn default_(cfg: &Cfg, m: &ArgMatches) -> Result<()> { Ok(()) } -fn install(cfg: &Cfg, m: &ArgMatches) -> Result<()> { +fn install(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { let names = m.values_of("toolchain").expect(""); for name in names { let desc = lookup_toolchain_desc(cfg, name)?; @@ -274,7 +274,7 @@ fn install(cfg: &Cfg, m: &ArgMatches) -> Result<()> { Ok(()) } -fn run(cfg: &Cfg, m: &ArgMatches) -> Result<()> { +fn run(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { let toolchain = m.value_of("toolchain").expect(""); let args = m.values_of("command").unwrap(); let args: Vec<_> = args.collect(); @@ -284,7 +284,7 @@ fn run(cfg: &Cfg, m: &ArgMatches) -> Result<()> { Ok(command::run_command_for_dir(cmd, args[0], &args[1..])?) } -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 @@ -415,7 +415,7 @@ fn show(cfg: &Cfg) -> 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 desc = lookup_toolchain_desc(cfg, toolchain)?; @@ -429,7 +429,7 @@ fn explicit_or_dir_toolchain<'a>(cfg: &'a Cfg, m: &ArgMatches) -> Result Result<()> { +fn toolchain_link(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { let toolchain = &m.value_of("toolchain").expect(""); let path = &m.value_of("path").expect(""); let desc = ToolchainDesc::Local { @@ -440,7 +440,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 desc = lookup_toolchain_desc(cfg, toolchain)?; let toolchain = cfg.get_toolchain(&desc, false)?; @@ -468,7 +468,10 @@ fn toolchain_gc(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { let json = m.is_present("json"); if json { let result = GCResult { - unused_toolchains: unused_toolchains.iter().map(|t| t.desc.to_string()).collect(), + unused_toolchains: unused_toolchains + .iter() + .map(|t| t.desc.to_string()) + .collect(), used_toolchains: used_toolchains .iter() .map(|(root, tc)| UsedToolchain { @@ -477,7 +480,10 @@ fn toolchain_gc(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { }) .collect(), }; - println!("{}", serde_json::to_string_pretty(&result).chain_err(|| "failed to print JSON")?); + println!( + "{}", + serde_json::to_string_pretty(&result).chain_err(|| "failed to print JSON")? + ); return Ok(()); } @@ -504,7 +510,7 @@ fn toolchain_gc(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { Ok(()) } -fn override_add(cfg: &Cfg, m: &ArgMatches) -> Result<()> { +fn override_add(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { let toolchain = m.value_of("toolchain").expect(""); let desc = lookup_toolchain_desc(cfg, toolchain)?; let toolchain = cfg.get_toolchain(&desc, false)?; @@ -512,7 +518,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 @@ -555,7 +561,7 @@ fn override_remove(cfg: &Cfg, m: &ArgMatches) -> Result<()> { Ok(()) } -fn doc(cfg: &Cfg, m: &ArgMatches) -> Result<()> { +fn doc(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { let doc_url = if m.is_present("book") { "book/index.html" } else if m.is_present("std") { @@ -567,7 +573,7 @@ fn doc(cfg: &Cfg, m: &ArgMatches) -> Result<()> { Ok(cfg.open_docs_for_dir(&utils::current_dir()?, doc_url)?) } -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(); @@ -583,13 +589,13 @@ 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) } -fn dump_state(cfg: &Cfg, m: &ArgMatches) -> Result<()> { +fn dump_state(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { let no_net = m.is_present("no-net"); Ok(json_dump::StateDump::new(cfg, no_net)?.print()?) diff --git a/src/elan-cli/errors.rs b/src/elan-cli/errors.rs index 1a3f14b..a9bc62f 100644 --- a/src/elan-cli/errors.rs +++ b/src/elan-cli/errors.rs @@ -3,9 +3,8 @@ use std::io; use std::path::PathBuf; -use elan; use elan_dist::{self, temp}; -use elan_utils; +use error_chain::error_chain; error_chain! { links { diff --git a/src/elan-cli/job.rs b/src/elan-cli/job.rs index 61c59be..d7c43c9 100644 --- a/src/elan-cli/job.rs +++ b/src/elan-cli/job.rs @@ -34,8 +34,6 @@ mod imp { #[cfg(windows)] mod imp { - extern crate winapi; - use std::ffi::OsString; use std::io; use std::mem; diff --git a/src/elan-cli/json_dump.rs b/src/elan-cli/json_dump.rs index 2a35f79..e155776 100644 --- a/src/elan-cli/json_dump.rs +++ b/src/elan-cli/json_dump.rs @@ -1,4 +1,8 @@ -use elan::{lookup_unresolved_toolchain_desc, resolve_toolchain_desc_ext, utils::{self, fetch_latest_release_tag}, Cfg, Toolchain, UnresolvedToolchainDesc}; +use elan::{ + lookup_unresolved_toolchain_desc, resolve_toolchain_desc_ext, + utils::{self, fetch_latest_release_tag}, + Cfg, Toolchain, UnresolvedToolchainDesc, +}; use std::{io, path::PathBuf}; use serde_derive::Serialize; @@ -61,33 +65,46 @@ pub struct StateDump { toolchains: Toolchains, } -fn mk_toolchain_resolution(cfg: &Cfg, unresolved: &UnresolvedToolchainDesc, no_net: bool) -> ToolchainResolution { - let live = resolve_toolchain_desc_ext(cfg, unresolved, no_net, false).map(|t| t.to_string()).map_err(|e| e.to_string()); - let cached = resolve_toolchain_desc_ext(cfg, unresolved, true, true).map(|t| t.to_string()).map_err(|e| e.to_string()).ok(); +fn mk_toolchain_resolution( + cfg: &Cfg, + unresolved: &UnresolvedToolchainDesc, + no_net: bool, +) -> ToolchainResolution { + let live = resolve_toolchain_desc_ext(cfg, unresolved, no_net, false) + .map(|t| t.to_string()) + .map_err(|e| e.to_string()); + let cached = resolve_toolchain_desc_ext(cfg, unresolved, true, true) + .map(|t| t.to_string()) + .map_err(|e| e.to_string()) + .ok(); ToolchainResolution { live, cached } } impl StateDump { pub fn new(cfg: &Cfg, no_net: bool) -> crate::Result { let newest = fetch_latest_release_tag("leanprover/elan", no_net); - let ref cwd = utils::current_dir()?; + let cwd = &(utils::current_dir()?); let active_override = cfg.find_override(cwd)?; let default = match cfg.get_default()? { None => None, - Some(d) => Some(lookup_unresolved_toolchain_desc(cfg, &d)?) + Some(d) => Some(lookup_unresolved_toolchain_desc(cfg, &d)?), }; Ok(StateDump { elan_version: Version { current: env!("CARGO_PKG_VERSION").to_string(), - newest: newest.map(|s| s.trim_start_matches('v').to_string()).map_err(|e| e.to_string()), + newest: newest + .map(|s| s.trim_start_matches('v').to_string()) + .map_err(|e| e.to_string()), }, toolchains: Toolchains { - installed: cfg.list_toolchains()? + installed: cfg + .list_toolchains()? .into_iter() .map(|t| InstalledToolchain { resolved_name: t.to_string(), path: Toolchain::from(cfg, &t).path().to_owned(), - }).collect(), + }) + .collect(), default: default.as_ref().map(|default| DefaultToolchain { unresolved: default.clone(), resolved: mk_toolchain_resolution(cfg, default, no_net), @@ -99,7 +116,7 @@ impl StateDump { resolved_active: active_override .map(|p| p.0) .or(default) - .map(|t| mk_toolchain_resolution(cfg, &t, no_net)) + .map(|t| mk_toolchain_resolution(cfg, &t, no_net)), }, }) } diff --git a/src/elan-cli/log.rs b/src/elan-cli/log.rs index 3adeb7d..d40dc9c 100644 --- a/src/elan-cli/log.rs +++ b/src/elan-cli/log.rs @@ -1,6 +1,6 @@ +use crate::term2; use std::fmt; use std::io::Write; -use term2; macro_rules! warn { ( $ ( $ arg : tt ) * ) => ( $crate::log::warn_fmt ( format_args ! ( $ ( $ arg ) * ) ) ) @@ -16,7 +16,7 @@ macro_rules! verbose { ( $ ( $ arg : tt ) * ) => ( $crate::log::verbose_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); @@ -26,7 +26,7 @@ pub fn warn_fmt(args: fmt::Arguments) { let _ = writeln!(t); } -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); @@ -36,7 +36,7 @@ pub fn err_fmt(args: fmt::Arguments) { let _ = writeln!(t); } -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: "); @@ -45,7 +45,7 @@ pub fn info_fmt(args: fmt::Arguments) { let _ = writeln!(t); } -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); diff --git a/src/elan-cli/main.rs b/src/elan-cli/main.rs index 5f8c871..e33bd2f 100644 --- a/src/elan-cli/main.rs +++ b/src/elan-cli/main.rs @@ -13,39 +13,7 @@ //! different name. #![recursion_limit = "1024"] - -extern crate elan_dist; -extern crate elan_utils; -#[macro_use] -extern crate error_chain; - -extern crate clap; -extern crate elan; -extern crate flate2; -extern crate itertools; -extern crate json; -extern crate markdown; -extern crate rand; -extern crate regex; -extern crate same_file; -extern crate scopeguard; -extern crate sha2; -extern crate tar; -extern crate tempfile; -extern crate term; -extern crate time; -extern crate toml; -extern crate wait_timeout; -extern crate zip; -extern crate serde_derive; - -#[cfg(windows)] -extern crate gcc; -extern crate libc; -#[cfg(windows)] -extern crate winapi; -#[cfg(windows)] -extern crate winreg; +#![deny(rust_2018_idioms)] #[macro_use] mod log; @@ -55,11 +23,11 @@ mod elan_mode; mod errors; mod help; mod job; +mod json_dump; mod proxy_mode; mod self_update; mod setup_mode; mod term2; -mod json_dump; use elan::env_var::LEAN_RECURSION_COUNT_MAX; use errors::*; diff --git a/src/elan-cli/proxy_mode.rs b/src/elan-cli/proxy_mode.rs index 3400881..04f9492 100644 --- a/src/elan-cli/proxy_mode.rs +++ b/src/elan-cli/proxy_mode.rs @@ -1,15 +1,15 @@ -use common::set_globals; +use crate::common::set_globals; +use crate::errors::*; +use crate::job; use elan::command::run_command_for_dir; use elan::{lookup_toolchain_desc, Cfg}; use elan_utils::utils; -use errors::*; -use job; use std::env; use std::ffi::OsString; use std::path::PathBuf; pub fn main() -> Result<()> { - ::self_update::cleanup_self_updater()?; + crate::self_update::cleanup_self_updater()?; let _setup = job::setup(); diff --git a/src/elan-cli/self_update.rs b/src/elan-cli/self_update.rs index bfda21c..37100a6 100644 --- a/src/elan-cli/self_update.rs +++ b/src/elan-cli/self_update.rs @@ -30,7 +30,9 @@ //! Deleting the running binary during uninstall is tricky //! and racy on Windows. -use common::{self, Confirm}; +use crate::common::{self, Confirm}; +use crate::errors::*; +use crate::term2; use elan::install; use elan::lookup_toolchain_desc; use elan::lookup_unresolved_toolchain_desc; @@ -39,8 +41,6 @@ use elan::Toolchain; use elan_dist::dist; use elan_dist::dist::ToolchainDesc; use elan_utils::utils; -use errors::*; -use flate2; use regex::Regex; use same_file::Handle; use std::env; @@ -49,10 +49,7 @@ use std::fs; use std::io; use std::path::{Component, Path, PathBuf}; use std::process::{self, Command}; -use tar; use tempfile::tempdir; -use term2; -use zip; pub struct InstallOpts { pub default_toolchain: String, @@ -208,11 +205,21 @@ fn clean_up_old_state() -> Result<()> { for tc in cfg.list_toolchains()? { let res = lookup_unresolved_toolchain_desc(cfg, &tc.to_string()); if let Ok(desc) = res { - if desc.0 == tc && !matches!(desc.0, ToolchainDesc::Remote { from_channel: Some(_), .. }) { continue; } + if desc.0 == tc + && !matches!( + desc.0, + ToolchainDesc::Remote { + from_channel: Some(_), + .. + } + ) + { + continue; + } } let t = Toolchain::from(cfg, &tc); - (cfg.notify_handler)(Notification::UninstallingObsoleteToolchain(&t.path())); - install::uninstall(&t.path(), &|n| (cfg.notify_handler)(n.into()))?; + (cfg.notify_handler)(Notification::UninstallingObsoleteToolchain(t.path())); + install::uninstall(t.path(), &|n| (cfg.notify_handler)(n.into()))?; } Ok(()) } @@ -348,7 +355,7 @@ fn check_existence_of_lean_in_path(no_prompt: bool) -> 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::ffi::CStr; use std::mem::MaybeUninit; @@ -493,7 +500,7 @@ fn customize_install(mut opts: InstallOpts) -> Result { fn install_bins() -> Result<()> { let bin_path = &utils::elan_home()?.join("bin"); let this_exe_path = &(utils::current_exe()?); - let elan_path = &bin_path.join(&format!("elan{}", EXE_SUFFIX)); + let elan_path = &bin_path.join(format!("elan{}", EXE_SUFFIX)); utils::ensure_dir_exists("bin", bin_path, &|_| {})?; // NB: Even on Linux we can't just copy the new binary over the (running) @@ -508,7 +515,7 @@ fn install_bins() -> Result<()> { pub fn install_proxies() -> Result<()> { let bin_path = &utils::elan_home()?.join("bin"); - let elan_path = &bin_path.join(&format!("elan{}", EXE_SUFFIX)); + let elan_path = &bin_path.join(format!("elan{}", EXE_SUFFIX)); let elan = Handle::from_path(elan_path)?; @@ -537,7 +544,7 @@ pub fn install_proxies() -> Result<()> { // `tool_handles` later on. This'll allow us, afterwards, to actually // overwrite all the previous hard links with new ones. for tool in TOOLS { - let tool_path = bin_path.join(&format!("{}{}", tool, EXE_SUFFIX)); + let tool_path = bin_path.join(format!("{}{}", tool, EXE_SUFFIX)); if let Ok(handle) = Handle::from_path(&tool_path) { tool_handles.push(handle); if elan == *tool_handles.last().unwrap() { @@ -576,7 +583,7 @@ pub fn uninstall(no_prompt: bool) -> Result<()> { let elan_home = &(utils::elan_home()?); - if !elan_home.join(&format!("bin/elan{}", EXE_SUFFIX)).exists() { + if !elan_home.join(format!("bin/elan{}", EXE_SUFFIX)).exists() { return Err(ErrorKind::NotSelfInstalled(elan_home.clone()).into()); } @@ -1231,8 +1238,8 @@ fn parse_new_elan_version(version: String) -> String { pub fn prepare_update() -> Result> { let elan_home = &(utils::elan_home()?); - let elan_path = &elan_home.join(&format!("bin/elan{}", EXE_SUFFIX)); - let setup_path = &elan_home.join(&format!("bin/elan-init{}", EXE_SUFFIX)); + let elan_path = &elan_home.join(format!("bin/elan{}", EXE_SUFFIX)); + let setup_path = &elan_home.join(format!("bin/elan-init{}", EXE_SUFFIX)); if !elan_path.exists() { return Err(ErrorKind::NotSelfInstalled(elan_home.clone()).into()); @@ -1343,14 +1350,14 @@ pub fn self_replace() -> Result<()> { pub fn cleanup_self_updater() -> Result<()> { let elan_home = utils::elan_home()?; - let setup = &elan_home.join(&format!("bin/elan-init{}", EXE_SUFFIX)); + let setup = &elan_home.join(format!("bin/elan-init{}", EXE_SUFFIX)); if setup.exists() { utils::remove_file("setup", setup)?; } // Transitional - let old_setup = &elan_home.join(&format!("bin/multilean-setup{}", EXE_SUFFIX)); + let old_setup = &elan_home.join(format!("bin/multilean-setup{}", EXE_SUFFIX)); if old_setup.exists() { utils::remove_file("setup", old_setup)?; diff --git a/src/elan-cli/setup_mode.rs b/src/elan-cli/setup_mode.rs index aae92ec..2b07895 100644 --- a/src/elan-cli/setup_mode.rs +++ b/src/elan-cli/setup_mode.rs @@ -1,7 +1,7 @@ +use crate::common; +use crate::errors::*; +use crate::self_update::{self, InstallOpts}; use clap::{App, AppSettings, Arg}; -use common; -use errors::*; -use self_update::{self, InstallOpts}; use std::env; pub fn main() -> Result<()> { diff --git a/src/elan-cli/term2.rs b/src/elan-cli/term2.rs index 311ab5f..260c510 100644 --- a/src/elan-cli/term2.rs +++ b/src/elan-cli/term2.rs @@ -6,7 +6,6 @@ use elan_utils::tty; use markdown::tokenize; use markdown::{Block, ListItem, Span}; use std::io; -use term; pub use term::color; pub use term::Attr; @@ -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/elan-dist/Cargo.toml b/src/elan-dist/Cargo.toml index c03ff98..7292c00 100644 --- a/src/elan-dist/Cargo.toml +++ b/src/elan-dist/Cargo.toml @@ -5,6 +5,7 @@ version = "1.11.0" authors = [ "Sebastian Ullrich " ] description = "Installation from a Lean distribution server" build = "build.rs" +edition = "2021" license = "MIT OR Apache-2.0" diff --git a/src/elan-dist/src/component/package.rs b/src/elan-dist/src/component/package.rs index 4c14331..9ce3a21 100644 --- a/src/elan-dist/src/component/package.rs +++ b/src/elan-dist/src/component/package.rs @@ -2,12 +2,7 @@ //! for installing from a directory or tarball to an installation //! prefix, represented by a `Components` instance. -extern crate filetime; -extern crate flate2; -extern crate tar; -extern crate zstd; - -use errors::*; +use crate::errors::*; use std::fs::{self, File}; use std::io::{self, Read, Seek}; diff --git a/src/elan-dist/src/config.rs b/src/elan-dist/src/config.rs index f515d89..c7d9005 100644 --- a/src/elan-dist/src/config.rs +++ b/src/elan-dist/src/config.rs @@ -1,8 +1,8 @@ use toml; use super::manifest::Component; +use crate::errors::*; use elan_utils::toml_utils::*; -use errors::*; pub const SUPPORTED_CONFIG_VERSIONS: [&'static str; 1] = ["1"]; pub const DEFAULT_CONFIG_VERSION: &'static str = "1"; diff --git a/src/elan-dist/src/dist.rs b/src/elan-dist/src/dist.rs index 9c266a5..940e9d6 100644 --- a/src/elan-dist/src/dist.rs +++ b/src/elan-dist/src/dist.rs @@ -1,8 +1,11 @@ -use download::DownloadCfg; -use elan_utils::{self, utils::{self}}; -use errors::*; -use manifestation::Manifestation; -use prefix::InstallPrefix; +use crate::download::DownloadCfg; +use crate::errors::*; +use crate::manifestation::Manifestation; +use crate::prefix::InstallPrefix; +use elan_utils::{ + self, + utils::{self}, +}; use regex::Regex; use serde_derive::Serialize; @@ -37,7 +40,11 @@ impl ToolchainDesc { Some(origin) => { let origin = origin.as_str().to_owned(); let release = c.get(2).unwrap().as_str().to_owned(); - Ok(ToolchainDesc::Remote { origin, release, from_channel: None }) + Ok(ToolchainDesc::Remote { + origin, + release, + from_channel: None, + }) } None => { let name = c.get(2).unwrap().as_str().to_owned(); @@ -57,10 +64,12 @@ impl ToolchainDesc { } impl fmt::Display for ToolchainDesc { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { ToolchainDesc::Local { name } => write!(f, "{}", name), - ToolchainDesc::Remote { origin, release, .. } => write!(f, "{}:{}", origin, release), + ToolchainDesc::Remote { + origin, release, .. + } => write!(f, "{}:{}", origin, release), } } } @@ -73,29 +82,29 @@ pub fn install_from_dist<'a>( let toolchain_str = toolchain.to_string(); let manifestation = Manifestation::open(prefix.clone())?; - let ToolchainDesc::Remote { origin, release, .. } = toolchain else { + let ToolchainDesc::Remote { + origin, release, .. + } = toolchain + else { return Ok(()); }; let url = format!( "https://github.com/{}/releases/expanded_assets/{}", origin, release ); - let res = match manifestation.install( - &origin, - &url, - &download.temp_cfg, - download.notify_handler, - ) { - Ok(()) => Ok(()), - e @ Err(Error(ErrorKind::Utils(elan_utils::ErrorKind::DownloadNotExists { .. }), _)) => e - .chain_err(|| { - format!( - "could not download nonexistent lean version `{}`", - toolchain_str - ) - }), - Err(e) => Err(e), - }; + let res = + match manifestation.install(&origin, &url, &download.temp_cfg, download.notify_handler) { + Ok(()) => Ok(()), + e + @ Err(Error(ErrorKind::Utils(elan_utils::ErrorKind::DownloadNotExists { .. }), _)) => e + .chain_err(|| { + format!( + "could not download nonexistent lean version `{}`", + toolchain_str + ) + }), + Err(e) => Err(e), + }; // Don't leave behind an empty / broken installation directory if res.is_err() { diff --git a/src/elan-dist/src/download.rs b/src/elan-dist/src/download.rs index c146c44..efaa6f5 100644 --- a/src/elan-dist/src/download.rs +++ b/src/elan-dist/src/download.rs @@ -1,7 +1,7 @@ +use crate::errors::*; +use crate::notifications::*; +use crate::temp; use elan_utils::utils; -use errors::*; -use notifications::*; -use temp; use std::ops; use std::path::{Path, PathBuf}; @@ -11,7 +11,7 @@ const _UPDATE_HASH_LEN: usize = 20; #[derive(Copy, Clone)] pub struct DownloadCfg<'a> { pub temp_cfg: &'a temp::Cfg, - pub notify_handler: &'a dyn Fn(Notification), + pub notify_handler: &'a dyn Fn(Notification<'_>), } pub struct File { diff --git a/src/elan-dist/src/errors.rs b/src/elan-dist/src/errors.rs index ed631d7..5a6ce9e 100644 --- a/src/elan-dist/src/errors.rs +++ b/src/elan-dist/src/errors.rs @@ -1,8 +1,9 @@ +use crate::manifest::Component; +use crate::temp; use elan_utils; -use manifest::Component; +use error_chain::error_chain; use std::io::{self, Write}; use std::path::PathBuf; -use temp; use time::error::ComponentRange; use toml; diff --git a/src/elan-dist/src/lib.rs b/src/elan-dist/src/lib.rs index 86fa9ce..30cd161 100644 --- a/src/elan-dist/src/lib.rs +++ b/src/elan-dist/src/lib.rs @@ -1,29 +1,5 @@ #![recursion_limit = "1024"] - -extern crate fslock; -extern crate elan_utils; -extern crate flate2; -extern crate itertools; -extern crate regex; -extern crate tar; -extern crate toml; -extern crate url; -extern crate walkdir; -#[macro_use] -extern crate error_chain; -extern crate json; -extern crate sha2; -extern crate time; -extern crate zip; -extern crate serde; -extern crate serde_derive; - -#[cfg(not(windows))] -extern crate libc; -#[cfg(windows)] -extern crate winapi; -#[cfg(windows)] -extern crate winreg; +#![deny(rust_2018_idioms)] pub use errors::*; pub use notifications::Notification; diff --git a/src/elan-dist/src/manifest.rs b/src/elan-dist/src/manifest.rs index eb8be23..dfd0351 100644 --- a/src/elan-dist/src/manifest.rs +++ b/src/elan-dist/src/manifest.rs @@ -10,8 +10,8 @@ //! //! See tests/channel-lean-nightly-example.toml for an example. +use crate::errors::*; use elan_utils::toml_utils::*; -use errors::*; use toml; #[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] diff --git a/src/elan-dist/src/manifestation.rs b/src/elan-dist/src/manifestation.rs index 4f20150..3b4764c 100644 --- a/src/elan-dist/src/manifestation.rs +++ b/src/elan-dist/src/manifestation.rs @@ -2,14 +2,14 @@ use std::{thread::sleep, time::Duration}; -use component::{TarGzPackage, TarZstdPackage, ZipPackage}; -use download::DownloadCfg; +use crate::component::{TarGzPackage, TarZstdPackage, ZipPackage}; +use crate::download::DownloadCfg; +use crate::errors::*; +use crate::notifications::*; +use crate::prefix::InstallPrefix; +use crate::temp; use elan_utils::{raw::read_file, utils}; -use errors::*; use fslock::LockFile; -use notifications::*; -use prefix::InstallPrefix; -use temp; #[derive(Debug)] pub struct Manifestation { @@ -26,7 +26,7 @@ impl Manifestation { origin: &String, url: &String, temp_cfg: &temp::Cfg, - notify_handler: &dyn Fn(Notification), + notify_handler: &dyn Fn(Notification<'_>), ) -> Result<()> { let prefix = self.prefix.path(); utils::ensure_dir_exists("toolchains", prefix.parent().unwrap(), &|n| { @@ -36,7 +36,10 @@ impl Manifestation { let lockfile_path = prefix.with_extension("lock"); let mut lockfile = LockFile::open(&lockfile_path)?; if !lockfile.try_lock_with_pid()? { - notify_handler(Notification::WaitingForFileLock(&lockfile_path, read_file(&lockfile_path)?.trim())); + notify_handler(Notification::WaitingForFileLock( + &lockfile_path, + read_file(&lockfile_path)?.trim(), + )); while !lockfile.try_lock_with_pid()? { sleep(Duration::from_secs(1)); } @@ -51,7 +54,7 @@ impl Manifestation { origin: &String, url: &String, temp_cfg: &temp::Cfg, - notify_handler: &dyn Fn(Notification), + notify_handler: &dyn Fn(Notification<'_>), ) -> Result<()> { let prefix = self.prefix.path(); let dlcfg = DownloadCfg { @@ -60,7 +63,7 @@ impl Manifestation { }; if utils::is_directory(prefix) { - return Ok(()) + return Ok(()); } // find correct download on HTML page (AAAAH) diff --git a/src/elan-dist/src/notifications.rs b/src/elan-dist/src/notifications.rs index f336f0a..6b9ada2 100644 --- a/src/elan-dist/src/notifications.rs +++ b/src/elan-dist/src/notifications.rs @@ -1,10 +1,10 @@ +use crate::errors::*; +use crate::manifest::Component; +use crate::temp; use elan_utils; use elan_utils::notify::NotificationLevel; -use errors::*; -use manifest::Component; use std::fmt::{self, Display}; use std::path::Path; -use temp; #[derive(Debug)] pub enum Notification<'a> { @@ -78,7 +78,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), @@ -128,7 +128,12 @@ impl<'a> Display for Notification<'a> { ) } WaitingForFileLock(path, pid) => { - write!(f, "waiting for previous installation request to finish ({}, held by PID {})", path.display(), pid) + write!( + f, + "waiting for previous installation request to finish ({}, held by PID {})", + path.display(), + pid + ) } } } diff --git a/src/elan-dist/src/temp.rs b/src/elan-dist/src/temp.rs index 2d5536c..e194847 100644 --- a/src/elan-dist/src/temp.rs +++ b/src/elan-dist/src/temp.rs @@ -1,5 +1,3 @@ -extern crate remove_dir_all; - use elan_utils::raw; use std::error; use std::fmt::{self, Display}; @@ -30,7 +28,7 @@ pub enum Notification<'a> { pub struct Cfg { root_directory: PathBuf, - notify_handler: Box, + notify_handler: Box)>, } #[derive(Debug)] @@ -62,7 +60,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()), @@ -107,7 +105,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: _ } => { @@ -124,7 +122,7 @@ impl Display for Error { } impl Cfg { - pub fn new(root_directory: PathBuf, notify_handler: Box) -> Self { + pub fn new(root_directory: PathBuf, notify_handler: Box)>) -> Self { Cfg { root_directory: root_directory, notify_handler: notify_handler, @@ -141,7 +139,7 @@ impl Cfg { }) } - pub fn new_directory(&self) -> Result { + pub fn new_directory(&self) -> Result> { self.create_root()?; loop { @@ -165,11 +163,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 { @@ -195,7 +193,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/elan-utils/Cargo.toml b/src/elan-utils/Cargo.toml index 2189d2c..6caaa6e 100644 --- a/src/elan-utils/Cargo.toml +++ b/src/elan-utils/Cargo.toml @@ -4,6 +4,7 @@ name = "elan-utils" version = "1.11.0" authors = [ "Sebastian Ullrich " ] description = "Utility functions for elan" +edition = "2021" license = "MIT OR Apache-2.0" diff --git a/src/elan-utils/src/errors.rs b/src/elan-utils/src/errors.rs index 7ac5d18..1a6c4a5 100644 --- a/src/elan-utils/src/errors.rs +++ b/src/elan-utils/src/errors.rs @@ -1,4 +1,5 @@ -use download; +use error_chain::error_chain; + use std::ffi::OsString; use std::io; use std::path::PathBuf; diff --git a/src/elan-utils/src/lib.rs b/src/elan-utils/src/lib.rs index b43a5c5..7bbb282 100644 --- a/src/elan-utils/src/lib.rs +++ b/src/elan-utils/src/lib.rs @@ -1,25 +1,5 @@ #![recursion_limit = "1024"] // for error_chain! - -extern crate rand; -extern crate scopeguard; -#[macro_use] -extern crate error_chain; -extern crate curl; -extern crate dirs; -extern crate download; -extern crate regex; -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; +#![deny(rust_2018_idioms)] pub mod errors; pub mod notifications; diff --git a/src/elan-utils/src/notifications.rs b/src/elan-utils/src/notifications.rs index d84e2f7..71f8322 100644 --- a/src/elan-utils/src/notifications.rs +++ b/src/elan-utils/src/notifications.rs @@ -3,7 +3,7 @@ use std::path::Path; use url::Url; -use notify::NotificationLevel; +use crate::notify::NotificationLevel; #[derive(Debug)] pub enum Notification<'a> { @@ -39,15 +39,13 @@ impl<'a> Notification<'a> { | ResumingPartialDownload | UsingCurl | UsingReqwest => NotificationLevel::Verbose, - UsingHyperDeprecated | NoCanonicalPath(_) => { - NotificationLevel::Warn - } + UsingHyperDeprecated | NoCanonicalPath(_) => NotificationLevel::Warn, } } } 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/elan-utils/src/raw.rs b/src/elan-utils/src/raw.rs index 1e62dbc..d08b41c 100644 --- a/src/elan-utils/src/raw.rs +++ b/src/elan-utils/src/raw.rs @@ -1,5 +1,3 @@ -extern crate remove_dir_all; - use std::char::from_u32; use std::env; use std::error; @@ -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/elan-utils/src/toml_utils.rs b/src/elan-utils/src/toml_utils.rs index a13d9ca..4b6f4ff 100644 --- a/src/elan-utils/src/toml_utils.rs +++ b/src/elan-utils/src/toml_utils.rs @@ -1,4 +1,4 @@ -use errors::*; +use crate::errors::*; use toml; pub fn get_value(table: &mut toml::value::Table, key: &str, path: &str) -> Result { diff --git a/src/elan-utils/src/utils.rs b/src/elan-utils/src/utils.rs index d1b63f0..32a0774 100644 --- a/src/elan-utils/src/utils.rs +++ b/src/elan-utils/src/utils.rs @@ -1,7 +1,6 @@ +use crate::errors::*; +use crate::notifications::Notification; use dirs; -use errors::*; -use notifications::Notification; -use raw; use std::cmp::Ord; use std::env; use std::ffi::OsString; @@ -13,14 +12,16 @@ use url::Url; #[cfg(windows)] use winreg; -pub use raw::{ +use crate::raw; + +pub use crate::raw::{ find_cmd, has_cmd, if_not_empty, is_directory, is_file, path_exists, prefix_arg, random_string, }; pub fn ensure_dir_exists( name: &'static str, path: &Path, - notify_handler: &dyn Fn(Notification), + notify_handler: &dyn Fn(Notification<'_>), ) -> Result { raw::ensure_dir_exists(path, |p| { notify_handler(Notification::CreatingDirectory(name, p)) @@ -106,7 +107,7 @@ pub fn match_file Option>( }) } -pub fn canonicalize_path(path: &Path, notify_handler: &dyn 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) @@ -120,7 +121,11 @@ pub fn tee_file(name: &'static str, path: &Path, w: &mut W) -> Res }) } -pub fn download_file(url: &Url, path: &Path, notify_handler: &dyn Fn(Notification)) -> Result<()> { +pub fn download_file( + url: &Url, + path: &Path, + notify_handler: &dyn Fn(Notification<'_>), +) -> Result<()> { use download::ErrorKind as DEK; match download_file_(url, path, notify_handler) { Ok(_) => Ok(()), @@ -148,7 +153,7 @@ pub fn download_file(url: &Url, path: &Path, notify_handler: &dyn Fn(Notificatio } } -fn download_file_(url: &Url, path: &Path, notify_handler: &dyn Fn(Notification)) -> Result<()> { +fn download_file_(url: &Url, path: &Path, notify_handler: &dyn Fn(Notification<'_>)) -> Result<()> { use download::download_to_path_with_backend; use download::{Backend, Event}; @@ -156,7 +161,7 @@ fn download_file_(url: &Url, path: &Path, notify_handler: &dyn Fn(Notification)) // This callback will write the download to disk and optionally // hash the contents, then forward the notification up the stack - let callback: &dyn Fn(Event) -> download::Result<()> = &|msg| { + let callback: &dyn Fn(Event<'_>) -> download::Result<()> = &|msg| { match msg { Event::DownloadContentLengthReceived(len) => { notify_handler(Notification::DownloadContentLengthReceived(len)); @@ -212,7 +217,11 @@ pub fn assert_is_directory(path: &Path) -> Result<()> { } } -pub fn symlink_dir(src: &Path, dest: &Path, notify_handler: &dyn 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), @@ -252,7 +261,7 @@ pub fn symlink_file(src: &Path, dest: &Path) -> Result<()> { .into()) } -pub fn copy_dir(src: &Path, dest: &Path, notify_handler: &dyn 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), @@ -272,7 +281,7 @@ pub fn copy_file(src: &Path, dest: &Path) -> Result<()> { pub fn remove_dir( name: &'static str, path: &Path, - notify_handler: &dyn Fn(Notification), + notify_handler: &dyn Fn(Notification<'_>), ) -> Result<()> { notify_handler(Notification::RemovingDirectory(name, path)); raw::remove_dir(path).chain_err(|| ErrorKind::RemovingDirectory { @@ -468,15 +477,14 @@ pub fn fetch_url(url: &str) -> Result { } // fetch from HTML page instead of Github API to avoid rate limit -pub fn fetch_latest_release_tag( - repo_slug: &str, - no_net: bool -) -> Result { +pub fn fetch_latest_release_tag(repo_slug: &str, no_net: bool) -> Result { use regex::Regex; let latest_url = format!("https://github.com/{}/releases/latest", repo_slug); let res = if no_net { - Err(Error::from("Cannot fetch latest release tag under `--no-net`")) + Err(Error::from( + "Cannot fetch latest release tag under `--no-net`", + )) } else { fetch_url(&latest_url) }; @@ -490,9 +498,7 @@ pub fn fetch_latest_release_tag( }; Ok(tag) } - Err(e) => { - Err(e) - } + Err(e) => Err(e), } } diff --git a/src/elan/command.rs b/src/elan/command.rs index b9b8d6f..c68857d 100644 --- a/src/elan/command.rs +++ b/src/elan/command.rs @@ -2,8 +2,8 @@ use std::ffi::OsStr; use std::io; use std::process::{self, Command}; +use crate::errors::*; use elan_utils; -use errors::*; pub fn run_command_for_dir>( mut cmd: Command, diff --git a/src/elan/config.rs b/src/elan/config.rs index 7ab69ac..f8c5a2a 100644 --- a/src/elan/config.rs +++ b/src/elan/config.rs @@ -5,19 +5,20 @@ use std::path::{Path, PathBuf}; use std::process::Command; use std::sync::Arc; +use crate::errors::*; +use crate::notifications::*; +use crate::settings::{Settings, SettingsFile}; +use crate::toolchain::Toolchain; use elan_dist::dist::ToolchainDesc; use elan_dist::temp; use elan_utils::utils; -use errors::*; use itertools::Itertools; -use notifications::*; use serde_derive::Serialize; -use settings::{Settings, SettingsFile}; -use toolchain::Toolchain; -use toml; - -use crate::{gc, lookup_toolchain_desc, lookup_unresolved_toolchain_desc, read_unresolved_toolchain_desc_from_file, resolve_toolchain_desc, UnresolvedToolchainDesc}; +use crate::{ + gc, lookup_toolchain_desc, lookup_unresolved_toolchain_desc, + read_unresolved_toolchain_desc_from_file, resolve_toolchain_desc, UnresolvedToolchainDesc, +}; #[derive(Debug, Serialize, Clone)] pub enum OverrideReason { @@ -34,7 +35,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 ELAN_TOOLCHAIN"), OverrideReason::OverrideDB(ref path) => { @@ -64,11 +65,11 @@ pub struct Cfg { pub temp_cfg: temp::Cfg, //pub gpg_key: Cow<'static, str>, pub env_override: Option, - 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 elan home directory let elan_dir = utils::elan_home()?; @@ -117,7 +118,11 @@ impl Cfg { Ok(()) } - pub fn get_toolchain(&self, name: &ToolchainDesc, create_parent: bool) -> Result { + pub fn get_toolchain( + &self, + name: &ToolchainDesc, + create_parent: bool, + ) -> Result> { if create_parent { utils::ensure_dir_exists("toolchains", &self.toolchains_dir, &|n| { (self.notify_handler)(n.into()) @@ -148,7 +153,10 @@ impl Cfg { } } - pub fn find_override(&self, path: &Path) -> Result> { + pub fn find_override( + &self, + path: &Path, + ) -> Result> { // First check ELAN_TOOLCHAIN if let Some(ref name) = self.env_override { return Ok(Some(( @@ -160,9 +168,10 @@ impl Cfg { // Then walk up the directory tree from 'path' looking for either the // directory in override database, a `lean-toolchain` file, or a // `leanpkg.toml` file. - if let Some(res) = self.settings_file.with(|s| { - self.find_override_from_dir_walk(path, s) - })? { + if let Some(res) = self + .settings_file + .with(|s| self.find_override_from_dir_walk(path, s))? + { return Ok(Some(res)); } Ok(None) @@ -233,9 +242,9 @@ impl Cfg { pub fn find_override_toolchain_or_default( &self, path: &Path, - ) -> Result)>> { + ) -> Result, Option)>> { if let Some((toolchain, reason)) = self.find_override(path)? { - let toolchain = resolve_toolchain_desc(&self, &toolchain)?; + let toolchain = resolve_toolchain_desc(self, &toolchain)?; match self.get_toolchain(&toolchain, false) { Ok(toolchain) => { if toolchain.exists() { @@ -281,8 +290,8 @@ impl Cfg { } }; Err(e) - .chain_err(|| Error::from(reason_err)) - .chain_err(|| ErrorKind::OverrideToolchainNotInstalled(toolchain)) + .chain_err(|| Error::from(reason_err)) + .chain_err(|| ErrorKind::OverrideToolchainNotInstalled(toolchain)) } } } else if let Some(tc) = self.resolve_default()? { @@ -321,7 +330,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(ErrorKind::NoDefaultToolchain.into())) } diff --git a/src/elan/errors.rs b/src/elan/errors.rs index 07fdccd..283b253 100644 --- a/src/elan/errors.rs +++ b/src/elan/errors.rs @@ -1,9 +1,9 @@ use elan_dist::dist::ToolchainDesc; use elan_dist::manifest::Component; use elan_dist::{self, temp}; -use elan_utils; use std::path::PathBuf; -use toml; + +use error_chain::error_chain; error_chain! { links { diff --git a/src/elan/gc.rs b/src/elan/gc.rs index 83e0238..a4fca41 100644 --- a/src/elan/gc.rs +++ b/src/elan/gc.rs @@ -6,7 +6,10 @@ use std::{ use elan_dist::dist::ToolchainDesc; use itertools::Itertools; -use crate::{lookup_unresolved_toolchain_desc, read_toolchain_desc_from_file, resolve_toolchain_desc_ext, Cfg, Toolchain}; +use crate::{ + lookup_unresolved_toolchain_desc, read_toolchain_desc_from_file, resolve_toolchain_desc_ext, + Cfg, Toolchain, +}; fn get_root_file(cfg: &Cfg) -> PathBuf { cfg.elan_dir.join("known-projects") @@ -34,7 +37,9 @@ pub fn add_root(cfg: &Cfg, root: &Path) -> elan_utils::Result<()> { Ok(()) } -pub fn analyze_toolchains(cfg: &Cfg) -> crate::Result<(Vec, Vec<(String, ToolchainDesc)>)> { +pub fn analyze_toolchains( + cfg: &Cfg, +) -> crate::Result<(Vec>, Vec<(String, ToolchainDesc)>)> { let roots = get_roots(cfg)?; let mut used_toolchains = roots .into_iter() @@ -48,19 +53,32 @@ pub fn analyze_toolchains(cfg: &Cfg) -> crate::Result<(Vec, Vec<(Stri }) .collect::>(); if let Some(default) = cfg.get_default()? { - if let Ok(default) = resolve_toolchain_desc_ext(cfg, &lookup_unresolved_toolchain_desc(cfg, &default)?, true, true) { + if let Ok(default) = resolve_toolchain_desc_ext( + cfg, + &lookup_unresolved_toolchain_desc(cfg, &default)?, + true, + true, + ) { used_toolchains.push(("default toolchain".to_string(), default)); } } if let Some(ref env_override) = cfg.env_override { - if let Ok(desc) = resolve_toolchain_desc_ext(cfg, &lookup_unresolved_toolchain_desc(cfg, &env_override)?, true, true) { + if let Ok(desc) = resolve_toolchain_desc_ext( + cfg, + &lookup_unresolved_toolchain_desc(cfg, env_override)?, + true, + true, + ) { used_toolchains.push(("ELAN_TOOLCHAIN".to_string(), desc)); } } for (path, tc) in cfg.get_overrides()? { used_toolchains.push((format!("{} (override)", path), tc)); } - let used_toolchains_set = used_toolchains.iter().map(|p| p.1.to_string()).collect::>(); + let used_toolchains_set = used_toolchains + .iter() + .map(|p| p.1.to_string()) + .collect::>(); let unused_toolchains = cfg .list_toolchains()? .into_iter() diff --git a/src/elan/install.rs b/src/elan/install.rs index b7ca905..0526a21 100644 --- a/src/elan/install.rs +++ b/src/elan/install.rs @@ -1,12 +1,12 @@ //! Installation and upgrade of both distribution-managed and local //! toolchains +use crate::errors::Result; use elan_dist::dist; use elan_dist::download::DownloadCfg; use elan_dist::prefix::InstallPrefix; use elan_dist::Notification; use elan_utils::utils::{self, fetch_latest_release_tag}; -use errors::Result; use std::path::Path; #[cfg(feature = "no-self-update")] @@ -43,8 +43,8 @@ pub enum InstallMethod<'a> { Dist(&'a dist::ToolchainDesc, DownloadCfg<'a>), } -impl<'a> InstallMethod<'a> { - pub fn run(self, path: &Path, notify_handler: &dyn Fn(Notification)) -> Result<()> { +impl InstallMethod<'_> { + pub fn run(self, path: &Path, notify_handler: &dyn Fn(Notification<'_>)) -> Result<()> { if path.exists() { // Don't uninstall first for Dist method match self { @@ -78,7 +78,7 @@ impl<'a> InstallMethod<'a> { } } -pub fn uninstall(path: &Path, notify_handler: &dyn 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/elan/lib.rs b/src/elan/lib.rs index b5d6ee5..0345b64 100644 --- a/src/elan/lib.rs +++ b/src/elan/lib.rs @@ -1,24 +1,9 @@ #![recursion_limit = "1024"] +#![deny(rust_2018_idioms)] -extern crate elan_dist; -extern crate elan_utils; -#[macro_use] -extern crate error_chain; -extern crate itertools; -#[cfg(unix)] -extern crate libc; -extern crate regex; -extern crate semver; -extern crate serde_derive; -extern crate serde_json; -extern crate tempfile; -extern crate time; -extern crate toml; -extern crate url; - +pub use crate::errors::*; pub use config::*; pub use elan_utils::{notify, toml_utils, utils}; -pub use errors::*; pub use notifications::*; pub use toolchain::*; diff --git a/src/elan/notifications.rs b/src/elan/notifications.rs index 82c4639..132fb92 100644 --- a/src/elan/notifications.rs +++ b/src/elan/notifications.rs @@ -1,11 +1,10 @@ use std::fmt::{self, Display}; use std::path::{Path, PathBuf}; +use crate::errors::*; use elan_dist::dist::ToolchainDesc; -use errors::*; use elan_dist::{self, temp}; -use elan_utils; use elan_utils::notify::NotificationLevel; #[derive(Debug)] @@ -56,7 +55,7 @@ impl<'a> From> for Notification<'a> { } } -impl<'a> Notification<'a> { +impl Notification<'_> { pub fn level(&self) -> NotificationLevel { use self::Notification::*; match *self { @@ -83,13 +82,15 @@ impl<'a> Notification<'a> { | MetadataUpgradeNotNeeded(_) | SetTelemetry(_) => NotificationLevel::Info, NonFatalError(_) => NotificationLevel::Error, - UpgradeRemovesToolchains | MissingFileDuringSelfUninstall(_) | UsingExistingRelease(_) => NotificationLevel::Warn, + UpgradeRemovesToolchains + | MissingFileDuringSelfUninstall(_) + | UsingExistingRelease(_) => NotificationLevel::Warn, } } } -impl<'a> Display for Notification<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> ::std::result::Result<(), fmt::Error> { +impl Display for Notification<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> ::std::result::Result<(), fmt::Error> { use self::Notification::*; match *self { Install(ref n) => n.fmt(f), @@ -111,7 +112,11 @@ impl<'a> Display for Notification<'a> { InstalledToolchain(name) => write!(f, "toolchain '{}' installed", name), UsingExistingToolchain(name) => write!(f, "using existing install for '{}'", name), UninstallingToolchain(name) => write!(f, "uninstalling toolchain '{}'", name), - UninstallingObsoleteToolchain(name) => write!(f, "uninstalling toolchain '{}' using obsolete format", name.display()), + UninstallingObsoleteToolchain(name) => write!( + f, + "uninstalling toolchain '{}' using obsolete format", + name.display() + ), UninstalledToolchain(name) => write!(f, "toolchain '{}' uninstalled", name), ToolchainNotInstalled(name) => write!(f, "no toolchain installed for '{}'", name), UpdateHashMatches => { @@ -150,9 +155,8 @@ impl<'a> Display for Notification<'a> { UsingExistingRelease(tc) => write!( f, "failed to query latest release, using existing version '{}'", - tc.to_string() + tc ), - } } } diff --git a/src/elan/settings.rs b/src/elan/settings.rs index 2f64d71..58b84b9 100644 --- a/src/elan/settings.rs +++ b/src/elan/settings.rs @@ -1,12 +1,12 @@ +use crate::errors::*; +use crate::notifications::*; +use crate::toml_utils::*; +use crate::utils; use elan_dist::dist::ToolchainDesc; -use errors::*; -use notifications::*; use std::cell::RefCell; use std::collections::BTreeMap; use std::path::{Path, PathBuf}; use toml; -use toml_utils::*; -use utils; pub const SUPPORTED_METADATA_VERSIONS: [&str; 2] = ["2", "12"]; pub const DEFAULT_METADATA_VERSION: &str = "12"; @@ -90,7 +90,7 @@ impl Default for Settings { } impl Settings { - fn path_to_key(path: &Path, notify_handler: &dyn 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() @@ -100,7 +100,11 @@ impl Settings { } } - pub fn remove_override(&mut self, path: &Path, notify_handler: &dyn 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() } @@ -109,7 +113,7 @@ impl Settings { &mut self, path: &Path, toolchain: ToolchainDesc, - notify_handler: &dyn Fn(Notification), + notify_handler: &dyn Fn(Notification<'_>), ) { let key = Self::path_to_key(path, notify_handler); notify_handler(Notification::SetOverrideToolchain(path, &toolchain)); @@ -119,7 +123,7 @@ impl Settings { pub fn dir_override( &self, dir: &Path, - notify_handler: &dyn Fn(Notification), + notify_handler: &dyn Fn(Notification<'_>), ) -> Option { let key = Self::path_to_key(dir, notify_handler); self.overrides.get(&key).cloned() diff --git a/src/elan/toolchain.rs b/src/elan/toolchain.rs index 1a09e1b..6fc77d0 100644 --- a/src/elan/toolchain.rs +++ b/src/elan/toolchain.rs @@ -1,15 +1,14 @@ -use config::Cfg; -use elan_dist; +use crate::config::Cfg; +use crate::env_var; +use crate::errors::*; +use crate::install::{self, InstallMethod}; +use crate::notifications::*; use elan_dist::dist::ToolchainDesc; use elan_dist::download::DownloadCfg; use elan_dist::manifest::Component; use elan_utils::utils; use elan_utils::utils::fetch_url; -use env_var; -use errors::*; -use install::{self, InstallMethod}; use itertools::Itertools; -use notifications::*; use regex::Regex; use serde_derive::Serialize; @@ -27,7 +26,7 @@ pub struct Toolchain<'a> { cfg: &'a Cfg, pub desc: ToolchainDesc, path: PathBuf, - dist_handler: Box, + dist_handler: Box) + 'a>, } /// Used by the `list_component` function @@ -54,7 +53,9 @@ pub fn lookup_unresolved_toolchain_desc(cfg: &Cfg, name: &str) -> Result Result Option None, }); let toolchains: Vec<_> = match channel { - "nightly" => toolchains.filter(|t| t.1.starts_with("nightly-")).sorted_by_key(|t| t.1.to_string()).map(|t| t.0).collect(), - _ => toolchains.filter_map(|t| - semver::Version::parse(t.1.trim_start_matches("v")).ok().filter(|v| - (channel == "stable") == v.pre.is_empty()).map (|v| (t.0, v))).sorted_by_key(|t| t.1.to_string()).map(|t| t.0).collect() + "nightly" => toolchains + .filter(|t| t.1.starts_with("nightly-")) + .sorted_by_key(|t| t.1.to_string()) + .map(|t| t.0) + .collect(), + _ => toolchains + .filter_map(|t| { + semver::Version::parse(t.1.trim_start_matches("v")) + .ok() + .filter(|v| (channel == "stable") == v.pre.is_empty()) + .map(|v| (t.0, v)) + }) + .sorted_by_key(|t| t.1.to_string()) + .map(|t| t.0) + .collect(), }; toolchains.into_iter().last() } -pub fn resolve_toolchain_desc_ext(cfg: &Cfg, unresolved_tc: &UnresolvedToolchainDesc, no_net: bool, use_cache: bool) -> Result { - if let ToolchainDesc::Remote { ref origin, ref release, from_channel: Some(ref channel) } = unresolved_tc.0 { +pub fn resolve_toolchain_desc_ext( + cfg: &Cfg, + unresolved_tc: &UnresolvedToolchainDesc, + no_net: bool, + use_cache: bool, +) -> Result { + if let ToolchainDesc::Remote { + ref origin, + ref release, + from_channel: Some(ref channel), + } = unresolved_tc.0 + { if release == "lean-toolchain" { let toolchain_url = format!( "https://raw.githubusercontent.com/{}/HEAD/lean-toolchain", origin ); - return resolve_toolchain_desc_ext(cfg, &lookup_unresolved_toolchain_desc(cfg, fetch_url(&toolchain_url)?.trim())?, no_net, use_cache); + resolve_toolchain_desc_ext( + cfg, + &lookup_unresolved_toolchain_desc(cfg, fetch_url(&toolchain_url)?.trim())?, + no_net, + use_cache, + ) } else if release == "stable" || release == "beta" || release == "nightly" { match utils::fetch_latest_release_tag(origin, no_net) { - Ok(release) => Ok(ToolchainDesc::Remote { origin: origin.clone(), release, from_channel: Some(channel.clone()) }), + Ok(release) => Ok(ToolchainDesc::Remote { + origin: origin.clone(), + release, + from_channel: Some(channel.clone()), + }), Err(e) => { - if let (true, Some(tc)) = (use_cache, find_latest_local_toolchain(cfg, &release)) { + if let (true, Some(tc)) = (use_cache, find_latest_local_toolchain(cfg, release)) + { if !no_net { (cfg.notify_handler)(Notification::UsingExistingRelease(&tc)); } @@ -122,7 +162,10 @@ pub fn resolve_toolchain_desc_ext(cfg: &Cfg, unresolved_tc: &UnresolvedToolchain } } -pub fn resolve_toolchain_desc(cfg: &Cfg, unresolved_tc: &UnresolvedToolchainDesc) -> Result { +pub fn resolve_toolchain_desc( + cfg: &Cfg, + unresolved_tc: &UnresolvedToolchainDesc, +) -> Result { resolve_toolchain_desc_ext(cfg, unresolved_tc, false, true) } @@ -130,18 +173,27 @@ pub fn lookup_toolchain_desc(cfg: &Cfg, name: &str) -> Result { resolve_toolchain_desc(cfg, &lookup_unresolved_toolchain_desc(cfg, name)?) } -pub fn read_unresolved_toolchain_desc_from_file(cfg: &Cfg, toolchain_file: &Path) -> Result { - let s = utils::read_file("toolchain file", &toolchain_file)?; +pub fn read_unresolved_toolchain_desc_from_file( + cfg: &Cfg, + toolchain_file: &Path, +) -> Result { + let s = utils::read_file("toolchain file", toolchain_file)?; if let Some(s) = s.lines().next() { let toolchain_name = s.trim(); lookup_unresolved_toolchain_desc(cfg, toolchain_name) } else { - Err(Error::from(format!("empty toolchain file '{}'", toolchain_file.display()))) + Err(Error::from(format!( + "empty toolchain file '{}'", + toolchain_file.display() + ))) } } pub fn read_toolchain_desc_from_file(cfg: &Cfg, toolchain_file: &Path) -> Result { - resolve_toolchain_desc(cfg, &read_unresolved_toolchain_desc_from_file(cfg, toolchain_file)?) + resolve_toolchain_desc( + cfg, + &read_unresolved_toolchain_desc_from_file(cfg, toolchain_file)?, + ) } impl<'a> Toolchain<'a> { @@ -197,7 +249,7 @@ impl<'a> Toolchain<'a> { } result } - fn install(&self, install_method: InstallMethod) -> Result<()> { + fn install(&self, install_method: InstallMethod<'_>) -> Result<()> { let exists = self.exists(); if exists { return Err(format!("'{}' is already installed", self.desc).into()); @@ -211,7 +263,7 @@ impl<'a> Toolchain<'a> { Ok(()) } - fn install_if_not_installed(&self, install_method: InstallMethod) -> Result<()> { + fn install_if_not_installed(&self, install_method: InstallMethod<'_>) -> Result<()> { (self.cfg.notify_handler)(Notification::LookingForToolchain(&self.desc)); if !self.exists() { self.install(install_method) @@ -220,7 +272,7 @@ impl<'a> Toolchain<'a> { } } - fn download_cfg(&self) -> DownloadCfg { + fn download_cfg(&self) -> DownloadCfg<'_> { DownloadCfg { temp_cfg: &self.cfg.temp_cfg, notify_handler: &*self.dist_handler,