Skip to content

Commit 99e7552

Browse files
committed
---
yaml --- r: 30541 b: refs/heads/incoming c: 7107b4e h: refs/heads/master i: 30539: 5de2bd8 v: v3
1 parent 392ffd0 commit 99e7552

File tree

8 files changed

+93
-60
lines changed

8 files changed

+93
-60
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: 34cece99cce373546d62aed06a7ec55d04aaa124
9+
refs/heads/incoming: 7107b4eff51e58aa1ae5e30b073b4d788b13a2cb
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/libsyntax/ast.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,12 @@ impl prim_ty : cmp::Eq {
10471047
type region = {id: node_id, node: region_};
10481048

10491049
#[auto_serialize]
1050-
enum region_ { re_anon, re_named(ident) }
1050+
enum region_ {
1051+
re_anon,
1052+
re_static,
1053+
re_self,
1054+
re_named(ident)
1055+
}
10511056

10521057
#[auto_serialize]
10531058
enum ty_ {

branches/incoming/src/libsyntax/parse/parser.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use result::Result;
44
use either::{Either, Left, Right};
55
use std::map::{HashMap, str_hash};
66
use token::{can_begin_expr, is_ident, is_ident_or_path, is_plain_ident,
7-
INTERPOLATED};
7+
INTERPOLATED, special_idents};
88
use codemap::{span,fss_none};
99
use util::interner::interner;
1010
use ast_util::{spanned, respan, mk_sp, ident_to_path, operator_prec};
@@ -51,7 +51,8 @@ use ast::{_mod, add, alt_check, alt_exhaustive, arg, arm, attribute,
5151
pat_ident, pat_lit, pat_range, pat_rec, pat_region, pat_struct,
5252
pat_tup, pat_uniq, pat_wild, path, private, proto, proto_bare,
5353
proto_block, proto_box, proto_uniq, provided, public, pure_fn,
54-
purity, re_anon, re_named, region, rem, required, ret_style,
54+
purity, re_static, re_self, re_anon, re_named, region,
55+
rem, required, ret_style,
5556
return_val, self_ty, shl, shr, stmt, stmt_decl, stmt_expr,
5657
stmt_semi, struct_def, struct_field, struct_variant_kind,
5758
subtract, sty_box, sty_by_ref, sty_region, sty_static, sty_uniq,
@@ -432,8 +433,10 @@ impl parser {
432433

433434
fn region_from_name(s: Option<ident>) -> @region {
434435
let r = match s {
435-
Some (id) => re_named(id),
436-
None => re_anon
436+
Some(id) if id == special_idents::static => ast::re_static,
437+
Some(id) if id == special_idents::self_ => re_self,
438+
Some(id) => re_named(id),
439+
None => re_anon
437440
};
438441

439442
@{id: self.get_id(), node: r}
@@ -614,7 +617,7 @@ impl parser {
614617
let name = self.parse_value_ident();
615618
self.bump();
616619
name
617-
} else { token::special_idents::invalid }
620+
} else { special_idents::invalid }
618621
};
619622

620623
let t = self.parse_ty(false);
@@ -2388,7 +2391,7 @@ impl parser {
23882391

23892392
fn is_self_ident() -> bool {
23902393
match self.token {
2391-
token::IDENT(id, false) if id == token::special_idents::self_
2394+
token::IDENT(id, false) if id == special_idents::self_
23922395
=> true,
23932396
_ => false
23942397
}
@@ -2603,7 +2606,7 @@ impl parser {
26032606

26042607
// This is a new-style impl declaration.
26052608
// XXX: clownshoes
2606-
let ident = token::special_idents::clownshoes_extensions;
2609+
let ident = special_idents::clownshoes_extensions;
26072610

26082611
// Parse the type.
26092612
let ty = self.parse_ty(false);
@@ -3019,7 +3022,7 @@ impl parser {
30193022
}
30203023

30213024
(ast::anonymous,
3022-
token::special_idents::clownshoes_foreign_mod)
3025+
special_idents::clownshoes_foreign_mod)
30233026
}
30243027
};
30253028

branches/incoming/src/libsyntax/print/pprust.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -328,14 +328,24 @@ fn print_foreign_mod(s: ps, nmod: ast::foreign_mod,
328328
for nmod.items.each |item| { print_foreign_item(s, item); }
329329
}
330330
331-
fn print_region(s: ps, region: @ast::region) {
331+
fn print_region(s: ps, region: @ast::region, sep: ~str) {
332332
match region.node {
333-
ast::re_anon => word_space(s, ~"&"),
334-
ast::re_named(name) => {
335-
word(s.s, ~"&");
336-
print_ident(s, name);
337-
}
333+
ast::re_anon => {
334+
word_space(s, ~"&");
335+
return;
336+
}
337+
ast::re_static => {
338+
word_space(s, ~"&static")
339+
}
340+
ast::re_self => {
341+
word_space(s, ~"&self")
342+
}
343+
ast::re_named(name) => {
344+
word(s.s, ~"&");
345+
print_ident(s, name);
346+
}
338347
}
348+
word(s.s, sep);
339349
}
340350
341351
fn print_type(s: ps, &&ty: @ast::ty) {
@@ -362,11 +372,8 @@ fn print_type_ex(s: ps, &&ty: @ast::ty, print_colons: bool) {
362372
}
363373
ast::ty_ptr(mt) => { word(s.s, ~"*"); print_mt(s, mt); }
364374
ast::ty_rptr(region, mt) => {
365-
match region.node {
366-
ast::re_anon => word(s.s, ~"&"),
367-
_ => { print_region(s, region); word(s.s, ~"/"); }
368-
}
369-
print_mt(s, mt);
375+
print_region(s, region, ~"/");
376+
print_mt(s, mt);
370377
}
371378
ast::ty_rec(fields) => {
372379
word(s.s, ~"{");
@@ -961,18 +968,11 @@ fn print_mac(s: ps, m: ast::mac) {
961968

962969
fn print_vstore(s: ps, t: ast::vstore) {
963970
match t {
964-
ast::vstore_fixed(Some(i)) => word(s.s, fmt!("%u", i)),
965-
ast::vstore_fixed(None) => word(s.s, ~"_"),
966-
ast::vstore_uniq => word(s.s, ~"~"),
967-
ast::vstore_box => word(s.s, ~"@"),
968-
ast::vstore_slice(r) => match r.node {
969-
ast::re_anon => word(s.s, ~"&"),
970-
ast::re_named(name) => {
971-
word(s.s, ~"&");
972-
print_ident(s, name);
973-
word(s.s, ~".");
974-
}
975-
}
971+
ast::vstore_fixed(Some(i)) => word(s.s, fmt!("%u", i)),
972+
ast::vstore_fixed(None) => word(s.s, ~"_"),
973+
ast::vstore_uniq => word(s.s, ~"~"),
974+
ast::vstore_box => word(s.s, ~"@"),
975+
ast::vstore_slice(r) => print_region(s, r, ~"/")
976976
}
977977
}
978978

@@ -1455,7 +1455,7 @@ fn print_path(s: ps, &&path: @ast::path, colons_before_params: bool) {
14551455
None => { /* ok */ }
14561456
Some(r) => {
14571457
word(s.s, ~"/");
1458-
print_region(s, r);
1458+
print_region(s, r, ~"");
14591459
}
14601460
}
14611461

branches/incoming/src/rustc/middle/region.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,10 @@ impl determine_rp_ctxt {
522522
// that flag to false when we enter a method.
523523
fn region_is_relevant(r: @ast::region) -> bool {
524524
match r.node {
525+
ast::re_static => false,
525526
ast::re_anon => self.anon_implies_rp,
526-
ast::re_named(id) => {
527-
id == syntax::parse::token::special_idents::self_
528-
}
527+
ast::re_self => true,
528+
ast::re_named(_) => false
529529
}
530530
}
531531

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ fn ast_region_to_region<AC: ast_conv, RS: region_scope Copy Owned>(
7373
self: AC, rscope: RS, span: span, a_r: @ast::region) -> ty::region {
7474

7575
let res = match a_r.node {
76-
ast::re_anon => rscope.anon_region(span),
77-
ast::re_named(id) => rscope.named_region(span, id)
76+
ast::re_static => Ok(ty::re_static),
77+
ast::re_anon => rscope.anon_region(span),
78+
ast::re_self => rscope.self_region(span),
79+
ast::re_named(id) => rscope.named_region(span, id)
7880
};
7981

8082
get_region_reporting_err(self.tcx(), span, res)

branches/incoming/src/rustc/middle/typeck/check.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ use syntax::ast::ty_i;
7777
use typeck::infer::{resolve_type, force_tvar};
7878
use result::{Result, Ok, Err};
7979
use syntax::print::pprust;
80+
use syntax::parse::token::special_idents;
8081

8182
use std::map::{str_hash, uint_hash};
8283

@@ -567,22 +568,34 @@ impl @fn_ctxt: ast_conv {
567568
}
568569
}
569570

571+
impl @fn_ctxt {
572+
fn search_in_scope_regions(br: ty::bound_region)
573+
-> Result<ty::region, ~str>
574+
{
575+
match self.in_scope_regions.find(br) {
576+
Some(r) => result::Ok(r),
577+
None => {
578+
let blk_br = ty::br_named(special_idents::blk);
579+
if br == blk_br {
580+
result::Ok(self.block_region())
581+
} else {
582+
result::Err(fmt!("named region `%s` not in scope here",
583+
bound_region_to_str(self.tcx(), br)))
584+
}
585+
}
586+
}
587+
}
588+
}
589+
570590
impl @fn_ctxt: region_scope {
571591
fn anon_region(span: span) -> Result<ty::region, ~str> {
572592
result::Ok(self.infcx().next_region_var_nb(span))
573593
}
574-
fn named_region(span: span, id: ast::ident) -> Result<ty::region, ~str> {
575-
do empty_rscope.named_region(span, id).chain_err |_e| {
576-
match self.in_scope_regions.find(ty::br_named(id)) {
577-
Some(r) => result::Ok(r),
578-
None if id == syntax::parse::token::special_idents::blk
579-
=> result::Ok(self.block_region()),
580-
None => {
581-
result::Err(fmt!("named region `%s` not in scope here",
582-
self.ccx.tcx.sess.str_of(id)))
583-
}
584-
}
585-
}
594+
fn self_region(_span: span) -> Result<ty::region, ~str> {
595+
self.search_in_scope_regions(ty::br_self)
596+
}
597+
fn named_region(_span: span, id: ast::ident) -> Result<ty::region, ~str> {
598+
self.search_in_scope_regions(ty::br_named(id))
586599
}
587600
}
588601

branches/incoming/src/rustc/middle/typeck/rscope.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use syntax::parse::token::special_idents;
33

44
trait region_scope {
55
fn anon_region(span: span) -> Result<ty::region, ~str>;
6+
fn self_region(span: span) -> Result<ty::region, ~str>;
67
fn named_region(span: span, id: ast::ident) -> Result<ty::region, ~str>;
78
}
89

@@ -11,9 +12,13 @@ impl empty_rscope: region_scope {
1112
fn anon_region(_span: span) -> Result<ty::region, ~str> {
1213
result::Ok(ty::re_static)
1314
}
14-
fn named_region(_span: span, id: ast::ident) -> Result<ty::region, ~str> {
15-
if id == special_idents::static { result::Ok(ty::re_static) }
16-
else { result::Err(~"only the static region is allowed here") }
15+
fn self_region(_span: span) -> Result<ty::region, ~str> {
16+
result::Err(~"only the static region is allowed here")
17+
}
18+
fn named_region(_span: span, _id: ast::ident)
19+
-> Result<ty::region, ~str>
20+
{
21+
result::Err(~"only the static region is allowed here")
1722
}
1823
}
1924

@@ -26,14 +31,13 @@ impl type_rscope: region_scope {
2631
type must be declared with a region bound")
2732
}
2833
}
34+
fn self_region(span: span) -> Result<ty::region, ~str> {
35+
self.anon_region(span)
36+
}
2937
fn named_region(span: span, id: ast::ident) -> Result<ty::region, ~str> {
3038
do empty_rscope.named_region(span, id).chain_err |_e| {
31-
if id == special_idents::self_ {
32-
self.anon_region(span)
33-
} else {
34-
result::Err(~"named regions other than `self` are not \
35-
allowed as part of a type declaration")
36-
}
39+
result::Err(~"named regions other than `self` are not \
40+
allowed as part of a type declaration")
3741
}
3842
}
3943
}
@@ -54,6 +58,9 @@ impl @anon_rscope: region_scope {
5458
fn anon_region(_span: span) -> Result<ty::region, ~str> {
5559
result::Ok(self.anon)
5660
}
61+
fn self_region(span: span) -> Result<ty::region, ~str> {
62+
self.base.self_region(span)
63+
}
5764
fn named_region(span: span, id: ast::ident) -> Result<ty::region, ~str> {
5865
self.base.named_region(span, id)
5966
}
@@ -74,6 +81,9 @@ impl @binding_rscope: region_scope {
7481
self.anon_bindings += 1;
7582
result::Ok(ty::re_bound(ty::br_anon(idx)))
7683
}
84+
fn self_region(span: span) -> Result<ty::region, ~str> {
85+
self.base.self_region(span)
86+
}
7787
fn named_region(span: span, id: ast::ident) -> Result<ty::region, ~str> {
7888
do self.base.named_region(span, id).chain_err |_e| {
7989
result::Ok(ty::re_bound(ty::br_named(id)))

0 commit comments

Comments
 (0)