Skip to content

Commit 2f7f43d

Browse files
committed
Compile on stable Rust
This removes the usage of #[fundamental] and intrinsics::type_name in the notifications module. The `Notifyable` trait and `Notifier` struct were also removed in favor of just using `&Fn(Notification)` where necessary. This change is less ergonomic when crossing crate boundaries where `Notifier` naturally implemented `Notifyable` for multiple notification types before. Instead, now closures must be written as: &|n| prev_handler(n.into()) Which is to say that when crossing crate boundaries you need to remap notification closures and leverage a `From` implementation. This crate does not currently compile on the stable *channel* due to the usage of `panic::catch_unwind` in the curl crate for now, but that will get fixed with the next stable release, this is just paving the way forward! Closes #58
1 parent c6e430a commit 2f7f43d

26 files changed

+513
-511
lines changed

src/rustup-cli/common.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use std::io::{Write, BufRead};
1010
use std::process::Command;
1111
use std::{cmp, iter};
1212
use std::str::FromStr;
13+
use std::sync::Arc;
1314
use std;
1415
use term2;
1516

@@ -102,7 +103,7 @@ pub fn set_globals(verbose: bool) -> Result<Cfg> {
102103

103104
let download_tracker = RefCell::new(DownloadTracker::new());
104105

105-
Ok(try!(Cfg::from_env(shared_ntfy!(move |n: Notification| {
106+
Ok(try!(Cfg::from_env(Arc::new(move |n: Notification| {
106107
if download_tracker.borrow_mut().handle_notification(&n) {
107108
return;
108109
}

src/rustup-cli/multirust_mode.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ use rustup_dist::dist::TargetTriple;
1010
use self_update;
1111
use std::env;
1212
use std::path::{Path, PathBuf};
13+
use std::sync::Arc;
1314
use job;
1415

1516
pub fn main() -> Result<()> {
1617
try!(::self_update::cleanup_self_updater());
1718

1819
let need_metadata = try!(command_requires_metadata());
1920
if need_metadata {
20-
let cfg = try!(Cfg::from_env(shared_ntfy!(move |_: Notification| { })));
21+
let cfg = try!(Cfg::from_env(Arc::new(move |_: Notification| { })));
2122
try!(cfg.check_metadata_version());
2223
}
2324

src/rustup-cli/self_update.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
//! and racy on Windows.
3232
3333
use common::{self, Confirm};
34-
use rustup::{NotifyHandler};
3534
use errors::*;
3635
use rustup_dist::dist;
3736
use rustup_utils::utils;
@@ -456,7 +455,7 @@ fn install_bins() -> Result<()> {
456455
let ref this_exe_path = try!(utils::current_exe());
457456
let ref multirust_path = bin_path.join(&format!("multirust{}", EXE_SUFFIX));
458457

459-
try!(utils::ensure_dir_exists("bin", bin_path, ntfy!(&NotifyHandler::none())));
458+
try!(utils::ensure_dir_exists("bin", bin_path, &|_| {}));
460459
// NB: Even on Linux we can't just copy the new binary over the (running)
461460
// old binary; we must unlink it first.
462461
if multirust_path.exists() {
@@ -519,7 +518,7 @@ pub fn uninstall(no_prompt: bool) -> Result<()> {
519518
// Delete RUSTUP_HOME
520519
let ref multirust_dir = try!(utils::multirust_home());
521520
if multirust_dir.exists() {
522-
try!(utils::remove_dir("multirust_home", multirust_dir, ntfy!(&NotifyHandler::none())));
521+
try!(utils::remove_dir("multirust_home", multirust_dir, &|_| {}));
523522
}
524523

525524
let read_dir_err = "failure reading directory";
@@ -537,7 +536,7 @@ pub fn uninstall(no_prompt: bool) -> Result<()> {
537536
let dirent = try!(dirent.chain_err(|| read_dir_err));
538537
if dirent.file_name().to_str() != Some("bin") {
539538
if dirent.path().is_dir() {
540-
try!(utils::remove_dir("cargo_home", &dirent.path(), ntfy!(&NotifyHandler::none())));
539+
try!(utils::remove_dir("cargo_home", &dirent.path(), &|_| {}));
541540
} else {
542541
try!(utils::remove_file("cargo_home", &dirent.path()));
543542
}
@@ -554,7 +553,7 @@ pub fn uninstall(no_prompt: bool) -> Result<()> {
554553
let file_is_tool = name.to_str().map(|n| tools.iter().any(|t| *t == n));
555554
if file_is_tool == Some(false) {
556555
if dirent.path().is_dir() {
557-
try!(utils::remove_dir("cargo_home", &dirent.path(), ntfy!(&NotifyHandler::none())));
556+
try!(utils::remove_dir("cargo_home", &dirent.path(), &|_| {}));
558557
} else {
559558
try!(utils::remove_file("cargo_home", &dirent.path()));
560559
}
@@ -576,7 +575,7 @@ pub fn uninstall(no_prompt: bool) -> Result<()> {
576575
#[cfg(unix)]
577576
fn delete_multirust_and_cargo_home() -> Result<()> {
578577
let ref cargo_home = try!(utils::cargo_home());
579-
try!(utils::remove_dir("cargo_home", cargo_home, ntfy!(&NotifyHandler::none())));
578+
try!(utils::remove_dir("cargo_home", cargo_home, &|_| ()));
580579

581580
Ok(())
582581
}
@@ -684,15 +683,14 @@ fn delete_multirust_and_cargo_home() -> Result<()> {
684683
/// Run by multirust-gc-$num.exe to delete CARGO_HOME
685684
#[cfg(windows)]
686685
pub fn complete_windows_uninstall() -> Result<()> {
687-
use rustup::NotifyHandler;
688686
use std::ffi::OsStr;
689687
use std::process::Stdio;
690688

691689
try!(wait_for_parent());
692690

693691
// Now that the parent has exited there are hopefully no more files open in CARGO_HOME
694692
let ref cargo_home = try!(utils::cargo_home());
695-
try!(utils::remove_dir("cargo_home", cargo_home, ntfy!(&NotifyHandler::none())));
693+
try!(utils::remove_dir("cargo_home", cargo_home, &|_| ()));
696694

697695
// Now, run a *system* binary to inherit the DELETE_ON_CLOSE
698696
// handle to *this* process, then exit. The OS will delete the gc
@@ -1099,7 +1097,7 @@ pub fn prepare_update() -> Result<Option<PathBuf>> {
10991097
info!("checking for self-updates");
11001098
let hash_url = try!(utils::parse_url(&(url.clone() + ".sha256")));
11011099
let hash_file = tempdir.path().join("hash");
1102-
try!(utils::download_file(&hash_url, &hash_file, None, ntfy!(&NotifyHandler::none())));
1100+
try!(utils::download_file(&hash_url, &hash_file, None, &|_| ()));
11031101
let mut latest_hash = try!(utils::read_file("hash", &hash_file));
11041102
latest_hash.truncate(64);
11051103

@@ -1118,7 +1116,7 @@ pub fn prepare_update() -> Result<Option<PathBuf>> {
11181116
try!(utils::download_file(&download_url,
11191117
&setup_path,
11201118
Some(&mut hasher),
1121-
ntfy!(&NotifyHandler::none())));
1119+
&|_| ()));
11221120
let download_hash = hasher.result_str();
11231121

11241122
// Check that hash is correct

src/rustup-dist/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ fn main() {
88
let target = env::var("TARGET").unwrap();
99

1010
File::create(out_dir.join("target.txt")).unwrap().write_all(target.as_bytes()).unwrap();
11+
println!("cargo:rerun-if-changed=build.rs");
1112
}

src/rustup-dist/src/component/components.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ impl Components {
8686
}
8787
}
8888

89-
#[derive(Debug)]
9089
pub struct ComponentBuilder<'a> {
9190
components: Components,
9291
name: String,

src/rustup-dist/src/component/transaction.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//! FIXME: This uses ensure_dir_exists in some places but rollback
1010
//! does not remove any dirs created by it.
1111
12-
use rustup_utils::{self, utils};
12+
use rustup_utils::utils;
1313
use temp;
1414
use prefix::InstallPrefix;
1515
use errors::*;
@@ -31,19 +31,18 @@ use std::path::{Path, PathBuf};
3131
///
3232
/// All operations that create files will fail if the destination
3333
/// already exists.
34-
#[derive(Debug)]
3534
pub struct Transaction<'a> {
3635
prefix: InstallPrefix,
3736
changes: Vec<ChangedItem<'a>>,
3837
temp_cfg: &'a temp::Cfg,
39-
notify_handler: NotifyHandler<'a>,
38+
notify_handler: &'a Fn(Notification),
4039
committed: bool,
4140
}
4241

4342
impl<'a> Transaction<'a> {
4443
pub fn new(prefix: InstallPrefix,
4544
temp_cfg: &'a temp::Cfg,
46-
notify_handler: NotifyHandler<'a>)
45+
notify_handler: &'a Fn(Notification))
4746
-> Self {
4847
Transaction {
4948
prefix: prefix,
@@ -131,7 +130,7 @@ impl<'a> Transaction<'a> {
131130
pub fn temp(&self) -> &'a temp::Cfg {
132131
self.temp_cfg
133132
}
134-
pub fn notify_handler(&self) -> NotifyHandler<'a> {
133+
pub fn notify_handler(&self) -> &'a Fn(Notification) {
135134
self.notify_handler
136135
}
137136
}
@@ -141,11 +140,16 @@ impl<'a> Transaction<'a> {
141140
impl<'a> Drop for Transaction<'a> {
142141
fn drop(&mut self) {
143142
if !self.committed {
144-
self.notify_handler.call(Notification::RollingBack);
143+
(self.notify_handler)(Notification::RollingBack);
145144
for item in self.changes.iter().rev() {
146-
ok_ntfy!(self.notify_handler,
147-
Notification::NonFatalError,
148-
item.roll_back(&self.prefix));
145+
// ok_ntfy!(self.notify_handler,
146+
// Notification::NonFatalError,
147+
match item.roll_back(&self.prefix) {
148+
Ok(()) => {}
149+
Err(e) => {
150+
(self.notify_handler)(Notification::NonFatalError(&e));
151+
}
152+
}
149153
}
150154
}
151155
}
@@ -172,7 +176,7 @@ impl<'a> ChangedItem<'a> {
172176
AddedDir(ref path) => {
173177
try!(utils::remove_dir("component",
174178
&prefix.abs_path(path),
175-
rustup_utils::NotifyHandler::none()))
179+
&|_| ()))
176180
}
177181
RemovedFile(ref path, ref tmp) | ModifiedFile(ref path, Some(ref tmp)) => {
178182
try!(utils::rename_file("component", &tmp, &prefix.abs_path(path)))
@@ -198,7 +202,7 @@ impl<'a> ChangedItem<'a> {
198202
}.into())
199203
} else {
200204
if let Some(p) = abs_path.parent() {
201-
try!(utils::ensure_dir_exists("component", p, rustup_utils::NotifyHandler::none()));
205+
try!(utils::ensure_dir_exists("component", p, &|_| ()));
202206
}
203207
let file = try!(File::create(&abs_path)
204208
.chain_err(|| format!("error creating file '{}'", abs_path.display())));
@@ -218,7 +222,7 @@ impl<'a> ChangedItem<'a> {
218222
}.into())
219223
} else {
220224
if let Some(p) = abs_path.parent() {
221-
try!(utils::ensure_dir_exists("component", p, rustup_utils::NotifyHandler::none()));
225+
try!(utils::ensure_dir_exists("component", p, &|_| ()));
222226
}
223227
try!(utils::copy_file(src, &abs_path));
224228
Ok(ChangedItem::AddedFile(relpath))
@@ -233,9 +237,9 @@ impl<'a> ChangedItem<'a> {
233237
}.into())
234238
} else {
235239
if let Some(p) = abs_path.parent() {
236-
try!(utils::ensure_dir_exists("component", p, rustup_utils::NotifyHandler::none()));
240+
try!(utils::ensure_dir_exists("component", p, &|_| ()));
237241
}
238-
try!(utils::copy_dir(src, &abs_path, rustup_utils::NotifyHandler::none()));
242+
try!(utils::copy_dir(src, &abs_path, &|_| ()));
239243
Ok(ChangedItem::AddedDir(relpath))
240244
}
241245
}
@@ -274,7 +278,7 @@ impl<'a> ChangedItem<'a> {
274278
Ok(ChangedItem::ModifiedFile(relpath, Some(backup)))
275279
} else {
276280
if let Some(p) = abs_path.parent() {
277-
try!(utils::ensure_dir_exists("component", p, rustup_utils::NotifyHandler::none()));
281+
try!(utils::ensure_dir_exists("component", p, &|_| {}));
278282
}
279283
Ok(ChangedItem::ModifiedFile(relpath, None))
280284
}

src/rustup-dist/src/dist.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -330,18 +330,19 @@ pub fn download_and_check<'a>(url_str: &str,
330330
return Ok(None);
331331
}
332332
} else {
333-
cfg.notify_handler.call(Notification::CantReadUpdateHash(hash_file));
333+
(cfg.notify_handler)(Notification::CantReadUpdateHash(hash_file));
334334
}
335335
} else {
336-
cfg.notify_handler.call(Notification::NoUpdateHash(hash_file));
336+
(cfg.notify_handler)(Notification::NoUpdateHash(hash_file));
337337
}
338338
}
339339

340340
let url = try!(utils::parse_url(url_str));
341341
let file = try!(cfg.temp_cfg.new_file_with_ext("", ext));
342342

343343
let mut hasher = Sha256::new();
344-
try!(utils::download_file(&url, &file, Some(&mut hasher), ntfy!(&cfg.notify_handler)));
344+
try!(utils::download_file(&url, &file, Some(&mut hasher),
345+
&|n| (cfg.notify_handler)(n.into())));
345346
let actual_hash = hasher.result_str();
346347

347348
if hash != actual_hash {
@@ -352,26 +353,27 @@ pub fn download_and_check<'a>(url_str: &str,
352353
calculated: actual_hash,
353354
}.into());
354355
} else {
355-
cfg.notify_handler.call(Notification::ChecksumValid(url_str));
356+
(cfg.notify_handler)(Notification::ChecksumValid(url_str));
356357
}
357358

358359
// TODO: Check the signature of the file
359360

360361
Ok(Some((file, partial_hash)))
361362
}
362363

363-
#[derive(Copy, Clone, Debug)]
364+
#[derive(Copy, Clone)]
364365
pub struct DownloadCfg<'a> {
365366
pub dist_root: &'a str,
366367
pub temp_cfg: &'a temp::Cfg,
367-
pub notify_handler: NotifyHandler<'a>,
368+
pub notify_handler: &'a Fn(Notification),
368369
}
369370

370371
pub fn download_hash(url: &str, cfg: DownloadCfg) -> Result<String> {
371372
let hash_url = try!(utils::parse_url(&(url.to_owned() + ".sha256")));
372373
let hash_file = try!(cfg.temp_cfg.new_file());
373374

374-
try!(utils::download_file(&hash_url, &hash_file, None, ntfy!(&cfg.notify_handler)));
375+
try!(utils::download_file(&hash_url, &hash_file, None,
376+
&|n| (cfg.notify_handler)(n.into())));
375377

376378
Ok(try!(utils::read_file("hash", &hash_file).map(|s| s[0..64].to_owned())))
377379
}
@@ -398,7 +400,7 @@ pub fn update_from_dist<'a>(download: DownloadCfg<'a>,
398400
};
399401

400402
// TODO: Add a notification about which manifest version is going to be used
401-
download.notify_handler.call(Notification::DownloadingManifest(&toolchain_str));
403+
(download.notify_handler)(Notification::DownloadingManifest(&toolchain_str));
402404
match dl_v2_manifest(download, update_hash, toolchain) {
403405
Ok(Some((m, hash))) => {
404406
return match try!(manifestation.update(&m, changes, &download.temp_cfg,
@@ -410,7 +412,7 @@ pub fn update_from_dist<'a>(download: DownloadCfg<'a>,
410412
Ok(None) => return Ok(None),
411413
Err(Error(ErrorKind::Utils(::rustup_utils::ErrorKind::Download404 { .. }), _)) => {
412414
// Proceed to try v1 as a fallback
413-
download.notify_handler.call(Notification::DownloadingLegacyManifest);
415+
(download.notify_handler)(Notification::DownloadingLegacyManifest);
414416
}
415417
Err(e) => return Err(e)
416418
}

src/rustup-dist/src/download.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ use sha2::{Sha256, Digest};
88
use std::path::Path;
99
use std::process::Command;
1010

11-
#[derive(Debug)]
1211
pub struct DownloadCfg<'a> {
1312
pub temp_cfg: &'a temp::Cfg,
14-
pub notify_handler: NotifyHandler<'a>,
13+
pub notify_handler: &'a Fn(Notification),
1514
pub gpg_key: Option<&'a str>,
1615
}
1716

@@ -22,7 +21,8 @@ impl<'a> DownloadCfg<'a> {
2221

2322
let sig_url = try!(utils::parse_url(&format!("{}.asc", url)));
2423
let sig_file = try!(self.temp_cfg.new_file());
25-
try!(utils::download_file(&sig_url, &sig_file, None, ntfy!(&self.notify_handler)));
24+
try!(utils::download_file(&sig_url, &sig_file, None,
25+
&|n| (self.notify_handler)(n.into())));
2626

2727
let target_url = try!(utils::parse_url(url));
2828
let target_file = try!(self.temp_cfg.new_file());
@@ -32,7 +32,7 @@ impl<'a> DownloadCfg<'a> {
3232
try!(utils::download_file(&target_url,
3333
&target_file,
3434
None,
35-
ntfy!(&self.notify_handler)));
35+
&|n| (self.notify_handler)(n.into())));
3636

3737
let key_file = try!(self.temp_cfg.new_file());
3838
let key_filename: &Path = &key_file;
@@ -62,7 +62,8 @@ impl<'a> DownloadCfg<'a> {
6262

6363
let hash_url = try!(utils::parse_url(&format!("{}.sha256", url)));
6464
let hash_file = try!(self.temp_cfg.new_file());
65-
try!(utils::download_file(&hash_url, &hash_file, None, ntfy!(&self.notify_handler)));
65+
try!(utils::download_file(&hash_url, &hash_file, None,
66+
&|n| (self.notify_handler)(n.into())));
6667

6768
let hash = try!(utils::read_file("hash", &hash_file).map(|s| s[0..64].to_owned()));
6869
let mut hasher = Sha256::new();
@@ -72,7 +73,7 @@ impl<'a> DownloadCfg<'a> {
7273
try!(utils::download_file(&target_url,
7374
&target_file,
7475
Some(&mut hasher),
75-
ntfy!(&self.notify_handler)));
76+
&|n| (self.notify_handler)(n.into())));
7677

7778
let actual_hash = hasher.result_str();
7879

@@ -84,7 +85,7 @@ impl<'a> DownloadCfg<'a> {
8485
calculated: actual_hash,
8586
}.into());
8687
} else {
87-
self.notify_handler.call(Notification::ChecksumValid(url));
88+
(self.notify_handler)(Notification::ChecksumValid(url));
8889
}
8990

9091
Ok(target_file)

src/rustup-dist/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extern crate error_chain;
1414
extern crate sha2;
1515

1616
pub use errors::*;
17-
pub use notifications::{Notification, NotifyHandler};
17+
pub use notifications::{Notification};
1818

1919
pub mod temp;
2020

0 commit comments

Comments
 (0)