Skip to content

Commit 67d740f

Browse files
authored
Merge pull request #1643 from dwijnand/edition-idioms
Upgrade to Rust 2018 edition idioms
2 parents 07fa042 + 0857a9f commit 67d740f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+235
-411
lines changed

Cargo.lock

Lines changed: 10 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ regex = "1.0.1"
4646
remove_dir_all = "0.5.1"
4747
same-file = "1.0"
4848
scopeguard = "0.3"
49-
serde = "1.0"
49+
serde = { version = "1.0.87", features = ['derive'] }
5050
serde_derive = "1.0"
5151
serde_json = "1.0"
5252
sha2 = "0.7.0"

src/download/src/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
use error_chain::error_chain;
2+
use error_chain::error_chain_processing;
3+
use error_chain::{impl_error_chain_kind, impl_error_chain_processed, impl_extract_backtrace};
4+
15
error_chain! {
26
links { }
37

src/download/src/lib.rs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
//! Easy file downloading
22
3-
#[macro_use]
4-
extern crate error_chain;
5-
extern crate url;
6-
7-
#[cfg(feature = "reqwest-backend")]
8-
#[macro_use]
9-
extern crate lazy_static;
10-
#[cfg(feature = "reqwest-backend")]
11-
extern crate reqwest;
12-
133
use std::path::Path;
144
use url::Url;
155

@@ -35,7 +25,7 @@ fn download_with_backend(
3525
backend: Backend,
3626
url: &Url,
3727
resume_from: u64,
38-
callback: &Fn(Event) -> Result<()>,
28+
callback: &dyn Fn(Event<'_>) -> Result<()>,
3929
) -> Result<()> {
4030
match backend {
4131
Backend::Curl => curl::download(url, resume_from, callback),
@@ -48,7 +38,7 @@ pub fn download_to_path_with_backend(
4838
url: &Url,
4939
path: &Path,
5040
resume_from_partial: bool,
51-
callback: Option<&Fn(Event) -> Result<()>>,
41+
callback: Option<&dyn Fn(Event<'_>) -> Result<()>>,
5242
) -> Result<()> {
5343
use std::cell::RefCell;
5444
use std::fs::OpenOptions;
@@ -133,7 +123,7 @@ pub fn download_to_path_with_backend(
133123
#[cfg(feature = "curl-backend")]
134124
pub mod curl {
135125

136-
extern crate curl;
126+
use curl;
137127

138128
use self::curl::easy::Easy;
139129
use super::Event;
@@ -143,7 +133,11 @@ pub mod curl {
143133
use std::time::Duration;
144134
use url::Url;
145135

146-
pub fn download(url: &Url, resume_from: u64, callback: &Fn(Event) -> Result<()>) -> Result<()> {
136+
pub fn download(
137+
url: &Url,
138+
resume_from: u64,
139+
callback: &dyn Fn(Event<'_>) -> Result<()>,
140+
) -> Result<()> {
147141
// Fetch either a cached libcurl handle (which will preserve open
148142
// connections) or create a new one if it isn't listed.
149143
//
@@ -239,7 +233,7 @@ pub mod curl {
239233
.response_code()
240234
.chain_err(|| "failed to get response code")?;
241235
match code {
242-
0 | 200...299 => {}
236+
0 | 200..=299 => {}
243237
_ => {
244238
return Err(ErrorKind::HttpStatus(code).into());
245239
}
@@ -252,16 +246,19 @@ pub mod curl {
252246

253247
#[cfg(feature = "reqwest-backend")]
254248
pub mod reqwest_be {
255-
extern crate env_proxy;
256-
257249
use super::Event;
258250
use crate::errors::*;
251+
use lazy_static::lazy_static;
259252
use reqwest::{header, Client, Proxy, Response};
260253
use std::io;
261254
use std::time::Duration;
262255
use url::Url;
263256

264-
pub fn download(url: &Url, resume_from: u64, callback: &Fn(Event) -> Result<()>) -> Result<()> {
257+
pub fn download(
258+
url: &Url,
259+
resume_from: u64,
260+
callback: &dyn Fn(Event<'_>) -> Result<()>,
261+
) -> Result<()> {
265262
// Short-circuit reqwest for the "file:" URL scheme
266263
if download_from_file_url(url, resume_from, callback)? {
267264
return Ok(());
@@ -316,7 +313,7 @@ pub mod reqwest_be {
316313
}
317314

318315
fn env_proxy(url: &Url) -> Option<Url> {
319-
env_proxy::for_url(url).to_url()
316+
::env_proxy::for_url(url).to_url()
320317
}
321318

322319
fn request(url: &Url, resume_from: u64) -> ::reqwest::Result<Response> {
@@ -332,7 +329,7 @@ pub mod reqwest_be {
332329
fn download_from_file_url(
333330
url: &Url,
334331
resume_from: u64,
335-
callback: &Fn(Event) -> Result<()>,
332+
callback: &dyn Fn(Event<'_>) -> Result<()>,
336333
) -> Result<bool> {
337334
use std::fs;
338335
use std::io;

src/download/tests/download-curl-resume.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#![cfg(feature = "curl-backend")]
22

3-
extern crate download;
4-
extern crate url;
5-
63
use std::sync::Mutex;
74

85
use url::Url;

src/download/tests/download-reqwest-resume.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#![cfg(feature = "reqwest-backend")]
22

3-
extern crate download;
4-
extern crate url;
5-
63
use std::sync::Mutex;
74

85
use url::Url;

src/download/tests/support/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
extern crate futures;
2-
extern crate hyper;
3-
extern crate tempdir;
4-
51
use std::fs::{self, File};
62
use std::io::{self, Read};
73
use std::net::SocketAddr;
84
use std::path::Path;
95

10-
use self::futures::sync::oneshot;
11-
use self::tempdir::TempDir;
6+
use futures::sync::oneshot;
7+
use tempdir::TempDir;
128

139
pub fn tmp_dir() -> TempDir {
1410
TempDir::new("rustup-download-test-").expect("creating tempdir for test")
@@ -37,7 +33,7 @@ pub fn write_file(path: &Path, contents: &str) {
3733
}
3834

3935
pub fn serve_file(contents: Vec<u8>) -> SocketAddr {
40-
use self::futures::Future;
36+
use futures::Future;
4137
use std::thread;
4238

4339
let addr = ([127, 0, 0, 1], 0).into();

src/rustup-cli/common.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ use crate::errors::*;
44
use crate::self_update;
55
use crate::term2;
66
use rustup::telemetry_analysis::TelemetryAnalysis;
7-
use rustup::{self, Cfg, Notification, Toolchain, UpdateStatus};
7+
use rustup::{Cfg, Notification, Toolchain, UpdateStatus};
88
use rustup_utils::notify::NotificationLevel;
99
use rustup_utils::utils;
10-
use std;
1110
use std::io::{BufRead, BufReader, Write};
1211
use std::path::Path;
1312
use std::process::{Command, Stdio};
@@ -109,7 +108,7 @@ pub fn set_globals(verbose: bool) -> Result<Cfg> {
109108

110109
let download_tracker = RefCell::new(DownloadTracker::new());
111110

112-
Ok(Cfg::from_env(Arc::new(move |n: Notification| {
111+
Ok(Cfg::from_env(Arc::new(move |n: Notification<'_>| {
113112
if download_tracker.borrow_mut().handle_notification(&n) {
114113
return;
115114
}
@@ -243,7 +242,7 @@ where
243242
Ok(())
244243
}
245244

246-
pub fn rustc_version(toolchain: &Toolchain) -> String {
245+
pub fn rustc_version(toolchain: &Toolchain<'_>) -> String {
247246
if toolchain.exists() {
248247
let rustc_path = toolchain.binary_file("rustc");
249248
if utils::is_file(&rustc_path) {
@@ -294,7 +293,7 @@ pub fn rustc_version(toolchain: &Toolchain) -> String {
294293
}
295294
}
296295

297-
pub fn list_targets(toolchain: &Toolchain) -> Result<()> {
296+
pub fn list_targets(toolchain: &Toolchain<'_>) -> Result<()> {
298297
let mut t = term2::stdout();
299298
for component in toolchain.list_components()? {
300299
if component.component.short_name_in_manifest() == "rust-std" {
@@ -320,7 +319,7 @@ pub fn list_targets(toolchain: &Toolchain) -> Result<()> {
320319
Ok(())
321320
}
322321

323-
pub fn list_components(toolchain: &Toolchain) -> Result<()> {
322+
pub fn list_components(toolchain: &Toolchain<'_>) -> Result<()> {
324323
let mut t = term2::stdout();
325324
for component in toolchain.list_components()? {
326325
let name = component.name;

src/rustup-cli/download_tracker.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustup_utils::tty;
44
use rustup_utils::Notification as Un;
55
use std::collections::VecDeque;
66
use std::fmt;
7-
use term;
87
use time::precise_time_s;
98

109
/// Keep track of this many past download amounts
@@ -50,7 +49,7 @@ impl DownloadTracker {
5049
}
5150
}
5251

53-
pub fn handle_notification(&mut self, n: &Notification) -> bool {
52+
pub fn handle_notification(&mut self, n: &Notification<'_>) -> bool {
5453
match *n {
5554
Notification::Install(In::Utils(Un::DownloadContentLengthReceived(content_len))) => {
5655
self.content_length_received(content_len);
@@ -170,7 +169,7 @@ impl DownloadTracker {
170169
struct HumanReadable(f64);
171170

172171
impl fmt::Display for HumanReadable {
173-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
172+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
174173
if f.alternate() {
175174
// repurposing the alternate mode for ETA
176175
let sec = self.0;

src/rustup-cli/errors.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
use std::io;
44
use std::path::PathBuf;
55

6-
use rustup;
7-
use rustup_dist::{self, temp};
8-
use rustup_utils;
6+
use error_chain::error_chain;
7+
use error_chain::error_chain_processing;
8+
use error_chain::{impl_error_chain_kind, impl_error_chain_processed, impl_extract_backtrace};
9+
use rustup_dist::temp;
910

1011
error_chain! {
1112
links {

0 commit comments

Comments
 (0)