Skip to content

Commit 47b8479

Browse files
committed
auto merge of #20363 : japaric/rust/moar-uc, r=nmatsakis
The the last argument of the `ItemDecorator::expand` method has changed to `Box<FnMut>`. Syntax extensions will break. [breaking-change] --- This PR removes pretty much all the remaining uses of boxed closures from the libraries. There are still boxed closures under the `test` directory, but I think those should be removed or replaced with unboxed closures at the same time we remove boxed closures from the language. In a few places I had to do some contortions (see the first commit for an example) to work around issue #19596. I have marked those workarounds with FIXMEs. In the future when `&mut F where F: FnMut` implements the `FnMut` trait, we should be able to remove those workarounds. I've take care to avoid placing the workaround functions in the public API. Since `let f = || {}` always gets type checked as a boxed closure, I have explictly annotated those closures (with e.g. `|&:| {}`) to force the compiler to type check them as unboxed closures. Instead of removing the type aliases (like `GetCrateDataCb`), I could have replaced them with newtypes. But this seemed like overcomplicating things for little to no gain. I think we should be able to remove the boxed closures from the languge after this PR lands. (I'm being optimistic here) r? @alexcrichton or @aturon cc @nikomatsakis
2 parents 7d4f487 + 10bbf69 commit 47b8479

File tree

59 files changed

+248
-224
lines changed

Some content is hidden

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

59 files changed

+248
-224
lines changed

src/libcollections/str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ impl<'a> Iterator<char> for Decompositions<'a> {
202202
let buffer = &mut self.buffer;
203203
let sorted = &mut self.sorted;
204204
{
205-
let callback = |d| {
205+
let callback = |&mut: d| {
206206
let class =
207207
unicode::char::canonical_combining_class(d);
208208
if class == 0 && !*sorted {

src/libcore/fmt/float.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,10 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
225225
// cut off the one extra digit, and depending on its value
226226
// round the remaining ones.
227227
if limit_digits && dig == digit_count {
228-
let ascii2value = |chr: u8| {
228+
let ascii2value = |&: chr: u8| {
229229
(chr as char).to_digit(radix).unwrap()
230230
};
231-
let value2ascii = |val: uint| {
231+
let value2ascii = |&: val: uint| {
232232
char::from_digit(val, radix).unwrap() as u8
233233
};
234234

src/libcore/fmt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ impl<'a> Formatter<'a> {
398398
}
399399

400400
// Writes the sign if it exists, and then the prefix if it was requested
401-
let write_prefix = |f: &mut Formatter| {
401+
let write_prefix = |&: f: &mut Formatter| {
402402
for c in sign.into_iter() {
403403
let mut b = [0, ..4];
404404
let n = c.encode_utf8(&mut b).unwrap_or(0);

src/libgetopts/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ fn each_split_within<F>(ss: &str, lim: uint, mut it: F) -> bool where
875875
lim = fake_i;
876876
}
877877

878-
let machine: |&mut bool, (uint, char)| -> bool = |cont, (i, c)| {
878+
let mut machine = |&mut: cont: &mut bool, (i, c): (uint, char)| -> bool {
879879
let whitespace = if c.is_whitespace() { Ws } else { Cr };
880880
let limit = if (i - slice_start + 1) <= lim { UnderLim } else { OverLim };
881881

src/librustc/metadata/creader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ fn extract_crate_info(e: &Env, i: &ast::ViewItem) -> Option<CrateInfo> {
177177
}
178178

179179
pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
180-
let err = |s: &str| {
180+
let err = |&: s: &str| {
181181
match (sp, sess) {
182182
(_, None) => panic!("{}", s),
183183
(Some(sp), Some(sess)) => sess.span_err(sp, s),

src/librustc/metadata/csearch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn each_child_of_item<F>(cstore: &cstore::CStore,
6262
F: FnMut(decoder::DefLike, ast::Name, ast::Visibility),
6363
{
6464
let crate_data = cstore.get_crate_data(def_id.krate);
65-
let get_crate_data: decoder::GetCrateDataCb = |cnum| {
65+
let get_crate_data = |&mut: cnum| {
6666
cstore.get_crate_data(cnum)
6767
};
6868
decoder::each_child_of_item(cstore.intr.clone(),
@@ -79,7 +79,7 @@ pub fn each_top_level_item_of_crate<F>(cstore: &cstore::CStore,
7979
F: FnMut(decoder::DefLike, ast::Name, ast::Visibility),
8080
{
8181
let crate_data = cstore.get_crate_data(cnum);
82-
let get_crate_data: decoder::GetCrateDataCb = |cnum| {
82+
let get_crate_data = |&mut: cnum| {
8383
cstore.get_crate_data(cnum)
8484
};
8585
decoder::each_top_level_item_of_crate(cstore.intr.clone(),

src/librustc/metadata/decoder.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -487,14 +487,13 @@ pub fn each_lang_item<F>(cdata: Cmd, mut f: F) -> bool where
487487
})
488488
}
489489

490-
pub type GetCrateDataCb<'a> = |ast::CrateNum|: 'a -> Rc<crate_metadata>;
491-
492-
fn each_child_of_item_or_crate<F>(intr: Rc<IdentInterner>,
493-
cdata: Cmd,
494-
item_doc: rbml::Doc,
495-
get_crate_data: GetCrateDataCb,
496-
mut callback: F) where
490+
fn each_child_of_item_or_crate<F, G>(intr: Rc<IdentInterner>,
491+
cdata: Cmd,
492+
item_doc: rbml::Doc,
493+
mut get_crate_data: G,
494+
mut callback: F) where
497495
F: FnMut(DefLike, ast::Name, ast::Visibility),
496+
G: FnMut(ast::CrateNum) -> Rc<crate_metadata>,
498497
{
499498
// Iterate over all children.
500499
let _ = reader::tagged_docs(item_doc, tag_mod_child, |child_info_doc| {
@@ -608,12 +607,13 @@ fn each_child_of_item_or_crate<F>(intr: Rc<IdentInterner>,
608607
}
609608

610609
/// Iterates over each child of the given item.
611-
pub fn each_child_of_item<F>(intr: Rc<IdentInterner>,
612-
cdata: Cmd,
613-
id: ast::NodeId,
614-
get_crate_data: GetCrateDataCb,
615-
callback: F) where
610+
pub fn each_child_of_item<F, G>(intr: Rc<IdentInterner>,
611+
cdata: Cmd,
612+
id: ast::NodeId,
613+
get_crate_data: G,
614+
callback: F) where
616615
F: FnMut(DefLike, ast::Name, ast::Visibility),
616+
G: FnMut(ast::CrateNum) -> Rc<crate_metadata>,
617617
{
618618
// Find the item.
619619
let root_doc = rbml::Doc::new(cdata.data());
@@ -631,11 +631,12 @@ pub fn each_child_of_item<F>(intr: Rc<IdentInterner>,
631631
}
632632

633633
/// Iterates over all the top-level crate items.
634-
pub fn each_top_level_item_of_crate<F>(intr: Rc<IdentInterner>,
635-
cdata: Cmd,
636-
get_crate_data: GetCrateDataCb,
637-
callback: F) where
634+
pub fn each_top_level_item_of_crate<F, G>(intr: Rc<IdentInterner>,
635+
cdata: Cmd,
636+
get_crate_data: G,
637+
callback: F) where
638638
F: FnMut(DefLike, ast::Name, ast::Visibility),
639+
G: FnMut(ast::CrateNum) -> Rc<crate_metadata>,
639640
{
640641
let root_doc = rbml::Doc::new(cdata.data());
641642
let misc_info_doc = reader::get_doc(root_doc, tag_misc_info);

src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
14181418
encode_parent_sort(rbml_w, 't');
14191419

14201420
let trait_item = &ms[i];
1421-
let encode_trait_item = |rbml_w: &mut Encoder| {
1421+
let encode_trait_item = |&: rbml_w: &mut Encoder| {
14221422
// If this is a static method, we've already
14231423
// encoded this.
14241424
if is_nonstatic_method {

src/librustc/metadata/filesearch.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ pub enum FileMatch {
3030
// FIXME (#2658): I'm not happy how this module turned out. Should
3131
// probably just be folded into cstore.
3232

33-
/// Functions with type `pick` take a parent directory as well as
34-
/// a file found in that directory.
35-
pub type pick<'a> = |path: &Path|: 'a -> FileMatch;
36-
3733
pub struct FileSearch<'a> {
3834
pub sysroot: &'a Path,
3935
pub search_paths: &'a SearchPaths,
@@ -95,7 +91,7 @@ impl<'a> FileSearch<'a> {
9591
make_target_lib_path(self.sysroot, self.triple)
9692
}
9793

98-
pub fn search(&self, pick: pick) {
94+
pub fn search<F>(&self, mut pick: F) where F: FnMut(&Path) -> FileMatch {
9995
self.for_each_lib_search_path(|lib_search_path| {
10096
debug!("searching {}", lib_search_path.display());
10197
match fs::readdir(lib_search_path) {

src/librustc/middle/check_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &ast::Expr) -> bool {
185185
ast::ExprBlock(ref block) => {
186186
// Check all statements in the block
187187
for stmt in block.stmts.iter() {
188-
let block_span_err = |span|
188+
let block_span_err = |&: span|
189189
span_err!(v.tcx.sess, span, E0016,
190190
"blocks in constants are limited to items and \
191191
tail expressions");

0 commit comments

Comments
 (0)