diff --git a/src/librustc_back/archive.rs b/src/librustc_back/archive.rs index a88bcafaa64b..3a4510703166 100644 --- a/src/librustc_back/archive.rs +++ b/src/librustc_back/archive.rs @@ -279,8 +279,9 @@ impl<'a> ArchiveBuilder<'a> { self.archive } - fn add_archive(&mut self, archive: &Path, name: &str, - skip: |&str| -> bool) -> io::IoResult<()> { + fn add_archive(&mut self, archive: &Path, name: &str, mut skip: F) -> io::IoResult<()> where + F: FnMut(&str) -> bool, + { let loc = TempDir::new("rsar").unwrap(); // First, extract the contents of the archive to a temporary directory. diff --git a/src/librustc_back/lib.rs b/src/librustc_back/lib.rs index fc98a5cd6b55..cb547df7d9cd 100644 --- a/src/librustc_back/lib.rs +++ b/src/librustc_back/lib.rs @@ -31,6 +31,7 @@ #![allow(unknown_features)] #![feature(globs, phase, macro_rules, slicing_syntax)] +#![feature(unboxed_closures)] #[phase(plugin, link)] extern crate log; diff --git a/src/librustc_back/rpath.rs b/src/librustc_back/rpath.rs index a90b49ba101f..1f8549098d94 100644 --- a/src/librustc_back/rpath.rs +++ b/src/librustc_back/rpath.rs @@ -14,17 +14,22 @@ use std::os; use std::io::IoError; use syntax::ast; -pub struct RPathConfig<'a> { +pub struct RPathConfig where + F: FnOnce() -> Path, + G: FnMut(&Path) -> Result, +{ pub used_crates: Vec<(ast::CrateNum, Option)>, pub out_filename: Path, pub is_like_osx: bool, pub has_rpath: bool, - pub get_install_prefix_lib_path: ||:'a -> Path, - pub realpath: |&Path|:'a -> Result + pub get_install_prefix_lib_path: F, + pub realpath: G, } -pub fn get_rpath_flags(config: RPathConfig) -> Vec { - +pub fn get_rpath_flags(config: RPathConfig) -> Vec where + F: FnOnce() -> Path, + G: FnMut(&Path) -> Result, +{ // No rpath on windows if !config.has_rpath { return Vec::new(); @@ -52,8 +57,10 @@ fn rpaths_to_flags(rpaths: &[String]) -> Vec { return ret; } -fn get_rpaths(mut config: RPathConfig, - libs: &[Path]) -> Vec { +fn get_rpaths(mut config: RPathConfig, libs: &[Path]) -> Vec where + F: FnOnce() -> Path, + G: FnMut(&Path) -> Result, +{ debug!("output: {}", config.out_filename.display()); debug!("libs:"); for libpath in libs.iter() { @@ -86,13 +93,18 @@ fn get_rpaths(mut config: RPathConfig, return rpaths; } -fn get_rpaths_relative_to_output(config: &mut RPathConfig, - libs: &[Path]) -> Vec { +fn get_rpaths_relative_to_output(config: &mut RPathConfig, + libs: &[Path]) -> Vec where + F: FnOnce() -> Path, + G: FnMut(&Path) -> Result, +{ libs.iter().map(|a| get_rpath_relative_to_output(config, a)).collect() } -fn get_rpath_relative_to_output(config: &mut RPathConfig, - lib: &Path) -> String { +fn get_rpath_relative_to_output(config: &mut RPathConfig, lib: &Path) -> String where + F: FnOnce() -> Path, + G: FnMut(&Path) -> Result, +{ use std::os; // Mac doesn't appear to support $ORIGIN @@ -114,7 +126,10 @@ fn get_rpath_relative_to_output(config: &mut RPathConfig, relative.as_str().expect("non-utf8 component in path")) } -fn get_install_prefix_rpath(config: RPathConfig) -> String { +fn get_install_prefix_rpath(config: RPathConfig) -> String where + F: FnOnce() -> Path, + G: FnMut(&Path) -> Result, +{ let path = (config.get_install_prefix_lib_path)(); let path = os::make_absolute(&path).unwrap(); // FIXME (#9639): This needs to handle non-utf8 paths diff --git a/src/librustc_back/sha2.rs b/src/librustc_back/sha2.rs index 1b662ef17876..1587104ca49d 100644 --- a/src/librustc_back/sha2.rs +++ b/src/librustc_back/sha2.rs @@ -82,7 +82,8 @@ fn add_bytes_to_bits(bits: T, bytes: T) -> T { trait FixedBuffer { /// Input a vector of bytes. If the buffer becomes full, process it with the provided /// function and then clear the buffer. - fn input(&mut self, input: &[u8], func: |&[u8]|); + fn input(&mut self, input: &[u8], func: F) where + F: FnMut(&[u8]); /// Reset the buffer. fn reset(&mut self); @@ -125,7 +126,9 @@ impl FixedBuffer64 { } impl FixedBuffer for FixedBuffer64 { - fn input(&mut self, input: &[u8], func: |&[u8]|) { + fn input(&mut self, input: &[u8], mut func: F) where + F: FnMut(&[u8]), + { let mut i = 0; let size = self.size(); @@ -201,11 +204,11 @@ trait StandardPadding { /// guaranteed to have exactly rem remaining bytes when it returns. If there are not at least /// rem bytes available, the buffer will be zero padded, processed, cleared, and then filled /// with zeros again until only rem bytes are remaining. - fn standard_padding(&mut self, rem: uint, func: |&[u8]|); + fn standard_padding(&mut self, rem: uint, func: F) where F: FnMut(&[u8]); } impl StandardPadding for T { - fn standard_padding(&mut self, rem: uint, func: |&[u8]|) { + fn standard_padding(&mut self, rem: uint, mut func: F) where F: FnMut(&[u8]) { let size = self.size(); self.next(1)[0] = 128;