Skip to content

Commit 950f02b

Browse files
committed
---
yaml --- r: 3815 b: refs/heads/master c: 05390b4 h: refs/heads/master i: 3813: 99dd587 3811: 34e8a77 3807: 0ba1e8d v: v3
1 parent 31db351 commit 950f02b

File tree

9 files changed

+71
-32
lines changed

9 files changed

+71
-32
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 99a95b36133e45fc54e26e2ad86e97e2a7d13ff5
2+
refs/heads/master: 05390b4b38b7ac9d7645afa0be9089a763677393

trunk/src/comp/front/test.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ fn mk_test_desc_rec(&test_ctxt cx, ast::ident[] path) -> @ast::expr {
228228
ident = "name",
229229
expr = @name_expr));
230230

231-
let ast::path fn_path = nospan(rec(idents = path,
231+
let ast::path fn_path = nospan(rec(global = false,
232+
idents = path,
232233
types = ~[]));
233234

234235
let ast::expr fn_expr = rec(id = cx.next_node_id(),
@@ -280,7 +281,8 @@ fn mk_main(&test_ctxt cx) -> @ast::item {
280281

281282
fn mk_test_main_call(&test_ctxt cx) -> @ast::expr {
282283

283-
let ast::path test_path = nospan(rec(idents = ~["tests"],
284+
let ast::path test_path = nospan(rec(global = false,
285+
idents = ~["tests"],
284286
types = ~[]));
285287

286288
let ast::expr_ test_path_expr_ = ast::expr_path(test_path);
@@ -295,7 +297,8 @@ fn mk_test_main_call(&test_ctxt cx) -> @ast::expr {
295297
node = test_call_expr_,
296298
span = rec(lo=0u, hi=0u));
297299

298-
let ast::path test_main_path = nospan(rec(idents = ~["std",
300+
let ast::path test_main_path = nospan(rec(global = false,
301+
idents = ~["std",
299302
"test",
300303
"test_main"],
301304
types = ~[]));

trunk/src/comp/metadata/tydecode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ fn parse_path(@pstate st, str_def sd) -> ast::path {
9191
case (?c) {
9292
if (c == '(') {
9393
ret respan(rec(lo=0u, hi=0u),
94-
rec(idents=idents, types=~[]));
94+
rec(global=false, idents=idents, types=~[]));
9595
}
9696
else {
9797
idents += ~[parse_ident_(st, sd, is_last)];

trunk/src/comp/middle/resolve.rs

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export def_map;
4444
// (FIXME See https://github.com/graydon/rust/issues/358 for the reason this
4545
// isn't a const.)
4646
tag scope {
47-
scope_crate(@ast::crate);
47+
scope_crate;
4848
scope_item(@ast::item);
4949
scope_fn(ast::fn_decl, ast::ty_param[]);
5050
scope_native_item(@ast::native_item);
@@ -154,7 +154,7 @@ fn map_crate(&@env e, &@ast::crate c) {
154154
@rec(visit_view_item=bind index_vi(e, _, _, _),
155155
visit_item=bind index_i(e, _, _, _)
156156
with *visit::default_visitor[scopes]());
157-
visit::visit_crate(*c, cons(scope_crate(c), @nil),
157+
visit::visit_crate(*c, cons(scope_crate, @nil),
158158
visit::mk_vt(v_map_mod));
159159
// Register the top-level mod
160160

@@ -199,7 +199,7 @@ fn map_crate(&@env e, &@ast::crate c) {
199199
@rec(visit_view_item=bind link_glob(e, _, _, _),
200200
visit_item=visit_item_with_scope
201201
with *visit::default_visitor[scopes]());
202-
visit::visit_crate(*c, cons(scope_crate(c), @nil),
202+
visit::visit_crate(*c, cons(scope_crate, @nil),
203203
visit::mk_vt(v_link_glob));
204204
fn link_glob(@env e, &@ast::view_item vi, &scopes sc, &vt[scopes] v) {
205205
fn find_mod(@env e, scopes sc) -> @indexed_mod {
@@ -253,16 +253,16 @@ fn resolve_names(&@env e, &@ast::crate c) {
253253
visit_constr=bind walk_constr(e, _, _, _),
254254
visit_fn=bind visit_fn_with_scope(e, _, _, _, _, _, _, _)
255255
with *visit::default_visitor());
256-
visit::visit_crate(*c, cons(scope_crate(c), @nil), visit::mk_vt(v));
256+
visit::visit_crate(*c, cons(scope_crate, @nil), visit::mk_vt(v));
257257
e.sess.abort_if_errors();
258258

259259
fn walk_expr(@env e, &@ast::expr exp, &scopes sc, &vt[scopes] v) {
260260
visit_expr_with_scope(exp, sc, v);
261261
alt (exp.node) {
262262
case (ast::expr_path(?p)) {
263263
maybe_insert(e, exp.id,
264-
lookup_path_strict(*e, sc, exp.span,
265-
p.node.idents, ns_value));
264+
lookup_path_strict(*e, sc, exp.span, p.node,
265+
ns_value));
266266
}
267267
case (_) { }
268268
}
@@ -272,16 +272,16 @@ fn resolve_names(&@env e, &@ast::crate c) {
272272
alt (t.node) {
273273
case (ast::ty_path(?p, ?id)) {
274274
maybe_insert(e, id,
275-
lookup_path_strict(*e, sc, t.span,
276-
p.node.idents, ns_type));
275+
lookup_path_strict(*e, sc, t.span, p.node,
276+
ns_type));
277277
}
278278
case (_) { }
279279
}
280280
}
281281
fn walk_constr(@env e, &@ast::constr c, &scopes sc, &vt[scopes] v) {
282282
maybe_insert(e, c.node.id,
283-
lookup_path_strict(*e, sc, c.span,
284-
c.node.path.node.idents, ns_value));
283+
lookup_path_strict(*e, sc, c.span, c.node.path.node,
284+
ns_value));
285285
}
286286
fn walk_arm(@env e, &ast::arm a, &scopes sc, &vt[scopes] v) {
287287
for (@ast::pat p in a.pats) { walk_pat(*e, sc, p); }
@@ -291,8 +291,7 @@ fn resolve_names(&@env e, &@ast::crate c) {
291291
alt (pat.node) {
292292
case (ast::pat_tag(?p, ?children)) {
293293
auto fnd =
294-
lookup_path_strict(e, sc, p.span, p.node.idents,
295-
ns_value);
294+
lookup_path_strict(e, sc, p.span, p.node, ns_value);
296295
if (option::is_some(fnd)) {
297296
alt (option::get(fnd)) {
298297
case (ast::def_variant(?did, ?vid)) {
@@ -396,7 +395,7 @@ fn follow_import(&env e, &scopes sc, &ident[] path, &span sp)
396395
fn resolve_constr(@env e, node_id id, &@ast::constr c, &scopes sc,
397396
&vt[scopes] v) {
398397
auto new_def =
399-
lookup_path_strict(*e, sc, c.span, c.node.path.node.idents, ns_value);
398+
lookup_path_strict(*e, sc, c.span, c.node.path.node, ns_value);
400399
if (option::is_some(new_def)) {
401400
alt (option::get(new_def)) {
402401
case (ast::def_fn(?pred_id, ast::pure_fn)) {
@@ -543,16 +542,26 @@ fn mk_unresolved_msg(&ident id, &str kind) -> str {
543542
}
544543

545544
// Lookup helpers
546-
fn lookup_path_strict(&env e, &scopes sc, &span sp, &ident[] idents,
545+
fn lookup_path_strict(&env e, &scopes sc, &span sp, &ast::path_ pth,
547546
namespace ns) -> option::t[def] {
548-
auto n_idents = ivec::len(idents);
547+
auto n_idents = ivec::len(pth.idents);
549548
auto headns = if (n_idents == 1u) { ns } else { ns_module };
550-
auto dcur = lookup_in_scope_strict(e, sc, sp, idents.(0), headns);
549+
550+
auto first_scope;
551+
if (pth.global) {
552+
first_scope = list::cons(scope_crate, @list::nil);
553+
} else {
554+
first_scope = sc;
555+
}
556+
557+
auto dcur = lookup_in_scope_strict(e, first_scope, sp, pth.idents.(0),
558+
headns);
559+
551560
auto i = 1u;
552561
while (i < n_idents && option::is_some(dcur)) {
553562
auto curns = if (n_idents == i + 1u) { ns } else { ns_module };
554563
dcur = lookup_in_mod_strict(e, option::get(dcur),
555-
sp, idents.(i), curns, outside);
564+
sp, pth.idents.(i), curns, outside);
556565
i += 1u;
557566
}
558567
ret dcur;
@@ -592,7 +601,7 @@ fn lookup_in_scope(&env e, scopes sc, &span sp, &ident name, namespace ns) ->
592601
fn in_scope(&env e, &span sp, &ident name, &scope s, namespace ns) ->
593602
option::t[def] {
594603
alt (s) {
595-
case (scope_crate(?c)) {
604+
case (scope_crate) {
596605
ret lookup_in_local_mod(e, -1, sp, name, ns, inside);
597606
}
598607
case (scope_item(?it)) {

trunk/src/comp/syntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type fn_ident = option::t[ident];
1616
// FIXME: with typestate constraint, could say
1717
// idents and types are the same length, and are
1818
// non-empty
19-
type path_ = rec(ident[] idents, (@ty)[] types);
19+
type path_ = rec(bool global, ident[] idents, (@ty)[] types);
2020

2121
type path = spanned[path_];
2222

trunk/src/comp/syntax/ext/fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn pieces_to_expr(&ext_ctxt cx, span sp, vec[piece] pieces,
6363
}
6464
fn make_path_expr(&ext_ctxt cx, span sp, &ast::ident[] idents)
6565
-> @ast::expr {
66-
auto path = rec(idents=idents, types=~[]);
66+
auto path = rec(global=false, idents=idents, types=~[]);
6767
auto sp_path = rec(node=path, span=sp);
6868
auto pathexpr = ast::expr_path(sp_path);
6969
ret @rec(id=cx.next_id(), node=pathexpr, span=sp);

trunk/src/comp/syntax/fold.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,8 @@ fn noop_fold_ident(&ident i, ast_fold fld) -> ident {
499499
}
500500

501501
fn noop_fold_path(&path_ p, ast_fold fld) -> path_ {
502-
ret rec(idents=ivec::map(fld.fold_ident, p.idents),
502+
ret rec(global=p.global,
503+
idents=ivec::map(fld.fold_ident, p.idents),
503504
types=ivec::map(fld.fold_ty, p.types));
504505
}
505506

trunk/src/comp/syntax/parse/parser.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,8 @@ fn parse_ty_postfix(@ast::ty orig_t, &parser p) -> @ast::ty {
421421
auto hi = p.get_hi_pos();
422422
ret @spanned(lo, hi,
423423
ast::ty_path(spanned(lo, hi,
424-
rec(idents=pth.node.idents,
424+
rec(global=pth.node.global,
425+
idents=pth.node.idents,
425426
types=seq_ivec)),
426427
ann));
427428
}
@@ -556,7 +557,7 @@ fn parse_ty(&parser p) -> @ast::ty {
556557
auto typ = parse_ty(p);
557558
t = typ.node;
558559
hi = typ.span.hi;
559-
} else if (is_ident(p.peek())) {
560+
} else if (p.peek() == token::MOD_SEP || is_ident(p.peek())) {
560561
auto path = parse_path(p);
561562
t = ast::ty_path(path, p.get_id());
562563
hi = path.span.hi;
@@ -673,6 +674,14 @@ fn is_ident(token::token t) -> bool {
673674
fn parse_path(&parser p) -> ast::path {
674675
auto lo = p.get_lo_pos();
675676
auto hi = lo;
677+
678+
auto global;
679+
if (p.peek() == token::MOD_SEP) {
680+
global = true; p.bump();
681+
} else {
682+
global = false;
683+
}
684+
676685
let ast::ident[] ids = ~[];
677686
while (true) {
678687
alt (p.peek()) {
@@ -686,7 +695,7 @@ fn parse_path(&parser p) -> ast::path {
686695
}
687696
}
688697
hi = p.get_hi_pos();
689-
ret spanned(lo, hi, rec(idents=ids, types=~[]));
698+
ret spanned(lo, hi, rec(global=global, idents=ids, types=~[]));
690699
}
691700

692701
fn parse_path_and_ty_param_substs(&parser p) -> ast::path {
@@ -701,7 +710,9 @@ fn parse_path_and_ty_param_substs(&parser p) -> ast::path {
701710
for (@ast::ty typ in seq.node) { seq_ivec += ~[typ]; }
702711

703712
auto hi = p.get_hi_pos();
704-
path = spanned(lo, hi, rec(idents=path.node.idents, types=seq_ivec));
713+
path = spanned(lo, hi, rec(global=path.node.global,
714+
idents=path.node.idents,
715+
types=seq_ivec));
705716
}
706717
ret path;
707718
}
@@ -975,8 +986,9 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
975986
parse_expr, p);
976987
hi = es.span.hi;
977988
ex = ast::expr_call(f, es.node);
978-
} else if (is_ident(p.peek()) && !is_word(p, "true") &&
979-
!is_word(p, "false")) {
989+
} else if (p.peek() == token::MOD_SEP ||
990+
(is_ident(p.peek()) && !is_word(p, "true") &&
991+
!is_word(p, "false"))) {
980992
check_bad_word(p);
981993
auto pth = parse_path_and_ty_param_substs(p);
982994
hi = pth.span.hi;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// xfail-stage0
2+
3+
fn f() -> int { ret 1; }
4+
5+
mod foo {
6+
fn f() -> int { ret 2; }
7+
fn g() {
8+
assert (f() == 2);
9+
assert (::f() == 1);
10+
}
11+
}
12+
13+
fn main() { ret foo::g(); }
14+

0 commit comments

Comments
 (0)