1
Fork 0

librustc: Eliminate the ref syntax for unboxed closure capture clauses

in favor of `move`.

This breaks code that used `move` as an identifier, because it is now a
keyword. Change such identifiers to not use the keyword `move`.
Additionally, this breaks code that was counting on by-value or
by-reference capture semantics for unboxed closures (behind the feature
gate). Change `ref |:|` to `|:|` and `|:|` to `move |:|`.

Part of RFC #63; part of issue #12831.

[breaking-change]
This commit is contained in:
Patrick Walton 2014-09-24 10:58:53 -07:00
parent 5d653c17a6
commit 2257e231a7
14 changed files with 82 additions and 81 deletions

View file

@ -96,12 +96,6 @@ pub trait BoxAny {
/// `Err(Self)` if it isn't. /// `Err(Self)` if it isn't.
#[unstable = "naming conventions around accessing innards may change"] #[unstable = "naming conventions around accessing innards may change"]
fn downcast<T: 'static>(self) -> Result<Box<T>, Self>; fn downcast<T: 'static>(self) -> Result<Box<T>, Self>;
/// Deprecated; this method has been renamed to `downcast`.
#[deprecated = "use downcast instead"]
fn move<T: 'static>(self) -> Result<Box<T>, Self> {
self.downcast::<T>()
}
} }
#[stable] #[stable]

View file

@ -652,12 +652,12 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
debug!("check_if_path_is_moved(id={:?}, use_kind={:?}, lp={})", debug!("check_if_path_is_moved(id={:?}, use_kind={:?}, lp={})",
id, use_kind, lp.repr(self.bccx.tcx)); id, use_kind, lp.repr(self.bccx.tcx));
let base_lp = owned_ptr_base_path_rc(lp); let base_lp = owned_ptr_base_path_rc(lp);
self.move_data.each_move_of(id, &base_lp, |move, moved_lp| { self.move_data.each_move_of(id, &base_lp, |the_move, moved_lp| {
self.bccx.report_use_of_moved_value( self.bccx.report_use_of_moved_value(
span, span,
use_kind, use_kind,
&**lp, &**lp,
move, the_move,
moved_lp); moved_lp);
false false
}); });

View file

@ -108,8 +108,8 @@ impl<'a, 'tcx> DataflowLabeller<'a, 'tcx> {
let move_index_to_path = |move_index| { let move_index_to_path = |move_index| {
let move_data = &self.analysis_data.move_data.move_data; let move_data = &self.analysis_data.move_data.move_data;
let moves = move_data.moves.borrow(); let moves = move_data.moves.borrow();
let move = moves.get(move_index); let the_move = moves.get(move_index);
move_data.path_loan_path(move.path) move_data.path_loan_path(the_move.path)
}; };
self.build_set(e, cfgidx, dfcx, move_index_to_path) self.build_set(e, cfgidx, dfcx, move_index_to_path)
} }

View file

@ -409,14 +409,14 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
use_span: Span, use_span: Span,
use_kind: MovedValueUseKind, use_kind: MovedValueUseKind,
lp: &LoanPath, lp: &LoanPath,
move: &move_data::Move, the_move: &move_data::Move,
moved_lp: &LoanPath) { moved_lp: &LoanPath) {
let verb = match use_kind { let verb = match use_kind {
MovedInUse => "use", MovedInUse => "use",
MovedInCapture => "capture", MovedInCapture => "capture",
}; };
match move.kind { match the_move.kind {
move_data::Declared => { move_data::Declared => {
self.tcx.sess.span_err( self.tcx.sess.span_err(
use_span, use_span,
@ -435,18 +435,20 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
} }
} }
match move.kind { match the_move.kind {
move_data::Declared => {} move_data::Declared => {}
move_data::MoveExpr => { move_data::MoveExpr => {
let (expr_ty, expr_span) = match self.tcx.map.find(move.id) { let (expr_ty, expr_span) = match self.tcx
.map
.find(the_move.id) {
Some(ast_map::NodeExpr(expr)) => { Some(ast_map::NodeExpr(expr)) => {
(ty::expr_ty_adjusted(self.tcx, &*expr), expr.span) (ty::expr_ty_adjusted(self.tcx, &*expr), expr.span)
} }
r => { r => {
self.tcx.sess.bug(format!("MoveExpr({:?}) maps to \ self.tcx.sess.bug(format!("MoveExpr({:?}) maps to \
{:?}, not Expr", {:?}, not Expr",
move.id, the_move.id,
r).as_slice()) r).as_slice())
} }
}; };
@ -461,8 +463,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
} }
move_data::MovePat => { move_data::MovePat => {
let pat_ty = ty::node_id_to_type(self.tcx, move.id); let pat_ty = ty::node_id_to_type(self.tcx, the_move.id);
self.tcx.sess.span_note(self.tcx.map.span(move.id), self.tcx.sess.span_note(self.tcx.map.span(the_move.id),
format!("`{}` moved here because it has type `{}`, \ format!("`{}` moved here because it has type `{}`, \
which is moved by default (use `ref` to \ which is moved by default (use `ref` to \
override)", override)",
@ -471,14 +473,16 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
} }
move_data::Captured => { move_data::Captured => {
let (expr_ty, expr_span) = match self.tcx.map.find(move.id) { let (expr_ty, expr_span) = match self.tcx
.map
.find(the_move.id) {
Some(ast_map::NodeExpr(expr)) => { Some(ast_map::NodeExpr(expr)) => {
(ty::expr_ty_adjusted(self.tcx, &*expr), expr.span) (ty::expr_ty_adjusted(self.tcx, &*expr), expr.span)
} }
r => { r => {
self.tcx.sess.bug(format!("Captured({:?}) maps to \ self.tcx.sess.bug(format!("Captured({:?}) maps to \
{:?}, not Expr", {:?}, not Expr",
move.id, the_move.id,
r).as_slice()) r).as_slice())
} }
}; };

View file

@ -413,8 +413,8 @@ impl MoveData {
* killed by scoping. See `doc.rs` for more details. * killed by scoping. See `doc.rs` for more details.
*/ */
for (i, move) in self.moves.borrow().iter().enumerate() { for (i, the_move) in self.moves.borrow().iter().enumerate() {
dfcx_moves.add_gen(move.id, i); dfcx_moves.add_gen(the_move.id, i);
} }
for (i, assignment) in self.var_assignments.borrow().iter().enumerate() { for (i, assignment) in self.var_assignments.borrow().iter().enumerate() {
@ -577,10 +577,10 @@ impl<'a, 'tcx> FlowedMoveData<'a, 'tcx> {
let mut ret = None; let mut ret = None;
for loan_path_index in self.move_data.path_map.borrow().find(&*loan_path).iter() { for loan_path_index in self.move_data.path_map.borrow().find(&*loan_path).iter() {
self.dfcx_moves.each_gen_bit(id, |move_index| { self.dfcx_moves.each_gen_bit(id, |move_index| {
let move = self.move_data.moves.borrow(); let the_move = self.move_data.moves.borrow();
let move = move.get(move_index); let the_move = the_move.get(move_index);
if move.path == **loan_path_index { if the_move.path == **loan_path_index {
ret = Some(move.kind); ret = Some(the_move.kind);
false false
} else { } else {
true true
@ -622,13 +622,13 @@ impl<'a, 'tcx> FlowedMoveData<'a, 'tcx> {
let mut ret = true; let mut ret = true;
self.dfcx_moves.each_bit_on_entry(id, |index| { self.dfcx_moves.each_bit_on_entry(id, |index| {
let move = self.move_data.moves.borrow(); let the_move = self.move_data.moves.borrow();
let move = move.get(index); let the_move = the_move.get(index);
let moved_path = move.path; let moved_path = the_move.path;
if base_indices.iter().any(|x| x == &moved_path) { if base_indices.iter().any(|x| x == &moved_path) {
// Scenario 1 or 2: `loan_path` or some base path of // Scenario 1 or 2: `loan_path` or some base path of
// `loan_path` was moved. // `loan_path` was moved.
if !f(move, &*self.move_data.path_loan_path(moved_path)) { if !f(the_move, &*self.move_data.path_loan_path(moved_path)) {
ret = false; ret = false;
} }
} else { } else {
@ -637,7 +637,8 @@ impl<'a, 'tcx> FlowedMoveData<'a, 'tcx> {
if p == loan_path_index { if p == loan_path_index {
// Scenario 3: some extension of `loan_path` // Scenario 3: some extension of `loan_path`
// was moved // was moved
f(move, &*self.move_data.path_loan_path(moved_path)) f(the_move,
&*self.move_data.path_loan_path(moved_path))
} else { } else {
true true
} }

View file

@ -2084,7 +2084,7 @@ impl<'a> Parser<'a> {
ExprBlock(blk)); ExprBlock(blk));
}, },
token::BINOP(token::OR) | token::OROR => { token::BINOP(token::OR) | token::OROR => {
return self.parse_lambda_expr(CaptureByValue); return self.parse_lambda_expr(CaptureByRef);
}, },
// FIXME #13626: Should be able to stick in // FIXME #13626: Should be able to stick in
// token::SELF_KEYWORD_NAME // token::SELF_KEYWORD_NAME
@ -2135,8 +2135,8 @@ impl<'a> Parser<'a> {
hi = self.last_span.hi; hi = self.last_span.hi;
} }
_ => { _ => {
if self.eat_keyword(keywords::Ref) { if self.eat_keyword(keywords::Move) {
return self.parse_lambda_expr(CaptureByRef); return self.parse_lambda_expr(CaptureByValue);
} }
if self.eat_keyword(keywords::Proc) { if self.eat_keyword(keywords::Proc) {
let decl = self.parse_proc_decl(); let decl = self.parse_proc_decl();

View file

@ -482,40 +482,41 @@ declare_special_idents_and_keywords! {
(25, Loop, "loop"); (25, Loop, "loop");
(26, Match, "match"); (26, Match, "match");
(27, Mod, "mod"); (27, Mod, "mod");
(28, Mut, "mut"); (28, Move, "move");
(29, Once, "once"); (29, Mut, "mut");
(30, Pub, "pub"); (30, Once, "once");
(31, Ref, "ref"); (31, Pub, "pub");
(32, Return, "return"); (32, Ref, "ref");
(33, Return, "return");
// Static and Self are also special idents (prefill de-dupes) // Static and Self are also special idents (prefill de-dupes)
(super::STATIC_KEYWORD_NAME_NUM, Static, "static"); (super::STATIC_KEYWORD_NAME_NUM, Static, "static");
(super::SELF_KEYWORD_NAME_NUM, Self, "self"); (super::SELF_KEYWORD_NAME_NUM, Self, "self");
(33, Struct, "struct"); (34, Struct, "struct");
(super::SUPER_KEYWORD_NAME_NUM, Super, "super"); (super::SUPER_KEYWORD_NAME_NUM, Super, "super");
(34, True, "true"); (35, True, "true");
(35, Trait, "trait"); (36, Trait, "trait");
(36, Type, "type"); (37, Type, "type");
(37, Unsafe, "unsafe"); (38, Unsafe, "unsafe");
(38, Use, "use"); (39, Use, "use");
(39, Virtual, "virtual"); (40, Virtual, "virtual");
(40, While, "while"); (41, While, "while");
(41, Continue, "continue"); (42, Continue, "continue");
(42, Proc, "proc"); (43, Proc, "proc");
(43, Box, "box"); (44, Box, "box");
(44, Const, "const"); (45, Const, "const");
(45, Where, "where"); (46, Where, "where");
'reserved: 'reserved:
(46, Alignof, "alignof"); (47, Alignof, "alignof");
(47, Be, "be"); (48, Be, "be");
(48, Offsetof, "offsetof"); (49, Offsetof, "offsetof");
(49, Priv, "priv"); (50, Priv, "priv");
(50, Pure, "pure"); (51, Pure, "pure");
(51, Sizeof, "sizeof"); (52, Sizeof, "sizeof");
(52, Typeof, "typeof"); (53, Typeof, "typeof");
(53, Unsized, "unsized"); (54, Unsized, "unsized");
(54, Yield, "yield"); (55, Yield, "yield");
(55, Do, "do"); (56, Do, "do");
} }
} }

View file

@ -2176,8 +2176,8 @@ impl<'a> State<'a> {
pub fn print_capture_clause(&mut self, capture_clause: ast::CaptureClause) pub fn print_capture_clause(&mut self, capture_clause: ast::CaptureClause)
-> IoResult<()> { -> IoResult<()> {
match capture_clause { match capture_clause {
ast::CaptureByValue => Ok(()), ast::CaptureByValue => self.word_space("move"),
ast::CaptureByRef => self.word_space("ref"), ast::CaptureByRef => Ok(()),
} }
} }

View file

@ -17,7 +17,7 @@ fn main() {
{ {
let c = 1; let c = 1;
let c_ref = &c; //~ ERROR `c` does not live long enough let c_ref = &c; //~ ERROR `c` does not live long enough
f = |&mut: a: int, b: int| { a + b + *c_ref }; f = move |&mut: a: int, b: int| { a + b + *c_ref };
} }
} }

View file

@ -17,7 +17,7 @@ fn each<T>(x: &[T], f: |&T|) {
fn main() { fn main() {
let mut sum = 0u; let mut sum = 0u;
let elems = [ 1u, 2, 3, 4, 5 ]; let elems = [ 1u, 2, 3, 4, 5 ];
each(elems, ref |val| sum += *val); each(elems, |val| sum += *val);
assert_eq!(sum, 15); assert_eq!(sum, 15);
} }

View file

@ -24,8 +24,8 @@ fn c<F:FnOnce(int, int) -> int>(f: F) -> int {
fn main() { fn main() {
let z: int = 7; let z: int = 7;
assert_eq!(a(|&: x: int, y| x + y + z), 10); assert_eq!(a(move |&: x: int, y| x + y + z), 10);
assert_eq!(b(|&mut: x: int, y| x + y + z), 14); assert_eq!(b(move |&mut: x: int, y| x + y + z), 14);
assert_eq!(c(|: x: int, y| x + y + z), 18); assert_eq!(c(move |: x: int, y| x + y + z), 18);
} }

View file

@ -13,7 +13,8 @@
use std::ops::FnMut; use std::ops::FnMut;
fn make_adder(x: int) -> Box<FnMut<(int,),int>+'static> { fn make_adder(x: int) -> Box<FnMut<(int,),int>+'static> {
(box |&mut: y: int| -> int { x + y }) as Box<FnMut<(int,),int>+'static> (box move |&mut: y: int| -> int { x + y }) as
Box<FnMut<(int,),int>+'static>
} }
pub fn main() { pub fn main() {

View file

@ -55,13 +55,13 @@ fn c<F:FnOnce(int, int) -> int>(f: F) -> int {
fn test_fn() { fn test_fn() {
{ {
a(|&: a: int, b| { a + b }); a(move |&: a: int, b| { a + b });
} }
assert_eq!(drop_count(), 0); assert_eq!(drop_count(), 0);
{ {
let z = &Droppable::new(); let z = &Droppable::new();
a(|&: a: int, b| { z; a + b }); a(move |&: a: int, b| { z; a + b });
assert_eq!(drop_count(), 0); assert_eq!(drop_count(), 0);
} }
assert_eq!(drop_count(), 1); assert_eq!(drop_count(), 1);
@ -69,7 +69,7 @@ fn test_fn() {
{ {
let z = &Droppable::new(); let z = &Droppable::new();
let zz = &Droppable::new(); let zz = &Droppable::new();
a(|&: a: int, b| { z; zz; a + b }); a(move |&: a: int, b| { z; zz; a + b });
assert_eq!(drop_count(), 1); assert_eq!(drop_count(), 1);
} }
assert_eq!(drop_count(), 3); assert_eq!(drop_count(), 3);
@ -77,13 +77,13 @@ fn test_fn() {
fn test_fn_mut() { fn test_fn_mut() {
{ {
b(|&mut: a: int, b| { a + b }); b(move |&mut: a: int, b| { a + b });
} }
assert_eq!(drop_count(), 3); assert_eq!(drop_count(), 3);
{ {
let z = &Droppable::new(); let z = &Droppable::new();
b(|&mut: a: int, b| { z; a + b }); b(move |&mut: a: int, b| { z; a + b });
assert_eq!(drop_count(), 3); assert_eq!(drop_count(), 3);
} }
assert_eq!(drop_count(), 4); assert_eq!(drop_count(), 4);
@ -91,7 +91,7 @@ fn test_fn_mut() {
{ {
let z = &Droppable::new(); let z = &Droppable::new();
let zz = &Droppable::new(); let zz = &Droppable::new();
b(|&mut: a: int, b| { z; zz; a + b }); b(move |&mut: a: int, b| { z; zz; a + b });
assert_eq!(drop_count(), 4); assert_eq!(drop_count(), 4);
} }
assert_eq!(drop_count(), 6); assert_eq!(drop_count(), 6);
@ -99,13 +99,13 @@ fn test_fn_mut() {
fn test_fn_once() { fn test_fn_once() {
{ {
c(|: a: int, b| { a + b }); c(move |: a: int, b| { a + b });
} }
assert_eq!(drop_count(), 6); assert_eq!(drop_count(), 6);
{ {
let z = Droppable::new(); let z = Droppable::new();
c(|: a: int, b| { z; a + b }); c(move |: a: int, b| { z; a + b });
assert_eq!(drop_count(), 7); assert_eq!(drop_count(), 7);
} }
assert_eq!(drop_count(), 7); assert_eq!(drop_count(), 7);
@ -113,7 +113,7 @@ fn test_fn_once() {
{ {
let z = Droppable::new(); let z = Droppable::new();
let zz = Droppable::new(); let zz = Droppable::new();
c(|: a: int, b| { z; zz; a + b }); c(move |: a: int, b| { z; zz; a + b });
assert_eq!(drop_count(), 9); assert_eq!(drop_count(), 9);
} }
assert_eq!(drop_count(), 9); assert_eq!(drop_count(), 9);

View file

@ -27,8 +27,8 @@ fn c<F:FnOnce(int, int) -> int>(f: F) -> int {
fn main() { fn main() {
let z = 10; let z = 10;
assert_eq!(a(|&: x: int, y| x + y + z), 13); assert_eq!(a(move |&: x: int, y| x + y + z), 13);
assert_eq!(b(|&mut: x: int, y| x + y + z), 17); assert_eq!(b(move |&mut: x: int, y| x + y + z), 17);
assert_eq!(c(|: x: int, y| x + y + z), 21); assert_eq!(c(move |: x: int, y| x + y + z), 21);
} }