Skip to content

Commit c225ddf

Browse files
committed
---
yaml --- r: 39359 b: refs/heads/incoming c: cd12073 h: refs/heads/master i: 39357: b11a4c2 39355: 3f0452a 39351: 4274072 39343: 204b3a9 39327: 73f566c 39295: 4ae659f v: v3
1 parent 3c2ab45 commit c225ddf

File tree

17 files changed

+156
-54
lines changed

17 files changed

+156
-54
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 3d5418789064fdb463e872a4e651af1c628a3650
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278
9-
refs/heads/incoming: 45848b20402cb3ad07dd0b0442155ca9c6b14f01
9+
refs/heads/incoming: cd120736cbe9a8157a8d0e3fb66f48a32545ef68
1010
refs/heads/dist-snap: 22efa39382d41b084fde1719df7ae8ce5697d8c9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/librustc/middle/astencode.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ impl ast::def: tr {
346346
did2_opt.map(|did2| did2.tr(xcx)),
347347
p)
348348
}
349-
ast::def_self(nid) => { ast::def_self(xcx.tr_id(nid)) }
349+
ast::def_self_ty(nid) => { ast::def_self_ty(xcx.tr_id(nid)) }
350+
ast::def_self(nid, i) => { ast::def_self(xcx.tr_id(nid), i) }
350351
ast::def_mod(did) => { ast::def_mod(did.tr(xcx)) }
351352
ast::def_foreign_mod(did) => { ast::def_foreign_mod(did.tr(xcx)) }
352353
ast::def_const(did) => { ast::def_const(did.tr(xcx)) }

branches/incoming/src/librustc/middle/borrowck/check_loans.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,9 @@ impl check_loan_ctxt {
471471
// rvalues, I guess.
472472
cat_special(sk_static_item) => {}
473473

474+
// We allow moving out of explicit self only.
475+
cat_special(sk_self) => {}
476+
474477
cat_deref(_, _, unsafe_ptr) => {}
475478

476479
// Nothing else.

branches/incoming/src/librustc/middle/borrowck/preserve.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ priv impl &preserve_ctxt {
7474
let _i = indenter();
7575

7676
match cmt.cat {
77-
cat_special(sk_self) | cat_special(sk_heap_upvar) => {
77+
cat_special(sk_self) |
78+
cat_special(sk_implicit_self) |
79+
cat_special(sk_heap_upvar) => {
7880
self.compare_scope(cmt, ty::re_scope(self.item_ub))
7981
}
8082
cat_special(sk_static_item) | cat_special(sk_method) => {

branches/incoming/src/librustc/middle/liveness.rs

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,10 @@ use core::io::WriterUtil;
110110
use std::map::HashMap;
111111
use syntax::ast::*;
112112
use syntax::codemap::span;
113+
use syntax::parse::token::special_idents;
113114
use syntax::print::pprust::{expr_to_str, block_to_str};
114-
use syntax::visit::vt;
115+
use syntax::visit::{fk_anon, fk_dtor, fk_fn_block, fk_item_fn, fk_method};
116+
use syntax::visit::{vt};
115117
use syntax::{visit, ast_util};
116118

117119
export check_crate;
@@ -265,15 +267,15 @@ struct LocalInfo {
265267
enum VarKind {
266268
Arg(node_id, ident, rmode),
267269
Local(LocalInfo),
268-
Self,
269270
ImplicitRet
270271
}
271272

272273
fn relevant_def(def: def) -> Option<node_id> {
273274
match def {
274275
def_binding(nid, _) |
275276
def_arg(nid, _) |
276-
def_local(nid, _) => Some(nid),
277+
def_local(nid, _) |
278+
def_self(nid, _) => Some(nid),
277279

278280
_ => None
279281
}
@@ -338,8 +340,7 @@ impl IrMaps {
338340
Arg(node_id, _, _) => {
339341
self.variable_map.insert(node_id, v);
340342
}
341-
Self | ImplicitRet => {
342-
}
343+
ImplicitRet => {}
343344
}
344345

345346
debug!("%s is %?", v.to_str(), vk);
@@ -361,7 +362,6 @@ impl IrMaps {
361362
match copy self.var_kinds[*var] {
362363
Local(LocalInfo {ident: nm, _}) |
363364
Arg(_, nm, _) => self.tcx.sess.str_of(nm),
364-
Self => ~"self",
365365
ImplicitRet => ~"<implicit-ret>"
366366
}
367367
}
@@ -404,7 +404,7 @@ impl IrMaps {
404404
(*v).push(id);
405405
}
406406
Arg(_, _, by_ref) |
407-
Arg(_, _, by_val) | Self | ImplicitRet => {
407+
Arg(_, _, by_val) | ImplicitRet => {
408408
debug!("--but it is not owned");
409409
}
410410
}
@@ -432,6 +432,31 @@ fn visit_fn(fk: visit::fn_kind, decl: fn_decl, body: blk,
432432
}
433433
};
434434

435+
// Add `self`, whether explicit or implicit.
436+
match fk {
437+
fk_method(_, _, method) => {
438+
match method.self_ty.node {
439+
sty_by_ref => {
440+
fn_maps.add_variable(Arg(method.self_id,
441+
special_idents::self_,
442+
by_ref));
443+
}
444+
sty_value | sty_region(_) | sty_box(_) | sty_uniq(_) => {
445+
fn_maps.add_variable(Arg(method.self_id,
446+
special_idents::self_,
447+
by_copy));
448+
}
449+
sty_static => {}
450+
}
451+
}
452+
fk_dtor(_, _, self_id, _) => {
453+
fn_maps.add_variable(Arg(self_id,
454+
special_idents::self_,
455+
by_copy));
456+
}
457+
fk_item_fn(*) | fk_anon(*) | fk_fn_block(*) => {}
458+
}
459+
435460
// gather up the various local variables, significant expressions,
436461
// and so forth:
437462
visit::visit_fn(fk, decl, body, sp, id, fn_maps, v);
@@ -1790,13 +1815,6 @@ impl @Liveness {
17901815
copy or move mode", self.tcx.sess.str_of(name)));
17911816
return;
17921817
}
1793-
Self => {
1794-
self.tcx.sess.span_err(
1795-
move_span,
1796-
~"illegal move from self (cannot move out of a field of \
1797-
self)");
1798-
return;
1799-
}
18001818
Local(*) | ImplicitRet => {
18011819
self.tcx.sess.span_bug(
18021820
move_span,

branches/incoming/src/librustc/middle/mem_categorization.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ enum special_kind {
224224
sk_method,
225225
sk_static_item,
226226
sk_self,
227+
sk_implicit_self, // old by-reference `self`
227228
sk_heap_upvar
228229
}
229230

@@ -566,7 +567,7 @@ impl &mem_categorization_ctxt {
566567
ast::def_ty(_) | ast::def_prim_ty(_) |
567568
ast::def_ty_param(*) | ast::def_struct(*) |
568569
ast::def_typaram_binder(*) | ast::def_region(_) |
569-
ast::def_label(_) => {
570+
ast::def_label(_) | ast::def_self_ty(*) => {
570571
@{id:id, span:span,
571572
cat:cat_special(sk_static_item), lp:None,
572573
mutbl:m_imm, ty:expr_ty}
@@ -599,9 +600,15 @@ impl &mem_categorization_ctxt {
599600
mutbl:m, ty:expr_ty}
600601
}
601602

602-
ast::def_self(_) => {
603+
ast::def_self(_, is_implicit) => {
604+
let special_kind = if is_implicit {
605+
sk_implicit_self
606+
} else {
607+
sk_self
608+
};
609+
603610
@{id:id, span:span,
604-
cat:cat_special(sk_self), lp:None,
611+
cat:cat_special(special_kind), lp:None,
605612
mutbl:m_imm, ty:expr_ty}
606613
}
607614

@@ -975,6 +982,7 @@ impl &mem_categorization_ctxt {
975982
match cat {
976983
cat_special(sk_method) => ~"method",
977984
cat_special(sk_static_item) => ~"static_item",
985+
cat_special(sk_implicit_self) => ~"implicit-self",
978986
cat_special(sk_self) => ~"self",
979987
cat_special(sk_heap_upvar) => ~"heap-upvar",
980988
cat_stack_upvar(_) => ~"stack-upvar",
@@ -1053,7 +1061,8 @@ impl &mem_categorization_ctxt {
10531061
match cmt.cat {
10541062
cat_special(sk_method) => ~"method",
10551063
cat_special(sk_static_item) => ~"static item",
1056-
cat_special(sk_self) => ~"self reference",
1064+
cat_special(sk_implicit_self) => ~"self reference",
1065+
cat_special(sk_self) => ~"self value",
10571066
cat_special(sk_heap_upvar) => {
10581067
~"captured outer variable in a heap closure"
10591068
}

branches/incoming/src/librustc/middle/resolve.rs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@ use metadata::decoder::{def_like, dl_def, dl_field, dl_impl};
1616
use middle::lang_items::LanguageItems;
1717
use middle::lint::{deny, allow, forbid, level, unused_imports, warn};
1818
use middle::pat_util::{pat_bindings};
19-
use syntax::ast::{_mod, add, arm};
20-
use syntax::ast::{bitand, bitor, bitxor};
21-
use syntax::ast::{binding_mode, blk, capture_clause, struct_dtor};
22-
use syntax::ast::{crate, crate_num, decl_item};
23-
use syntax::ast::{def, def_arg, def_binding, def_struct, def_const, def_fn};
24-
use syntax::ast::{def_foreign_mod, def_id, def_label, def_local, def_mod};
25-
use syntax::ast::{def_prim_ty, def_region, def_self, def_ty, def_ty_param};
26-
use syntax::ast::{def_typaram_binder, def_static_method};
19+
use syntax::ast::{_mod, add, arm, binding_mode, bitand, bitor, bitxor, blk};
20+
use syntax::ast::{capture_clause};
21+
use syntax::ast::{crate, crate_num, decl_item, def, def_arg, def_binding};
22+
use syntax::ast::{def_const, def_foreign_mod, def_fn, def_id, def_label};
23+
use syntax::ast::{def_local, def_mod, def_prim_ty, def_region, def_self};
24+
use syntax::ast::{def_self_ty, def_static_method, def_struct, def_ty};
25+
use syntax::ast::{def_ty_param, def_typaram_binder};
2726
use syntax::ast::{def_upvar, def_use, def_variant, expr, expr_assign_op};
2827
use syntax::ast::{expr_binary, expr_break, expr_cast, expr_field, expr_fn};
2928
use syntax::ast::{expr_fn_block, expr_index, expr_method_call, expr_path};
@@ -40,13 +39,13 @@ use syntax::ast::{local, local_crate, lt, method, mode, module_ns, mul, ne};
4039
use syntax::ast::{neg, node_id, pat, pat_enum, pat_ident, path, prim_ty};
4140
use syntax::ast::{pat_box, pat_lit, pat_range, pat_rec, pat_struct};
4241
use syntax::ast::{pat_tup, pat_uniq, pat_wild, private, provided, public};
43-
use syntax::ast::{required, rem, self_ty_, shl, shr, stmt_decl};
44-
use syntax::ast::{struct_field, struct_variant_kind, sty_static, subtract};
45-
use syntax::ast::{trait_ref, tuple_variant_kind, Ty, ty_bool, ty_char};
46-
use syntax::ast::{ty_f, ty_f32, ty_f64, ty_float, ty_i, ty_i16, ty_i32};
47-
use syntax::ast::{ty_i64, ty_i8, ty_int, ty_param, ty_path, ty_str, ty_u};
48-
use syntax::ast::{ty_u16, ty_u32, ty_u64, ty_u8, ty_uint, type_value_ns};
49-
use syntax::ast::{ty_param_bound, unnamed_field};
42+
use syntax::ast::{required, rem, self_ty_, shl, shr, stmt_decl, struct_dtor};
43+
use syntax::ast::{struct_field, struct_variant_kind, sty_by_ref, sty_static};
44+
use syntax::ast::{subtract, trait_ref, tuple_variant_kind, Ty, ty_bool};
45+
use syntax::ast::{ty_char, ty_f, ty_f32, ty_f64, ty_float, ty_i, ty_i16};
46+
use syntax::ast::{ty_i32, ty_i64, ty_i8, ty_int, ty_param, ty_path, ty_str};
47+
use syntax::ast::{ty_u, ty_u16, ty_u32, ty_u64, ty_u8, ty_uint};
48+
use syntax::ast::{type_value_ns, ty_param_bound, unnamed_field};
5049
use syntax::ast::{variant, view_item, view_item_export, view_item_import};
5150
use syntax::ast::{view_item_use, view_path_glob, view_path_list};
5251
use syntax::ast::{view_path_simple, visibility, anonymous, named};
@@ -197,7 +196,7 @@ impl Mutability : cmp::Eq {
197196

198197
enum SelfBinding {
199198
NoSelfBinding,
200-
HasSelfBinding(node_id)
199+
HasSelfBinding(node_id, bool /* is implicit */)
201200
}
202201

203202
enum CaptureClause {
@@ -1753,7 +1752,7 @@ impl Resolver {
17531752
def_self(*) | def_arg(*) | def_local(*) |
17541753
def_prim_ty(*) | def_ty_param(*) | def_binding(*) |
17551754
def_use(*) | def_upvar(*) | def_region(*) |
1756-
def_typaram_binder(*) | def_label(*) => {
1755+
def_typaram_binder(*) | def_label(*) | def_self_ty(*) => {
17571756
fail fmt!("didn't expect `%?`", def);
17581757
}
17591758
}
@@ -3724,7 +3723,7 @@ impl Resolver {
37243723
let self_type_rib = @Rib(NormalRibKind);
37253724
(*self.type_ribs).push(self_type_rib);
37263725
self_type_rib.bindings.insert(self.self_ident,
3727-
dl_def(def_self(item.id)));
3726+
dl_def(def_self_ty(item.id)));
37283727

37293728
// Create a new rib for the trait-wide type parameters.
37303729
do self.with_type_parameter_rib
@@ -3985,8 +3984,9 @@ impl Resolver {
39853984
NoSelfBinding => {
39863985
// Nothing to do.
39873986
}
3988-
HasSelfBinding(self_node_id) => {
3989-
let def_like = dl_def(def_self(self_node_id));
3987+
HasSelfBinding(self_node_id, is_implicit) => {
3988+
let def_like = dl_def(def_self(self_node_id,
3989+
is_implicit));
39903990
(*function_value_rib).bindings.insert(self.self_ident,
39913991
def_like);
39923992
}
@@ -4065,7 +4065,8 @@ impl Resolver {
40654065
NoTypeParameters,
40664066
(*destructor).node.body,
40674067
HasSelfBinding
4068-
((*destructor).node.self_id),
4068+
((*destructor).node.self_id,
4069+
true),
40694070
NoCaptureClause,
40704071
visitor);
40714072
}
@@ -4088,7 +4089,8 @@ impl Resolver {
40884089
// we only have self ty if it is a non static method
40894090
let self_binding = match method.self_ty.node {
40904091
sty_static => { NoSelfBinding }
4091-
_ => { HasSelfBinding(method.self_id) }
4092+
sty_by_ref => { HasSelfBinding(method.self_id, true) }
4093+
_ => { HasSelfBinding(method.self_id, false) }
40924094
};
40934095

40944096
self.resolve_function(rib_kind,

branches/incoming/src/librustc/middle/trans/callee.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ fn trans(bcx: block, expr: @ast::expr) -> Callee {
114114
ast::def_mod(*) | ast::def_foreign_mod(*) |
115115
ast::def_const(*) | ast::def_ty(*) | ast::def_prim_ty(*) |
116116
ast::def_use(*) | ast::def_typaram_binder(*) |
117-
ast::def_region(*) | ast::def_label(*) | ast::def_ty_param(*) => {
117+
ast::def_region(*) | ast::def_label(*) | ast::def_ty_param(*) |
118+
ast::def_self_ty(*) => {
118119
bcx.tcx().sess.span_bug(
119120
ref_expr.span,
120121
fmt!("Cannot translate def %? \

branches/incoming/src/librustc/middle/trans/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ fn trans_local_var(bcx: block,
828828
ast::def_local(nid, _) | ast::def_binding(nid, _) => {
829829
take_local(bcx, bcx.fcx.lllocals, nid, expr_id_opt)
830830
}
831-
ast::def_self(nid) => {
831+
ast::def_self(nid, _) => {
832832
let self_info: ValSelfData = match bcx.fcx.llself {
833833
Some(ref self_info) => *self_info,
834834
None => {

branches/incoming/src/librustc/middle/typeck/astconv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ fn ast_ty_to_ty<AC: ast_conv, RS: region_scope Copy Owned>(
354354
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
355355
ty::mk_param(tcx, n, id)
356356
}
357-
ast::def_self(_) => {
357+
ast::def_self_ty(_) => {
358358
// n.b.: resolve guarantees that the self type only appears in a
359359
// trait, which we rely upon in various places when creating
360360
// substs

branches/incoming/src/librustc/middle/typeck/check/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2721,7 +2721,7 @@ fn ty_param_bounds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) ->
27212721

27222722
match defn {
27232723
ast::def_arg(nid, _) | ast::def_local(nid, _) |
2724-
ast::def_self(nid) | ast::def_binding(nid, _) => {
2724+
ast::def_self(nid, _) | ast::def_binding(nid, _) => {
27252725
assert (fcx.inh.locals.contains_key(nid));
27262726
let typ = ty::mk_var(fcx.ccx.tcx, lookup_local(fcx, sp, nid));
27272727
return no_params(typ);
@@ -2774,6 +2774,9 @@ fn ty_param_bounds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) ->
27742774
ast::def_label(*) => {
27752775
fcx.ccx.tcx.sess.span_bug(sp, ~"expected value but found label");
27762776
}
2777+
ast::def_self_ty(*) => {
2778+
fcx.ccx.tcx.sess.span_bug(sp, ~"expected value but found self ty");
2779+
}
27772780
}
27782781
}
27792782

branches/incoming/src/librustc/middle/typeck/check/regionck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type rvt = visit::vt<@rcx>;
4646
fn encl_region_of_def(fcx: @fn_ctxt, def: ast::def) -> ty::Region {
4747
let tcx = fcx.tcx();
4848
match def {
49-
def_local(node_id, _) | def_arg(node_id, _) | def_self(node_id) |
49+
def_local(node_id, _) | def_arg(node_id, _) | def_self(node_id, _) |
5050
def_binding(node_id, _) =>
5151
return encl_region(tcx, node_id),
5252
def_upvar(_, subdef, closure_id, body_id) => {

branches/incoming/src/libsyntax/ast.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ enum def {
118118
def_static_method(/* method */ def_id,
119119
/* trait */ Option<def_id>,
120120
purity),
121-
def_self(node_id),
121+
def_self(node_id, bool /* is_implicit */),
122+
def_self_ty(node_id),
122123
def_mod(def_id),
123124
def_foreign_mod(def_id),
124125
def_const(def_id),
@@ -156,9 +157,15 @@ impl def : cmp::Eq {
156157
_ => false
157158
}
158159
}
159-
def_self(e0a) => {
160+
def_self(e0a, e1a) => {
160161
match (*other) {
161-
def_self(e0b) => e0a == e0b,
162+
def_self(e0b, e1b) => e0a == e0b && e1a == e1b,
163+
_ => false
164+
}
165+
}
166+
def_self_ty(e0a) => {
167+
match (*other) {
168+
def_self_ty(e0b) => e0a == e0b,
162169
_ => false
163170
}
164171
}

0 commit comments

Comments
 (0)