Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unbox more closures in the libraries #20363

Merged
merged 23 commits into from
Jan 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ea94a90
unicode: unbox closures used in function arguments
Dec 30, 2014
a17c2b6
collections: fix fallout
Dec 30, 2014
371f04d
std: unbox closures used in function arguments
Dec 30, 2014
70ce68e
syntax: unbox closures used in function arguments
Dec 30, 2014
5de9f47
rustc: unbox closures used in function arguments
Dec 31, 2014
24b4922
rustc_trans: unbox closures used in function arguments
Dec 31, 2014
bcc2120
rustc_borrowck: unbox closures used in function arguments
Dec 31, 2014
ddb4e43
core: unbox closures used in let bindings
Dec 31, 2014
16a4ba8
getopts: unbox closures used in let bindings
Dec 31, 2014
06408b4
rustc: unbox closures used in let bindings
Dec 31, 2014
a6f3053
rustc_back: unbox closures used in let bindings
Dec 31, 2014
28ea99e
rustc_borrowck: unbox closures used in let bindings
Dec 31, 2014
a49cdb8
rustc_driver: unbox closures used in let bindings
Dec 31, 2014
1e4bbef
rustc_resolve: unbox closures used in let bindings
Dec 31, 2014
e47035b
rustc_trans: unbox closures used in let bindings
Dec 31, 2014
e9ddd82
rustc_typeck: unbox closures used in let bindings
Dec 31, 2014
fb14dad
rustdoc: unbox closures used in let bindings
Dec 31, 2014
12dd778
std: unbox closures used in let bindings
Dec 31, 2014
ab402c0
syntax: unbox closures used in let bindings
Dec 31, 2014
63af3e6
time: unbox closures used in let bindings
Dec 31, 2014
1d21dad
rustc: replace `GetCrateDataCb` alias with an unboxed closure
Dec 31, 2014
c8cf3a3
rustc: replace `pick` alias with an unboxed closure
Dec 31, 2014
10bbf69
rustc_trans: replace `EnterPatterns` alias with an unboxed closure
Dec 31, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libcollections/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl<'a> Iterator<char> for Decompositions<'a> {
let buffer = &mut self.buffer;
let sorted = &mut self.sorted;
{
let callback = |d| {
let callback = |&mut: d| {
let class =
unicode::char::canonical_combining_class(d);
if class == 0 && !*sorted {
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/fmt/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,10 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
// cut off the one extra digit, and depending on its value
// round the remaining ones.
if limit_digits && dig == digit_count {
let ascii2value = |chr: u8| {
let ascii2value = |&: chr: u8| {
(chr as char).to_digit(radix).unwrap()
};
let value2ascii = |val: uint| {
let value2ascii = |&: val: uint| {
char::from_digit(val, radix).unwrap() as u8
};

Expand Down
2 changes: 1 addition & 1 deletion src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ impl<'a> Formatter<'a> {
}

// Writes the sign if it exists, and then the prefix if it was requested
let write_prefix = |f: &mut Formatter| {
let write_prefix = |&: f: &mut Formatter| {
for c in sign.into_iter() {
let mut b = [0, ..4];
let n = c.encode_utf8(&mut b).unwrap_or(0);
Expand Down
2 changes: 1 addition & 1 deletion src/libgetopts/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ fn each_split_within<F>(ss: &str, lim: uint, mut it: F) -> bool where
lim = fake_i;
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ fn extract_crate_info(e: &Env, i: &ast::ViewItem) -> Option<CrateInfo> {
}

pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
let err = |s: &str| {
let err = |&: s: &str| {
match (sp, sess) {
(_, None) => panic!("{}", s),
(Some(sp), Some(sess)) => sess.span_err(sp, s),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/metadata/csearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn each_child_of_item<F>(cstore: &cstore::CStore,
F: FnMut(decoder::DefLike, ast::Name, ast::Visibility),
{
let crate_data = cstore.get_crate_data(def_id.krate);
let get_crate_data: decoder::GetCrateDataCb = |cnum| {
let get_crate_data = |&mut: cnum| {
cstore.get_crate_data(cnum)
};
decoder::each_child_of_item(cstore.intr.clone(),
Expand All @@ -79,7 +79,7 @@ pub fn each_top_level_item_of_crate<F>(cstore: &cstore::CStore,
F: FnMut(decoder::DefLike, ast::Name, ast::Visibility),
{
let crate_data = cstore.get_crate_data(cnum);
let get_crate_data: decoder::GetCrateDataCb = |cnum| {
let get_crate_data = |&mut: cnum| {
cstore.get_crate_data(cnum)
};
decoder::each_top_level_item_of_crate(cstore.intr.clone(),
Expand Down
33 changes: 17 additions & 16 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,14 +487,13 @@ pub fn each_lang_item<F>(cdata: Cmd, mut f: F) -> bool where
})
}

pub type GetCrateDataCb<'a> = |ast::CrateNum|: 'a -> Rc<crate_metadata>;

fn each_child_of_item_or_crate<F>(intr: Rc<IdentInterner>,
cdata: Cmd,
item_doc: rbml::Doc,
get_crate_data: GetCrateDataCb,
mut callback: F) where
fn each_child_of_item_or_crate<F, G>(intr: Rc<IdentInterner>,
cdata: Cmd,
item_doc: rbml::Doc,
mut get_crate_data: G,
mut callback: F) where
F: FnMut(DefLike, ast::Name, ast::Visibility),
G: FnMut(ast::CrateNum) -> Rc<crate_metadata>,
{
// Iterate over all children.
let _ = reader::tagged_docs(item_doc, tag_mod_child, |child_info_doc| {
Expand Down Expand Up @@ -608,12 +607,13 @@ fn each_child_of_item_or_crate<F>(intr: Rc<IdentInterner>,
}

/// Iterates over each child of the given item.
pub fn each_child_of_item<F>(intr: Rc<IdentInterner>,
cdata: Cmd,
id: ast::NodeId,
get_crate_data: GetCrateDataCb,
callback: F) where
pub fn each_child_of_item<F, G>(intr: Rc<IdentInterner>,
cdata: Cmd,
id: ast::NodeId,
get_crate_data: G,
callback: F) where
F: FnMut(DefLike, ast::Name, ast::Visibility),
G: FnMut(ast::CrateNum) -> Rc<crate_metadata>,
{
// Find the item.
let root_doc = rbml::Doc::new(cdata.data());
Expand All @@ -631,11 +631,12 @@ pub fn each_child_of_item<F>(intr: Rc<IdentInterner>,
}

/// Iterates over all the top-level crate items.
pub fn each_top_level_item_of_crate<F>(intr: Rc<IdentInterner>,
cdata: Cmd,
get_crate_data: GetCrateDataCb,
callback: F) where
pub fn each_top_level_item_of_crate<F, G>(intr: Rc<IdentInterner>,
cdata: Cmd,
get_crate_data: G,
callback: F) where
F: FnMut(DefLike, ast::Name, ast::Visibility),
G: FnMut(ast::CrateNum) -> Rc<crate_metadata>,
{
let root_doc = rbml::Doc::new(cdata.data());
let misc_info_doc = reader::get_doc(root_doc, tag_misc_info);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_parent_sort(rbml_w, 't');

let trait_item = &ms[i];
let encode_trait_item = |rbml_w: &mut Encoder| {
let encode_trait_item = |&: rbml_w: &mut Encoder| {
// If this is a static method, we've already
// encoded this.
if is_nonstatic_method {
Expand Down
6 changes: 1 addition & 5 deletions src/librustc/metadata/filesearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ pub enum FileMatch {
// FIXME (#2658): I'm not happy how this module turned out. Should
// probably just be folded into cstore.

/// Functions with type `pick` take a parent directory as well as
/// a file found in that directory.
pub type pick<'a> = |path: &Path|: 'a -> FileMatch;

pub struct FileSearch<'a> {
pub sysroot: &'a Path,
pub search_paths: &'a SearchPaths,
Expand Down Expand Up @@ -95,7 +91,7 @@ impl<'a> FileSearch<'a> {
make_target_lib_path(self.sysroot, self.triple)
}

pub fn search(&self, pick: pick) {
pub fn search<F>(&self, mut pick: F) where F: FnMut(&Path) -> FileMatch {
self.for_each_lib_search_path(|lib_search_path| {
debug!("searching {}", lib_search_path.display());
match fs::readdir(lib_search_path) {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/check_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &ast::Expr) -> bool {
ast::ExprBlock(ref block) => {
// Check all statements in the block
for stmt in block.stmts.iter() {
let block_span_err = |span|
let block_span_err = |&: span|
span_err!(v.tcx.sess, span, E0016,
"blocks in constants are limited to items and \
tail expressions");
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
})
}

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

// x @ Foo(..) is legal, but x @ Foo(y) isn't.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/infer/region_inference/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl<'a, 'tcx> ConstraintGraph<'a, 'tcx> {
let mut i = 0;
let mut node_ids = FnvHashMap::new();
{
let add_node = |node| {
let mut add_node = |&mut : node| {
if let Vacant(e) = node_ids.entry(node) {
e.set(i);
i += 1;
Expand Down
38 changes: 20 additions & 18 deletions src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1122,11 +1122,15 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
})
}

// FIXME(#19596) unbox `op`
pub fn cat_pattern(&self,
cmt: cmt<'tcx>,
pat: &ast::Pat,
op: |&MemCategorizationContext<'t, TYPER>, cmt<'tcx>, &ast::Pat|)
pub fn cat_pattern<F>(&self, cmt: cmt<'tcx>, pat: &ast::Pat, mut op: F) where
F: FnMut(&MemCategorizationContext<'t, TYPER>, cmt<'tcx>, &ast::Pat),
{
self.cat_pattern_(cmt, pat, &mut op)
}

// FIXME(#19596) This is a workaround, but there should be a better way to do this
fn cat_pattern_<F>(&self, cmt: cmt<'tcx>, pat: &ast::Pat, op: &mut F) where
F: FnMut(&MemCategorizationContext<'t, TYPER>, cmt<'tcx>, &ast::Pat),
{
// Here, `cmt` is the categorization for the value being
// matched and pat is the pattern it is being matched against.
Expand Down Expand Up @@ -1177,7 +1181,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
pat.id, pprust::pat_to_string(pat),
cmt.repr(self.tcx()));

op(self, cmt.clone(), pat);
(*op)(self, cmt.clone(), pat);

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

self.cat_pattern(subcmt, &**subpat, |x,y,z| op(x,y,z));
self.cat_pattern_(subcmt, &**subpat, op);
}
}
Some(&def::DefStruct(..)) => {
Expand All @@ -1224,13 +1228,12 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
self.cat_imm_interior(
pat, cmt.clone(), subpat_ty,
InteriorField(PositionalField(i)));
self.cat_pattern(cmt_field, &**subpat,
|x,y,z| op(x,y,z));
self.cat_pattern_(cmt_field, &**subpat, op);
}
}
Some(&def::DefConst(..)) => {
for subpat in subpats.iter() {
self.cat_pattern(cmt.clone(), &**subpat, |x,y,z| op(x,y,z));
self.cat_pattern_(cmt.clone(), &**subpat, op);
}
}
_ => {
Expand All @@ -1242,7 +1245,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
}

ast::PatIdent(_, _, Some(ref subpat)) => {
self.cat_pattern(cmt, &**subpat, op);
self.cat_pattern_(cmt, &**subpat, op);
}

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

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

ast::PatBox(ref subpat) | ast::PatRegion(ref subpat) => {
// @p1, ~p1, ref p1
let subcmt = self.cat_deref(pat, cmt, 0, false);
self.cat_pattern(subcmt, &**subpat, op);
self.cat_pattern_(subcmt, &**subpat, op);
}

ast::PatVec(ref before, ref slice, ref after) => {
let elt_cmt = self.cat_index(pat, self.deref_vec(pat, cmt));
for before_pat in before.iter() {
self.cat_pattern(elt_cmt.clone(), &**before_pat,
|x,y,z| op(x,y,z));
self.cat_pattern_(elt_cmt.clone(), &**before_pat, op);
}
for slice_pat in slice.iter() {
let slice_ty = self.pat_ty(&**slice_pat);
let slice_cmt = self.cat_rvalue_node(pat.id(), pat.span(), slice_ty);
self.cat_pattern(slice_cmt, &**slice_pat, |x,y,z| op(x,y,z));
self.cat_pattern_(slice_cmt, &**slice_pat, op);
}
for after_pat in after.iter() {
self.cat_pattern(elt_cmt.clone(), &**after_pat, |x,y,z| op(x,y,z));
self.cat_pattern_(elt_cmt.clone(), &**after_pat, op);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/privacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
fn check_path(&mut self, span: Span, path_id: ast::NodeId, path: &ast::Path) {
debug!("privacy - path {}", self.nodestr(path_id));
let orig_def = self.tcx.def_map.borrow()[path_id].clone();
let ck = |tyname: &str| {
let ck = |&: tyname: &str| {
let ck_public = |def: ast::DefId| {
let name = token::get_ident(path.segments.last().unwrap().identifier);
let origdid = orig_def.def_id();
Expand Down Expand Up @@ -921,7 +921,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
}
}
ast::ExprPath(..) => {
let guard = |did: ast::DefId| {
let guard = |&: did: ast::DefId| {
let fields = ty::lookup_struct_fields(self.tcx, did);
let any_priv = fields.iter().any(|f| {
f.vis != ast::Public && (
Expand Down Expand Up @@ -1126,7 +1126,7 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
/// later on down the road...
fn check_sane_privacy(&self, item: &ast::Item) {
let tcx = self.tcx;
let check_inherited = |sp: Span, vis: ast::Visibility, note: &str| {
let check_inherited = |&: sp: Span, vis: ast::Visibility, note: &str| {
if vis != ast::Inherited {
tcx.sess.span_err(sp, "unnecessary visibility qualifier");
if note.len() > 0 {
Expand Down Expand Up @@ -1206,7 +1206,7 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
tcx.sess.span_err(sp, "visibility has no effect inside functions");
}
}
let check_struct = |def: &ast::StructDef| {
let check_struct = |&: def: &ast::StructDef| {
for f in def.fields.iter() {
match f.node.kind {
ast::NamedField(_, p) => check_inherited(tcx, f.span, p),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ fn resolve_expr(visitor: &mut RegionResolutionVisitor, expr: &ast::Expr) {

{
let region_maps = &mut visitor.region_maps;
let terminating = |id| {
let terminating = |&: id| {
let scope = CodeExtent::from_node_id(id);
region_maps.mark_as_terminating_scope(scope)
};
Expand Down
Loading