Skip to content

Commit 64dd7be

Browse files
committed
Merge remote-tracking branch 'origin/master' into rollup
Conflicts: src/liballoc/lib.rs src/libcore/ops.rs
2 parents 3a2530d + 3fbfad3 commit 64dd7be

30 files changed

+644
-480
lines changed

src/liballoc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
#![feature(box_syntax)]
7171
#![feature(optin_builtin_traits)]
7272
#![feature(int_uint)]
73+
#![feature(unboxed_closures)]
7374
#![feature(core)]
7475
#![feature(hash)]
7576
#![feature(libc)]

src/libcore/ops.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,7 @@ impl<'a, T: ?Sized> DerefMut for &'a mut T {
11341134
#[lang="fn"]
11351135
#[unstable(feature = "core",
11361136
reason = "uncertain about variadic generics, input versus associated types")]
1137+
#[rustc_paren_sugar]
11371138
pub trait Fn<Args> {
11381139
type Output;
11391140

@@ -1145,6 +1146,7 @@ pub trait Fn<Args> {
11451146
#[lang="fn_mut"]
11461147
#[unstable(feature = "core",
11471148
reason = "uncertain about variadic generics, input versus associated types")]
1149+
#[rustc_paren_sugar]
11481150
pub trait FnMut<Args> {
11491151
type Output;
11501152

@@ -1156,6 +1158,7 @@ pub trait FnMut<Args> {
11561158
#[lang="fn_once"]
11571159
#[unstable(feature = "core",
11581160
reason = "uncertain about variadic generics, input versus associated types")]
1161+
#[rustc_paren_sugar]
11591162
pub trait FnOnce<Args> {
11601163
type Output;
11611164

src/librustc/lint/builtin.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,7 @@ impl LintPass for UnusedAttributes {
670670
// FIXME: #19470 this shouldn't be needed forever
671671
"old_orphan_check",
672672
"old_impl_check",
673+
"rustc_paren_sugar", // FIXME: #18101 temporary unboxed closure hack
673674
];
674675

675676
static CRATE_ATTRS: &'static [&'static str] = &[

src/librustc/metadata/common.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ pub enum astencode_tag { // Reserves 0x40 -- 0x5f
140140
tag_table_moves_map = 0x52,
141141
tag_table_capture_map = 0x53,
142142
tag_table_closures = 0x54,
143-
tag_table_upvar_borrow_map = 0x55,
143+
tag_table_upvar_capture_map = 0x55,
144144
tag_table_capture_modes = 0x56,
145145
tag_table_object_cast_map = 0x57,
146146
}
@@ -265,3 +265,5 @@ pub const tag_polarity: uint = 0xb4;
265265
pub const tag_macro_defs: uint = 0xb5;
266266
pub const tag_macro_def: uint = 0xb6;
267267
pub const tag_macro_def_body: uint = 0xb7;
268+
269+
pub const tag_paren_sugar: uint = 0xb8;

src/librustc/metadata/decoder.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,11 @@ fn parse_unsafety(item_doc: rbml::Doc) -> ast::Unsafety {
371371
}
372372
}
373373

374+
fn parse_paren_sugar(item_doc: rbml::Doc) -> bool {
375+
let paren_sugar_doc = reader::get_doc(item_doc, tag_paren_sugar);
376+
reader::doc_as_u8(paren_sugar_doc) != 0
377+
}
378+
374379
fn parse_polarity(item_doc: rbml::Doc) -> ast::ImplPolarity {
375380
let polarity_doc = reader::get_doc(item_doc, tag_polarity);
376381
if reader::doc_as_u8(polarity_doc) != 0 {
@@ -400,8 +405,10 @@ pub fn get_trait_def<'tcx>(cdata: Cmd,
400405
let bounds = trait_def_bounds(item_doc, tcx, cdata);
401406
let unsafety = parse_unsafety(item_doc);
402407
let associated_type_names = parse_associated_type_names(item_doc);
408+
let paren_sugar = parse_paren_sugar(item_doc);
403409

404410
ty::TraitDef {
411+
paren_sugar: paren_sugar,
405412
unsafety: unsafety,
406413
generics: generics,
407414
bounds: bounds,

src/librustc/metadata/encoder.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
13171317
encode_item_variances(rbml_w, ecx, item.id);
13181318
let trait_def = ty::lookup_trait_def(tcx, def_id);
13191319
encode_unsafety(rbml_w, trait_def.unsafety);
1320+
encode_paren_sugar(rbml_w, trait_def.paren_sugar);
13201321
encode_associated_type_names(rbml_w, trait_def.associated_type_names.as_slice());
13211322
encode_generics(rbml_w, ecx, &trait_def.generics, tag_item_generics);
13221323
encode_trait_ref(rbml_w, ecx, &*trait_def.trait_ref, tag_item_trait_ref);
@@ -1697,6 +1698,11 @@ fn encode_unsafety(rbml_w: &mut Encoder, unsafety: ast::Unsafety) {
16971698
rbml_w.wr_tagged_u8(tag_unsafety, byte);
16981699
}
16991700

1701+
fn encode_paren_sugar(rbml_w: &mut Encoder, paren_sugar: bool) {
1702+
let byte: u8 = if paren_sugar {1} else {0};
1703+
rbml_w.wr_tagged_u8(tag_paren_sugar, byte);
1704+
}
1705+
17001706
fn encode_associated_type_names(rbml_w: &mut Encoder, names: &[ast::Name]) {
17011707
rbml_w.start_tag(tag_associated_type_names);
17021708
for &name in names.iter() {

src/librustc/middle/astencode.rs

Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -518,10 +518,6 @@ fn encode_freevar_entry(rbml_w: &mut Encoder, fv: &ty::Freevar) {
518518
(*fv).encode(rbml_w).unwrap();
519519
}
520520

521-
fn encode_capture_mode(rbml_w: &mut Encoder, cm: ast::CaptureClause) {
522-
cm.encode(rbml_w).unwrap();
523-
}
524-
525521
trait rbml_decoder_helper {
526522
fn read_freevar_entry(&mut self, dcx: &DecodeContext)
527523
-> ty::Freevar;
@@ -559,6 +555,15 @@ impl tr for ty::UpvarBorrow {
559555
}
560556
}
561557

558+
impl tr for ty::UpvarCapture {
559+
fn tr(&self, dcx: &DecodeContext) -> ty::UpvarCapture {
560+
match *self {
561+
ty::UpvarCapture::ByValue => ty::UpvarCapture::ByValue,
562+
ty::UpvarCapture::ByRef(ref data) => ty::UpvarCapture::ByRef(data.tr(dcx)),
563+
}
564+
}
565+
}
566+
562567
// ______________________________________________________________________
563568
// Encoding and decoding of MethodCallee
564569

@@ -1210,34 +1215,20 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
12101215
});
12111216

12121217
for freevar in fv.iter() {
1213-
match tcx.capture_mode(id) {
1214-
ast::CaptureByRef => {
1215-
rbml_w.tag(c::tag_table_upvar_borrow_map, |rbml_w| {
1216-
rbml_w.id(id);
1217-
rbml_w.tag(c::tag_table_val, |rbml_w| {
1218-
let var_id = freevar.def.def_id().node;
1219-
let upvar_id = ty::UpvarId {
1220-
var_id: var_id,
1221-
closure_expr_id: id
1222-
};
1223-
let upvar_borrow = tcx.upvar_borrow_map.borrow()[upvar_id].clone();
1224-
var_id.encode(rbml_w);
1225-
upvar_borrow.encode(rbml_w);
1226-
})
1227-
})
1228-
}
1229-
_ => {}
1230-
}
1231-
}
1232-
}
1233-
1234-
for &cm in tcx.capture_modes.borrow().get(&id).iter() {
1235-
rbml_w.tag(c::tag_table_capture_modes, |rbml_w| {
1236-
rbml_w.id(id);
1237-
rbml_w.tag(c::tag_table_val, |rbml_w| {
1238-
encode_capture_mode(rbml_w, *cm);
1218+
rbml_w.tag(c::tag_table_upvar_capture_map, |rbml_w| {
1219+
rbml_w.id(id);
1220+
rbml_w.tag(c::tag_table_val, |rbml_w| {
1221+
let var_id = freevar.def.def_id().node;
1222+
let upvar_id = ty::UpvarId {
1223+
var_id: var_id,
1224+
closure_expr_id: id
1225+
};
1226+
let upvar_capture = tcx.upvar_capture_map.borrow()[upvar_id].clone();
1227+
var_id.encode(rbml_w);
1228+
upvar_capture.encode(rbml_w);
1229+
})
12391230
})
1240-
})
1231+
}
12411232
}
12421233

12431234
let lid = ast::DefId { krate: ast::LOCAL_CRATE, node: id };
@@ -1911,21 +1902,14 @@ fn decode_side_tables(dcx: &DecodeContext,
19111902
}).unwrap().into_iter().collect();
19121903
dcx.tcx.freevars.borrow_mut().insert(id, fv_info);
19131904
}
1914-
c::tag_table_upvar_borrow_map => {
1905+
c::tag_table_upvar_capture_map => {
19151906
let var_id: ast::NodeId = Decodable::decode(val_dsr).unwrap();
19161907
let upvar_id = ty::UpvarId {
19171908
var_id: dcx.tr_id(var_id),
19181909
closure_expr_id: id
19191910
};
1920-
let ub: ty::UpvarBorrow = Decodable::decode(val_dsr).unwrap();
1921-
dcx.tcx.upvar_borrow_map.borrow_mut().insert(upvar_id, ub.tr(dcx));
1922-
}
1923-
c::tag_table_capture_modes => {
1924-
let capture_mode = val_dsr.read_capture_mode();
1925-
dcx.tcx
1926-
.capture_modes
1927-
.borrow_mut()
1928-
.insert(id, capture_mode);
1911+
let ub: ty::UpvarCapture = Decodable::decode(val_dsr).unwrap();
1912+
dcx.tcx.upvar_capture_map.borrow_mut().insert(upvar_id, ub.tr(dcx));
19291913
}
19301914
c::tag_table_tcache => {
19311915
let type_scheme = val_dsr.read_type_scheme(dcx);

src/librustc/middle/expr_use_visitor.rs

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
366366
consume_id: ast::NodeId,
367367
consume_span: Span,
368368
cmt: mc::cmt<'tcx>) {
369+
debug!("delegate_consume(consume_id={}, cmt={})",
370+
consume_id, cmt.repr(self.tcx()));
371+
369372
let mode = copy_or_move(self.typer, &cmt, DirectRefMove);
370373
self.delegate.consume(consume_id, consume_span, cmt, mode);
371374
}
@@ -1194,53 +1197,32 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
11941197
debug!("walk_captures({})", closure_expr.repr(self.tcx()));
11951198

11961199
ty::with_freevars(self.tcx(), closure_expr.id, |freevars| {
1197-
match self.tcx().capture_mode(closure_expr.id) {
1198-
ast::CaptureByRef => {
1199-
self.walk_by_ref_captures(closure_expr, freevars);
1200-
}
1201-
ast::CaptureByValue => {
1202-
self.walk_by_value_captures(closure_expr, freevars);
1200+
for freevar in freevars.iter() {
1201+
let id_var = freevar.def.def_id().node;
1202+
let upvar_id = ty::UpvarId { var_id: id_var,
1203+
closure_expr_id: closure_expr.id };
1204+
let upvar_capture = self.typer.upvar_capture(upvar_id).unwrap();
1205+
let cmt_var = return_if_err!(self.cat_captured_var(closure_expr.id,
1206+
closure_expr.span,
1207+
freevar.def));
1208+
match upvar_capture {
1209+
ty::UpvarCapture::ByValue => {
1210+
let mode = copy_or_move(self.typer, &cmt_var, CaptureMove);
1211+
self.delegate.consume(closure_expr.id, freevar.span, cmt_var, mode);
1212+
}
1213+
ty::UpvarCapture::ByRef(upvar_borrow) => {
1214+
self.delegate.borrow(closure_expr.id,
1215+
closure_expr.span,
1216+
cmt_var,
1217+
upvar_borrow.region,
1218+
upvar_borrow.kind,
1219+
ClosureCapture(freevar.span));
1220+
}
12031221
}
12041222
}
12051223
});
12061224
}
12071225

1208-
fn walk_by_ref_captures(&mut self,
1209-
closure_expr: &ast::Expr,
1210-
freevars: &[ty::Freevar]) {
1211-
for freevar in freevars.iter() {
1212-
let id_var = freevar.def.def_id().node;
1213-
let cmt_var = return_if_err!(self.cat_captured_var(closure_expr.id,
1214-
closure_expr.span,
1215-
freevar.def));
1216-
1217-
// Lookup the kind of borrow the callee requires, as
1218-
// inferred by regionbk
1219-
let upvar_id = ty::UpvarId { var_id: id_var,
1220-
closure_expr_id: closure_expr.id };
1221-
let upvar_borrow = self.typer.upvar_borrow(upvar_id).unwrap();
1222-
1223-
self.delegate.borrow(closure_expr.id,
1224-
closure_expr.span,
1225-
cmt_var,
1226-
upvar_borrow.region,
1227-
upvar_borrow.kind,
1228-
ClosureCapture(freevar.span));
1229-
}
1230-
}
1231-
1232-
fn walk_by_value_captures(&mut self,
1233-
closure_expr: &ast::Expr,
1234-
freevars: &[ty::Freevar]) {
1235-
for freevar in freevars.iter() {
1236-
let cmt_var = return_if_err!(self.cat_captured_var(closure_expr.id,
1237-
closure_expr.span,
1238-
freevar.def));
1239-
let mode = copy_or_move(self.typer, &cmt_var, CaptureMove);
1240-
self.delegate.consume(closure_expr.id, freevar.span, cmt_var, mode);
1241-
}
1242-
}
1243-
12441226
fn cat_captured_var(&mut self,
12451227
closure_id: ast::NodeId,
12461228
closure_span: Span,

0 commit comments

Comments
 (0)