Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Rust 2018 edition idioms #1643

Merged
merged 1 commit into from
Feb 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions src/download/src/errors.rs
Original file line number Diff line number Diff line change
@@ -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 { }

Expand Down
37 changes: 17 additions & 20 deletions src/download/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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),
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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.
//
Expand Down Expand Up @@ -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());
}
Expand All @@ -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(());
Expand Down Expand Up @@ -316,7 +313,7 @@ pub mod reqwest_be {
}

fn env_proxy(url: &Url) -> Option<Url> {
env_proxy::for_url(url).to_url()
::env_proxy::for_url(url).to_url()
}

fn request(url: &Url, resume_from: u64) -> ::reqwest::Result<Response> {
Expand All @@ -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<bool> {
use std::fs;
use std::io;
Expand Down
3 changes: 0 additions & 3 deletions src/download/tests/download-curl-resume.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#![cfg(feature = "curl-backend")]

extern crate download;
extern crate url;

use std::sync::Mutex;

use url::Url;
Expand Down
3 changes: 0 additions & 3 deletions src/download/tests/download-reqwest-resume.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#![cfg(feature = "reqwest-backend")]

extern crate download;
extern crate url;

use std::sync::Mutex;

use url::Url;
Expand Down
10 changes: 3 additions & 7 deletions src/download/tests/support/mod.rs
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -37,7 +33,7 @@ pub fn write_file(path: &Path, contents: &str) {
}

pub fn serve_file(contents: Vec<u8>) -> SocketAddr {
use self::futures::Future;
use futures::Future;
use std::thread;

let addr = ([127, 0, 0, 1], 0).into();
Expand Down
11 changes: 5 additions & 6 deletions src/rustup-cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -109,7 +108,7 @@ pub fn set_globals(verbose: bool) -> Result<Cfg> {

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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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" {
Expand All @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions src/rustup-cli/download_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/rustup-cli/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 6 additions & 8 deletions src/rustup-cli/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/rustup-cli/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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: ");
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Loading