]> git.lizzy.rs Git - rust.git/commitdiff
librustc_back: use unboxed closures
authorJorge Aparicio <japaricious@gmail.com>
Mon, 8 Dec 2014 23:35:22 +0000 (18:35 -0500)
committerJorge Aparicio <japaricious@gmail.com>
Sat, 13 Dec 2014 22:03:47 +0000 (17:03 -0500)
src/librustc_back/archive.rs
src/librustc_back/lib.rs
src/librustc_back/rpath.rs
src/librustc_back/sha2.rs

index a88bcafaa64b389aba7a7a9c8a8093994f21e47f..3a4510703166c84a835b983ceaf0746b86c5ee95 100644 (file)
@@ -279,8 +279,9 @@ pub fn build(self) -> Archive<'a> {
         self.archive
     }
 
-    fn add_archive(&mut self, archive: &Path, name: &str,
-                   skip: |&str| -> bool) -> io::IoResult<()> {
+    fn add_archive<F>(&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.
index fc98a5cd6b559e1dc87a223eac374d4f6fa5dac7..cb547df7d9cd83a9cc8a710eb586730431d2e899 100644 (file)
@@ -31,6 +31,7 @@
 
 #![allow(unknown_features)]
 #![feature(globs, phase, macro_rules, slicing_syntax)]
+#![feature(unboxed_closures)]
 
 #[phase(plugin, link)]
 extern crate log;
index a90b49ba101fa57c426ed54a63ce92aa2686edc7..1f8549098d949f044c4768d295b5baa3eb5eaeb4 100644 (file)
 use std::io::IoError;
 use syntax::ast;
 
-pub struct RPathConfig<'a> {
+pub struct RPathConfig<F, G> where
+    F: FnOnce() -> Path,
+    G: FnMut(&Path) -> Result<Path, IoError>,
+{
     pub used_crates: Vec<(ast::CrateNum, Option<Path>)>,
     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<Path, IoError>
+    pub get_install_prefix_lib_path: F,
+    pub realpath: G,
 }
 
-pub fn get_rpath_flags(config: RPathConfig) -> Vec<String> {
-
+pub fn get_rpath_flags<F, G>(config: RPathConfig<F, G>) -> Vec<String> where
+    F: FnOnce() -> Path,
+    G: FnMut(&Path) -> Result<Path, IoError>,
+{
     // No rpath on windows
     if !config.has_rpath {
         return Vec::new();
@@ -52,8 +57,10 @@ fn rpaths_to_flags(rpaths: &[String]) -> Vec<String> {
     return ret;
 }
 
-fn get_rpaths(mut config: RPathConfig,
-              libs: &[Path]) -> Vec<String> {
+fn get_rpaths<F, G>(mut config: RPathConfig<F, G>, libs: &[Path]) -> Vec<String> where
+    F: FnOnce() -> Path,
+    G: FnMut(&Path) -> Result<Path, IoError>,
+{
     debug!("output: {}", config.out_filename.display());
     debug!("libs:");
     for libpath in libs.iter() {
@@ -86,13 +93,18 @@ fn log_rpaths(desc: &str, rpaths: &[String]) {
     return rpaths;
 }
 
-fn get_rpaths_relative_to_output(config: &mut RPathConfig,
-                                 libs: &[Path]) -> Vec<String> {
+fn get_rpaths_relative_to_output<F, G>(config: &mut RPathConfig<F, G>,
+                                       libs: &[Path]) -> Vec<String> where
+    F: FnOnce() -> Path,
+    G: FnMut(&Path) -> Result<Path, IoError>,
+{
     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<F, G>(config: &mut RPathConfig<F, G>, lib: &Path) -> String where
+    F: FnOnce() -> Path,
+    G: FnMut(&Path) -> Result<Path, IoError>,
+{
     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<F, G>(config: RPathConfig<F, G>) -> String where
+    F: FnOnce() -> Path,
+    G: FnMut(&Path) -> Result<Path, IoError>,
+{
     let path = (config.get_install_prefix_lib_path)();
     let path = os::make_absolute(&path).unwrap();
     // FIXME (#9639): This needs to handle non-utf8 paths
index 1b662ef17876007c53c34385c25ca138f93ca417..1587104ca49d16443664352c8fc3c5677d76e4ab 100644 (file)
@@ -82,7 +82,8 @@ fn add_bytes_to_bits<T: Int + ToBits>(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<F>(&mut self, input: &[u8], func: F) where
+        F: FnMut(&[u8]);
 
     /// Reset the buffer.
     fn reset(&mut self);
@@ -125,7 +126,9 @@ fn new() -> FixedBuffer64 {
 }
 
 impl FixedBuffer for FixedBuffer64 {
-    fn input(&mut self, input: &[u8], func: |&[u8]|) {
+    fn input<F>(&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<F>(&mut self, rem: uint, func: F) where F: FnMut(&[u8]);
 }
 
 impl <T: FixedBuffer> StandardPadding for T {
-    fn standard_padding(&mut self, rem: uint, func: |&[u8]|) {
+    fn standard_padding<F>(&mut self, rem: uint, mut func: F) where F: FnMut(&[u8]) {
         let size = self.size();
 
         self.next(1)[0] = 128;