Skip to content

Commit b414db0

Browse files
committed
rustc: Parse by-reference pattern bindings with the "ref" keyword
1 parent a841789 commit b414db0

25 files changed

+202
-145
lines changed

src/cargo/cargo.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type package = {
2020
url: ~str,
2121
method: ~str,
2222
description: ~str,
23-
ref: option<~str>,
23+
reference: option<~str>,
2424
tags: ~[~str],
2525
versions: ~[(~str, ~str)]
2626
};
@@ -497,7 +497,7 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
497497
}
498498
};
499499

500-
let ref = alt p.find(~"ref") {
500+
let reference = alt p.find(~"ref") {
501501
some(json::string(n)) { some(*n) }
502502
_ { none }
503503
};
@@ -530,7 +530,7 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
530530
url: url,
531531
method: method,
532532
description: description,
533-
ref: ref,
533+
reference: reference,
534534
tags: tags,
535535
versions: ~[]
536536
};
@@ -815,10 +815,10 @@ fn install_source(c: cargo, path: ~str) {
815815
}
816816
}
817817

818-
fn install_git(c: cargo, wd: ~str, url: ~str, ref: option<~str>) {
818+
fn install_git(c: cargo, wd: ~str, url: ~str, reference: option<~str>) {
819819
run::program_output(~"git", ~[~"clone", url, wd]);
820-
if option::is_some(ref) {
821-
let r = option::get(ref);
820+
if option::is_some(reference) {
821+
let r = option::get(reference);
822822
os::change_dir(wd);
823823
run::run_program(~"git", ~[~"checkout", r]);
824824
}
@@ -855,7 +855,7 @@ fn install_package(c: cargo, src: ~str, wd: ~str, pkg: package) {
855855
info(fmt!{"installing %s/%s via %s...", src, pkg.name, method});
856856

857857
alt method {
858-
~"git" { install_git(c, wd, url, copy pkg.ref); }
858+
~"git" { install_git(c, wd, url, copy pkg.reference); }
859859
~"file" { install_file(c, wd, url); }
860860
~"curl" { install_curl(c, wd, copy url); }
861861
_ {}
@@ -1034,12 +1034,12 @@ fn install_query(c: cargo, wd: ~str, target: ~str) {
10341034
install_file(c, wd, target);
10351035
ret;
10361036
} else if is_git_url(target) {
1037-
let ref = if c.opts.free.len() >= 4u {
1037+
let reference = if c.opts.free.len() >= 4u {
10381038
some(c.opts.free[3u])
10391039
} else {
10401040
none
10411041
};
1042-
install_git(c, wd, target, ref);
1042+
install_git(c, wd, target, reference);
10431043
} else if !valid_pkg_name(target) && has_archive_extension(target) {
10441044
install_curl(c, wd, target);
10451045
ret;

src/libcore/vec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ fn push_slow<T>(&v: ~[const T], +initval: T) {
536536

537537
// Unchecked vector indexing
538538
#[inline(always)]
539-
unsafe fn ref<T: copy>(v: &[const T], i: uint) -> T {
539+
unsafe fn get_ref<T: copy>(v: &[const T], i: uint) -> T {
540540
as_buf(v, |p, _len| *ptr::offset(p, i))
541541
}
542542

@@ -555,7 +555,7 @@ fn push_all<T: copy>(&v: ~[const T], rhs: &[const T]) {
555555
reserve(v, v.len() + rhs.len());
556556

557557
for uint::range(0u, rhs.len()) |i| {
558-
push(v, unsafe { ref(rhs, i) })
558+
push(v, unsafe { get_ref(rhs, i) })
559559
}
560560
}
561561

src/libsyntax/ast.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ type pat = {id: node_id, node: pat_, span: span};
145145
#[auto_serialize]
146146
type field_pat = {ident: ident, pat: @pat};
147147

148+
#[auto_serialize]
149+
enum binding_mode {
150+
bind_by_value,
151+
bind_by_ref
152+
}
153+
148154
#[auto_serialize]
149155
enum pat_ {
150156
pat_wild,
@@ -155,7 +161,7 @@ enum pat_ {
155161
// which it is. The resolver determines this, and
156162
// records this pattern's node_id in an auxiliary
157163
// set (of "pat_idents that refer to nullary enums")
158-
pat_ident(@path, option<@pat>),
164+
pat_ident(binding_mode, @path, option<@pat>),
159165
pat_enum(@path, option<~[@pat]>), // "none" means a * pattern where
160166
// we don't bind the fields to names
161167
pat_rec(~[field_pat], bool),

src/libsyntax/ast_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ fn map_block(b: blk, cx: ctx, v: vt) {
158158
fn number_pat(cx: ctx, pat: @pat) {
159159
do ast_util::walk_pat(pat) |p| {
160160
alt p.node {
161-
pat_ident(_, _) {
161+
pat_ident(*) {
162162
cx.map.insert(p.id, node_local(cx.local_id));
163163
cx.local_id += 1u;
164164
}

src/libsyntax/ast_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,15 +568,15 @@ pure fn is_item_impl(item: @ast::item) -> bool {
568568
fn walk_pat(pat: @pat, it: fn(@pat)) {
569569
it(pat);
570570
alt pat.node {
571-
pat_ident(pth, some(p)) { walk_pat(p, it); }
571+
pat_ident(_, pth, some(p)) { walk_pat(p, it); }
572572
pat_rec(fields, _) {
573573
for fields.each |f| { walk_pat(f.pat, it); }
574574
}
575575
pat_enum(_, some(s)) | pat_tup(s) {
576576
for s.each |p| { walk_pat(p, it); }
577577
}
578578
pat_box(s) | pat_uniq(s) { walk_pat(s, it); }
579-
pat_wild | pat_lit(_) | pat_range(_, _) | pat_ident(_, _)
579+
pat_wild | pat_lit(_) | pat_range(_, _) | pat_ident(_, _, _)
580580
| pat_enum(_, _) {}
581581
}
582582
}

src/libsyntax/ext/auto_serialize.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl helpers of ext_ctxt_helpers for ext_ctxt {
228228
let path = @{span: span, global: false, idents: ~[nm],
229229
rp: none, types: ~[]};
230230
@{id: self.next_id(),
231-
node: ast::pat_ident(path, none),
231+
node: ast::pat_ident(ast::bind_by_ref, path, none),
232232
span: span}
233233
}
234234

@@ -834,7 +834,9 @@ fn ser_enum(cx: ext_ctxt, tps: ser_tps_map, e_name: ast::ident,
834834
// Generate pattern var(v1, v2, v3)
835835
|pats| {
836836
if vec::is_empty(pats) {
837-
ast::pat_ident(cx.path(v_span, ~[v_name]), none)
837+
ast::pat_ident(ast::bind_by_ref,
838+
cx.path(v_span, ~[v_name]),
839+
none)
838840
} else {
839841
ast::pat_enum(cx.path(v_span, ~[v_name]), some(pats))
840842
}

src/libsyntax/ext/pipes/ast_builder.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,10 @@ impl ast_builder of ext_ctxt_ast_builder for ext_ctxt {
116116
@{node: {is_mutbl: false,
117117
ty: self.ty_infer(),
118118
pat: @{id: self.next_id(),
119-
node: ast::pat_ident(
120-
path(ident, self.empty_span()), none),
119+
node: ast::pat_ident(ast::bind_by_ref,
120+
path(ident,
121+
self.empty_span()),
122+
none),
121123
span: self.empty_span()},
122124
init: some({op: ast::init_move,
123125
expr: e}),

src/libsyntax/ext/qquote.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ fn parse_crate(p: parser) -> @ast::crate { p.parse_crate_mod(~[]) }
170170
fn parse_ty(p: parser) -> @ast::ty { p.parse_ty(false) }
171171
fn parse_stmt(p: parser) -> @ast::stmt { p.parse_stmt(~[]) }
172172
fn parse_expr(p: parser) -> @ast::expr { p.parse_expr() }
173-
fn parse_pat(p: parser) -> @ast::pat { p.parse_pat() }
173+
fn parse_pat(p: parser) -> @ast::pat { p.parse_pat(true) }
174174

175175
fn parse_item(p: parser) -> @ast::item {
176176
alt p.parse_item(~[], ast::public) {

src/libsyntax/ext/tt/earley_parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ fn parse_nt(p: parser, name: ~str) -> nonterminal {
326326
}}
327327
~"block" { token::nt_block(p.parse_block()) }
328328
~"stmt" { token::nt_stmt(p.parse_stmt(~[])) }
329-
~"pat" { token::nt_pat(p.parse_pat()) }
329+
~"pat" { token::nt_pat(p.parse_pat(true)) }
330330
~"expr" { token::nt_expr(p.parse_expr()) }
331331
~"ty" { token::nt_ty(p.parse_ty(false /* no need to disambiguate*/)) }
332332
// this could be handled like a token, since it is one

src/libsyntax/fold.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,9 @@ fn noop_fold_arm(a: arm, fld: ast_fold) -> arm {
332332
fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
333333
ret alt p {
334334
pat_wild { pat_wild }
335-
pat_ident(pth, sub) {
336-
pat_ident(fld.fold_path(pth),
335+
pat_ident(binding_mode, pth, sub) {
336+
pat_ident(binding_mode,
337+
fld.fold_path(pth),
337338
option::map(sub, |x| fld.fold_pat(x)))
338339
}
339340
pat_lit(e) { pat_lit(fld.fold_expr(e)) }

0 commit comments

Comments
 (0)