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

+1-1
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

+2-2
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

+1-1
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

+1-1
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

+1-1
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

+2-2
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

+17-16
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

+1-1
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

+1-5
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

+1-1
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");

src/librustc/middle/check_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
10121012
})
10131013
}
10141014

1015-
let check_move: |&Pat, Option<&Pat>| = |p, sub| {
1015+
let check_move = |&: p: &Pat, sub: Option<&Pat>| {
10161016
// check legality of moving out of the enum
10171017

10181018
// x @ Foo(..) is legal, but x @ Foo(y) isn't.

src/librustc/middle/infer/region_inference/graphviz.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl<'a, 'tcx> ConstraintGraph<'a, 'tcx> {
136136
let mut i = 0;
137137
let mut node_ids = FnvHashMap::new();
138138
{
139-
let add_node = |node| {
139+
let mut add_node = |&mut : node| {
140140
if let Vacant(e) = node_ids.entry(node) {
141141
e.set(i);
142142
i += 1;

src/librustc/middle/mem_categorization.rs

+20-18
Original file line numberDiff line numberDiff line change
@@ -1122,11 +1122,15 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
11221122
})
11231123
}
11241124

1125-
// FIXME(#19596) unbox `op`
1126-
pub fn cat_pattern(&self,
1127-
cmt: cmt<'tcx>,
1128-
pat: &ast::Pat,
1129-
op: |&MemCategorizationContext<'t, TYPER>, cmt<'tcx>, &ast::Pat|)
1125+
pub fn cat_pattern<F>(&self, cmt: cmt<'tcx>, pat: &ast::Pat, mut op: F) where
1126+
F: FnMut(&MemCategorizationContext<'t, TYPER>, cmt<'tcx>, &ast::Pat),
1127+
{
1128+
self.cat_pattern_(cmt, pat, &mut op)
1129+
}
1130+
1131+
// FIXME(#19596) This is a workaround, but there should be a better way to do this
1132+
fn cat_pattern_<F>(&self, cmt: cmt<'tcx>, pat: &ast::Pat, op: &mut F) where
1133+
F: FnMut(&MemCategorizationContext<'t, TYPER>, cmt<'tcx>, &ast::Pat),
11301134
{
11311135
// Here, `cmt` is the categorization for the value being
11321136
// matched and pat is the pattern it is being matched against.
@@ -1177,7 +1181,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
11771181
pat.id, pprust::pat_to_string(pat),
11781182
cmt.repr(self.tcx()));
11791183

1180-
op(self, cmt.clone(), pat);
1184+
(*op)(self, cmt.clone(), pat);
11811185

11821186
let def_map = self.tcx().def_map.borrow();
11831187
let opt_def = def_map.get(&pat.id);
@@ -1214,7 +1218,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
12141218
pat, cmt.clone(), subpat_ty,
12151219
InteriorField(PositionalField(i)));
12161220

1217-
self.cat_pattern(subcmt, &**subpat, |x,y,z| op(x,y,z));
1221+
self.cat_pattern_(subcmt, &**subpat, op);
12181222
}
12191223
}
12201224
Some(&def::DefStruct(..)) => {
@@ -1224,13 +1228,12 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
12241228
self.cat_imm_interior(
12251229
pat, cmt.clone(), subpat_ty,
12261230
InteriorField(PositionalField(i)));
1227-
self.cat_pattern(cmt_field, &**subpat,
1228-
|x,y,z| op(x,y,z));
1231+
self.cat_pattern_(cmt_field, &**subpat, op);
12291232
}
12301233
}
12311234
Some(&def::DefConst(..)) => {
12321235
for subpat in subpats.iter() {
1233-
self.cat_pattern(cmt.clone(), &**subpat, |x,y,z| op(x,y,z));
1236+
self.cat_pattern_(cmt.clone(), &**subpat, op);
12341237
}
12351238
}
12361239
_ => {
@@ -1242,7 +1245,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
12421245
}
12431246

12441247
ast::PatIdent(_, _, Some(ref subpat)) => {
1245-
self.cat_pattern(cmt, &**subpat, op);
1248+
self.cat_pattern_(cmt, &**subpat, op);
12461249
}
12471250

12481251
ast::PatIdent(_, _, None) => {
@@ -1254,7 +1257,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
12541257
for fp in field_pats.iter() {
12551258
let field_ty = self.pat_ty(&*fp.node.pat); // see (*2)
12561259
let cmt_field = self.cat_field(pat, cmt.clone(), fp.node.ident.name, field_ty);
1257-
self.cat_pattern(cmt_field, &*fp.node.pat, |x,y,z| op(x,y,z));
1260+
self.cat_pattern_(cmt_field, &*fp.node.pat, op);
12581261
}
12591262
}
12601263

@@ -1266,29 +1269,28 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
12661269
self.cat_imm_interior(
12671270
pat, cmt.clone(), subpat_ty,
12681271
InteriorField(PositionalField(i)));
1269-
self.cat_pattern(subcmt, &**subpat, |x,y,z| op(x,y,z));
1272+
self.cat_pattern_(subcmt, &**subpat, op);
12701273
}
12711274
}
12721275

12731276
ast::PatBox(ref subpat) | ast::PatRegion(ref subpat) => {
12741277
// @p1, ~p1, ref p1
12751278
let subcmt = self.cat_deref(pat, cmt, 0, false);
1276-
self.cat_pattern(subcmt, &**subpat, op);
1279+
self.cat_pattern_(subcmt, &**subpat, op);
12771280
}
12781281

12791282
ast::PatVec(ref before, ref slice, ref after) => {
12801283
let elt_cmt = self.cat_index(pat, self.deref_vec(pat, cmt));
12811284
for before_pat in before.iter() {
1282-
self.cat_pattern(elt_cmt.clone(), &**before_pat,
1283-
|x,y,z| op(x,y,z));
1285+
self.cat_pattern_(elt_cmt.clone(), &**before_pat, op);
12841286
}
12851287
for slice_pat in slice.iter() {
12861288
let slice_ty = self.pat_ty(&**slice_pat);
12871289
let slice_cmt = self.cat_rvalue_node(pat.id(), pat.span(), slice_ty);
1288-
self.cat_pattern(slice_cmt, &**slice_pat, |x,y,z| op(x,y,z));
1290+
self.cat_pattern_(slice_cmt, &**slice_pat, op);
12891291
}
12901292
for after_pat in after.iter() {
1291-
self.cat_pattern(elt_cmt.clone(), &**after_pat, |x,y,z| op(x,y,z));
1293+
self.cat_pattern_(elt_cmt.clone(), &**after_pat, op);
12921294
}
12931295
}
12941296

src/librustc/middle/privacy.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
749749
fn check_path(&mut self, span: Span, path_id: ast::NodeId, path: &ast::Path) {
750750
debug!("privacy - path {}", self.nodestr(path_id));
751751
let orig_def = self.tcx.def_map.borrow()[path_id].clone();
752-
let ck = |tyname: &str| {
752+
let ck = |&: tyname: &str| {
753753
let ck_public = |def: ast::DefId| {
754754
let name = token::get_ident(path.segments.last().unwrap().identifier);
755755
let origdid = orig_def.def_id();
@@ -921,7 +921,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
921921
}
922922
}
923923
ast::ExprPath(..) => {
924-
let guard = |did: ast::DefId| {
924+
let guard = |&: did: ast::DefId| {
925925
let fields = ty::lookup_struct_fields(self.tcx, did);
926926
let any_priv = fields.iter().any(|f| {
927927
f.vis != ast::Public && (
@@ -1126,7 +1126,7 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
11261126
/// later on down the road...
11271127
fn check_sane_privacy(&self, item: &ast::Item) {
11281128
let tcx = self.tcx;
1129-
let check_inherited = |sp: Span, vis: ast::Visibility, note: &str| {
1129+
let check_inherited = |&: sp: Span, vis: ast::Visibility, note: &str| {
11301130
if vis != ast::Inherited {
11311131
tcx.sess.span_err(sp, "unnecessary visibility qualifier");
11321132
if note.len() > 0 {
@@ -1206,7 +1206,7 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
12061206
tcx.sess.span_err(sp, "visibility has no effect inside functions");
12071207
}
12081208
}
1209-
let check_struct = |def: &ast::StructDef| {
1209+
let check_struct = |&: def: &ast::StructDef| {
12101210
for f in def.fields.iter() {
12111211
match f.node.kind {
12121212
ast::NamedField(_, p) => check_inherited(tcx, f.span, p),

src/librustc/middle/region.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ fn resolve_expr(visitor: &mut RegionResolutionVisitor, expr: &ast::Expr) {
488488

489489
{
490490
let region_maps = &mut visitor.region_maps;
491-
let terminating = |id| {
491+
let terminating = |&: id| {
492492
let scope = CodeExtent::from_node_id(id);
493493
region_maps.mark_as_terminating_scope(scope)
494494
};

0 commit comments

Comments
 (0)