diff options
| author | Marijn Haverbeke <marijnh@gmail.com> | 2012-03-07 12:54:00 +0100 |
|---|---|---|
| committer | Marijn Haverbeke <marijnh@gmail.com> | 2012-03-08 21:17:32 +0100 |
| commit | c71306b0dbdec6c8d6aaec06cb6770d5b0a2a7cc (patch) | |
| tree | 4b3a69f7b3e8af17f7049e4f3b48b1dbfa327579 /src/rustc/syntax | |
| parent | fd465f91a89450b7daebecdde9c280a923bbe394 (diff) | |
| download | rust-c71306b0dbdec6c8d6aaec06cb6770d5b0a2a7cc.tar.gz rust-c71306b0dbdec6c8d6aaec06cb6770d5b0a2a7cc.zip | |
Explicitly store self_ids use for self locals in methods
This makes it possible to move them between crates without confusion, and to instantiate them at a point where the monomorphizing substitutions are known. Issue #1944
Diffstat (limited to 'src/rustc/syntax')
| -rw-r--r-- | src/rustc/syntax/ast.rs | 2 | ||||
| -rw-r--r-- | src/rustc/syntax/ast_util.rs | 2 | ||||
| -rw-r--r-- | src/rustc/syntax/fold.rs | 3 | ||||
| -rw-r--r-- | src/rustc/syntax/parse/parser.rs | 3 | ||||
| -rw-r--r-- | src/rustc/syntax/visit.rs | 8 |
5 files changed, 10 insertions, 8 deletions
diff --git a/src/rustc/syntax/ast.rs b/src/rustc/syntax/ast.rs index b9102ff4b22..e29b80f8d46 100644 --- a/src/rustc/syntax/ast.rs +++ b/src/rustc/syntax/ast.rs @@ -424,7 +424,7 @@ enum ret_style { type method = {ident: ident, attrs: [attribute], tps: [ty_param], decl: fn_decl, body: blk, - id: node_id, span: span}; + id: node_id, span: span, self_id: node_id}; type _mod = {view_items: [@view_item], items: [@item]}; diff --git a/src/rustc/syntax/ast_util.rs b/src/rustc/syntax/ast_util.rs index dc0939cc2e4..98f87008a60 100644 --- a/src/rustc/syntax/ast_util.rs +++ b/src/rustc/syntax/ast_util.rs @@ -41,7 +41,7 @@ fn def_id_of_def(d: def) -> def_id { def_use(id) | def_class(id) | def_class_field(_, id) | def_class_method(_, id) { id } - def_self(id) | def_arg(id, _) | def_local(id, _) | + def_arg(id, _) | def_local(id, _) | def_self(id) | def_upvar(id, _, _) | def_binding(id) { local_def(id) } diff --git a/src/rustc/syntax/fold.rs b/src/rustc/syntax/fold.rs index bc9b4b79048..25e6219161f 100644 --- a/src/rustc/syntax/fold.rs +++ b/src/rustc/syntax/fold.rs @@ -301,7 +301,8 @@ fn noop_fold_method(&&m: @method, fld: ast_fold) -> @method { decl: fold_fn_decl(m.decl, fld), body: fld.fold_block(m.body), id: fld.new_id(m.id), - span: fld.new_span(m.span)}; + span: fld.new_span(m.span), + self_id: fld.new_id(m.self_id)}; } diff --git a/src/rustc/syntax/parse/parser.rs b/src/rustc/syntax/parse/parser.rs index ec7b63926c9..69c28c3c904 100644 --- a/src/rustc/syntax/parse/parser.rs +++ b/src/rustc/syntax/parse/parser.rs @@ -1931,7 +1931,8 @@ fn parse_method(p: parser) -> @ast::method { let (inner_attrs, body) = parse_inner_attrs_and_block(p, true); let attrs = attrs + inner_attrs; @{ident: ident, attrs: attrs, tps: tps, decl: decl, body: body, - id: p.get_id(), span: ast_util::mk_sp(lo, body.span.hi)} + id: p.get_id(), span: ast_util::mk_sp(lo, body.span.hi), + self_id: p.get_id()} } fn parse_item_iface(p: parser, attrs: [ast::attribute]) -> @ast::item { diff --git a/src/rustc/syntax/visit.rs b/src/rustc/syntax/visit.rs index dd1a53942fa..dd39028aab3 100644 --- a/src/rustc/syntax/visit.rs +++ b/src/rustc/syntax/visit.rs @@ -14,7 +14,7 @@ enum vt<E> { mk_vt(visitor<E>), } enum fn_kind { fk_item_fn(ident, [ty_param]), //< an item declared with fn() - fk_method(ident, [ty_param]), + fk_method(ident, [ty_param], @method), fk_res(ident, [ty_param]), fk_anon(proto), //< an anonymous function like fn@(...) fk_fn_block, //< a block {||...} @@ -22,14 +22,14 @@ enum fn_kind { fn name_of_fn(fk: fn_kind) -> ident { alt fk { - fk_item_fn(name, _) | fk_method(name, _) | fk_res(name, _) { name } + fk_item_fn(name, _) | fk_method(name, _, _) | fk_res(name, _) { name } fk_anon(_) | fk_fn_block { "anon" } } } fn tps_of_fn(fk: fn_kind) -> [ty_param] { alt fk { - fk_item_fn(_, tps) | fk_method(_, tps) | fk_res(_, tps) { tps } + fk_item_fn(_, tps) | fk_method(_, tps, _) | fk_res(_, tps) { tps } fk_anon(_) | fk_fn_block { [] } } } @@ -256,7 +256,7 @@ fn visit_fn_decl<E>(fd: fn_decl, e: E, v: vt<E>) { // because it is not a default impl of any method, though I doubt that really // clarifies anything. - Niko fn visit_method_helper<E>(m: @method, e: E, v: vt<E>) { - v.visit_fn(fk_method(m.ident, m.tps), m.decl, m.body, m.span, + v.visit_fn(fk_method(m.ident, m.tps, m), m.decl, m.body, m.span, m.id, e, v); } |
