Skip to content

Commit 451eef5

Browse files
author
Jorge Aparicio
committed
librustc_back: use unboxed closures
1 parent d3d707c commit 451eef5

File tree

4 files changed

+38
-18
lines changed

4 files changed

+38
-18
lines changed

src/librustc_back/archive.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,9 @@ impl<'a> ArchiveBuilder<'a> {
279279
self.archive
280280
}
281281

282-
fn add_archive(&mut self, archive: &Path, name: &str,
283-
skip: |&str| -> bool) -> io::IoResult<()> {
282+
fn add_archive<F>(&mut self, archive: &Path, name: &str, mut skip: F) -> io::IoResult<()> where
283+
F: FnMut(&str) -> bool,
284+
{
284285
let loc = TempDir::new("rsar").unwrap();
285286

286287
// First, extract the contents of the archive to a temporary directory.

src/librustc_back/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#![allow(unknown_features)]
3333
#![feature(globs, phase, macro_rules, slicing_syntax)]
34+
#![feature(unboxed_closures)]
3435

3536
#[phase(plugin, link)]
3637
extern crate log;

src/librustc_back/rpath.rs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,22 @@ use std::os;
1414
use std::io::IoError;
1515
use syntax::ast;
1616

17-
pub struct RPathConfig<'a> {
17+
pub struct RPathConfig<F, G> where
18+
F: FnOnce() -> Path,
19+
G: FnMut(&Path) -> Result<Path, IoError>,
20+
{
1821
pub used_crates: Vec<(ast::CrateNum, Option<Path>)>,
1922
pub out_filename: Path,
2023
pub is_like_osx: bool,
2124
pub has_rpath: bool,
22-
pub get_install_prefix_lib_path: ||:'a -> Path,
23-
pub realpath: |&Path|:'a -> Result<Path, IoError>
25+
pub get_install_prefix_lib_path: F,
26+
pub realpath: G,
2427
}
2528

26-
pub fn get_rpath_flags(config: RPathConfig) -> Vec<String> {
27-
29+
pub fn get_rpath_flags<F, G>(config: RPathConfig<F, G>) -> Vec<String> where
30+
F: FnOnce() -> Path,
31+
G: FnMut(&Path) -> Result<Path, IoError>,
32+
{
2833
// No rpath on windows
2934
if !config.has_rpath {
3035
return Vec::new();
@@ -52,8 +57,10 @@ fn rpaths_to_flags(rpaths: &[String]) -> Vec<String> {
5257
return ret;
5358
}
5459

55-
fn get_rpaths(mut config: RPathConfig,
56-
libs: &[Path]) -> Vec<String> {
60+
fn get_rpaths<F, G>(mut config: RPathConfig<F, G>, libs: &[Path]) -> Vec<String> where
61+
F: FnOnce() -> Path,
62+
G: FnMut(&Path) -> Result<Path, IoError>,
63+
{
5764
debug!("output: {}", config.out_filename.display());
5865
debug!("libs:");
5966
for libpath in libs.iter() {
@@ -86,13 +93,18 @@ fn get_rpaths(mut config: RPathConfig,
8693
return rpaths;
8794
}
8895

89-
fn get_rpaths_relative_to_output(config: &mut RPathConfig,
90-
libs: &[Path]) -> Vec<String> {
96+
fn get_rpaths_relative_to_output<F, G>(config: &mut RPathConfig<F, G>,
97+
libs: &[Path]) -> Vec<String> where
98+
F: FnOnce() -> Path,
99+
G: FnMut(&Path) -> Result<Path, IoError>,
100+
{
91101
libs.iter().map(|a| get_rpath_relative_to_output(config, a)).collect()
92102
}
93103

94-
fn get_rpath_relative_to_output(config: &mut RPathConfig,
95-
lib: &Path) -> String {
104+
fn get_rpath_relative_to_output<F, G>(config: &mut RPathConfig<F, G>, lib: &Path) -> String where
105+
F: FnOnce() -> Path,
106+
G: FnMut(&Path) -> Result<Path, IoError>,
107+
{
96108
use std::os;
97109

98110
// Mac doesn't appear to support $ORIGIN
@@ -114,7 +126,10 @@ fn get_rpath_relative_to_output(config: &mut RPathConfig,
114126
relative.as_str().expect("non-utf8 component in path"))
115127
}
116128

117-
fn get_install_prefix_rpath(config: RPathConfig) -> String {
129+
fn get_install_prefix_rpath<F, G>(config: RPathConfig<F, G>) -> String where
130+
F: FnOnce() -> Path,
131+
G: FnMut(&Path) -> Result<Path, IoError>,
132+
{
118133
let path = (config.get_install_prefix_lib_path)();
119134
let path = os::make_absolute(&path).unwrap();
120135
// FIXME (#9639): This needs to handle non-utf8 paths

src/librustc_back/sha2.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ fn add_bytes_to_bits<T: Int + ToBits>(bits: T, bytes: T) -> T {
8282
trait FixedBuffer {
8383
/// Input a vector of bytes. If the buffer becomes full, process it with the provided
8484
/// function and then clear the buffer.
85-
fn input(&mut self, input: &[u8], func: |&[u8]|);
85+
fn input<F>(&mut self, input: &[u8], func: F) where
86+
F: FnMut(&[u8]);
8687

8788
/// Reset the buffer.
8889
fn reset(&mut self);
@@ -125,7 +126,9 @@ impl FixedBuffer64 {
125126
}
126127

127128
impl FixedBuffer for FixedBuffer64 {
128-
fn input(&mut self, input: &[u8], func: |&[u8]|) {
129+
fn input<F>(&mut self, input: &[u8], mut func: F) where
130+
F: FnMut(&[u8]),
131+
{
129132
let mut i = 0;
130133

131134
let size = self.size();
@@ -201,11 +204,11 @@ trait StandardPadding {
201204
/// guaranteed to have exactly rem remaining bytes when it returns. If there are not at least
202205
/// rem bytes available, the buffer will be zero padded, processed, cleared, and then filled
203206
/// with zeros again until only rem bytes are remaining.
204-
fn standard_padding(&mut self, rem: uint, func: |&[u8]|);
207+
fn standard_padding<F>(&mut self, rem: uint, func: F) where F: FnMut(&[u8]);
205208
}
206209

207210
impl <T: FixedBuffer> StandardPadding for T {
208-
fn standard_padding(&mut self, rem: uint, func: |&[u8]|) {
211+
fn standard_padding<F>(&mut self, rem: uint, mut func: F) where F: FnMut(&[u8]) {
209212
let size = self.size();
210213

211214
self.next(1)[0] = 128;

0 commit comments

Comments
 (0)