Skip to content

Commit 2ccbfee

Browse files
committed
---
yaml --- r: 16107 b: refs/heads/try c: 653a1f8 h: refs/heads/master i: 16105: f1cefa1 16103: 1f8c991 v: v3
1 parent 0748afa commit 2ccbfee

22 files changed

+323
-144
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 22a10f0e4afc504384f5a64ecb8d6b44cb3d9503
5+
refs/heads/try: 653a1f8781cd4148d836915228ac28f13853457d
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/librustsyntax/parse/parser.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,18 @@ class parser {
136136
}
137137
fn get_id() -> node_id { next_node_id(self.sess) }
138138

139-
fn parse_ty_fn() -> fn_decl {
139+
fn parse_ty_fn(purity: ast::purity) -> ty_ {
140+
let proto = if self.eat_keyword("native") {
141+
self.expect_keyword("fn");
142+
ast::proto_bare
143+
} else {
144+
self.expect_keyword("fn");
145+
self.parse_fn_ty_proto()
146+
};
147+
ty_fn(proto, self.parse_ty_fn_decl(purity))
148+
}
149+
150+
fn parse_ty_fn_decl(purity: ast::purity) -> fn_decl {
140151
let inputs =
141152
self.parse_seq(token::LPAREN, token::RPAREN,
142153
seq_sep(token::COMMA)) { |p|
@@ -159,7 +170,7 @@ class parser {
159170
let constrs: [@constr] = [];
160171
let (ret_style, ret_ty) = self.parse_ret_ty();
161172
ret {inputs: inputs.node, output: ret_ty,
162-
purity: impure_fn, cf: ret_style,
173+
purity: purity, cf: ret_style,
163174
constraints: constrs};
164175
}
165176

@@ -170,7 +181,7 @@ class parser {
170181
let pur = p.parse_fn_purity();
171182
let ident = p.parse_method_name();
172183
let tps = p.parse_ty_params();
173-
let d = p.parse_ty_fn(), fhi = p.last_span.hi;
184+
let d = p.parse_ty_fn_decl(pur), fhi = p.last_span.hi;
174185
self.expect(token::SEMI);
175186
{ident: ident, attrs: attrs, decl: {purity: pur with d}, tps: tps,
176187
span: mk_sp(flo, fhi)}
@@ -384,16 +395,15 @@ class parser {
384395
let region = self.parse_region_dot();
385396
let mt = self.parse_mt();
386397
ty_rptr(region, mt)
387-
} else if self.eat_keyword("fn") {
388-
let proto = self.parse_fn_ty_proto();
389-
alt proto {
390-
proto_bare { self.warn("fn is deprecated, use native fn"); }
391-
_ { /* fallthrough */ }
392-
}
393-
ty_fn(proto, self.parse_ty_fn())
398+
} else if self.eat_keyword("pure") {
399+
self.parse_ty_fn(ast::pure_fn)
400+
} else if self.eat_keyword("unsafe") {
401+
self.parse_ty_fn(ast::unsafe_fn)
402+
} else if self.is_keyword("fn") {
403+
self.parse_ty_fn(ast::impure_fn)
394404
} else if self.eat_keyword("native") {
395405
self.expect_keyword("fn");
396-
ty_fn(proto_bare, self.parse_ty_fn())
406+
ty_fn(proto_bare, self.parse_ty_fn_decl(ast::impure_fn))
397407
} else if self.token == token::MOD_SEP || is_ident(self.token) {
398408
let path = self.parse_path_with_tps(colons_before_params);
399409
ty_path(path, self.get_id())

branches/try/src/librustsyntax/print/pprust.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
10291029
cbox(s, indent_unit);
10301030
// head-box, will be closed by print-block at start
10311031
ibox(s, 0u);
1032+
print_purity(s, decl.purity);
10321033
word(s.s, proto_to_str(proto));
10331034
print_fn_args_and_ret(s, decl, *cap_clause);
10341035
space(s.s);
@@ -1322,10 +1323,8 @@ fn print_pat(s: ps, &&pat: @ast::pat) {
13221323
fn print_fn(s: ps, decl: ast::fn_decl, name: ast::ident,
13231324
typarams: [ast::ty_param]) {
13241325
alt decl.purity {
1325-
ast::impure_fn { head(s, "fn"); }
1326-
ast::unsafe_fn { head(s, "unsafe fn"); }
1327-
ast::pure_fn { head(s, "pure fn"); }
1328-
ast::crust_fn { head(s, "crust fn"); }
1326+
ast::impure_fn { head(s, "fn") }
1327+
_ { head(s, purity_to_str(decl.purity) + " fn") }
13291328
}
13301329
word(s.s, name);
13311330
print_type_params(s, typarams);
@@ -1825,6 +1824,22 @@ fn opt_proto_to_str(opt_p: option<ast::proto>) -> str {
18251824
}
18261825
}
18271826

1827+
fn purity_to_str(p: ast::purity) -> str {
1828+
alt p {
1829+
ast::impure_fn {"impure"}
1830+
ast::unsafe_fn {"unsafe"}
1831+
ast::pure_fn {"pure"}
1832+
ast::crust_fn {"crust"}
1833+
}
1834+
}
1835+
1836+
fn print_purity(s: ps, p: ast::purity) {
1837+
alt p {
1838+
ast::impure_fn {}
1839+
_ { word_nbsp(s, purity_to_str(p)) }
1840+
}
1841+
}
1842+
18281843
fn proto_to_str(p: ast::proto) -> str {
18291844
ret alt p {
18301845
ast::proto_bare { "native fn" }

branches/try/src/rustc/metadata/tydecode.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ fn parse_constr<T: copy>(st: @pstate, conv: conv_did,
159159
ret @respan(sp, {path: pth, args: args, id: def});
160160
}
161161

162-
fn parse_ty_rust_fn(st: @pstate, conv: conv_did, p: ast::proto) -> ty::t {
163-
ret ty::mk_fn(st.tcx, {proto: p with parse_ty_fn(st, conv)});
162+
fn parse_ty_rust_fn(st: @pstate, conv: conv_did) -> ty::t {
163+
ret ty::mk_fn(st.tcx, parse_ty_fn(st, conv));
164164
}
165165

166166
fn parse_proto(c: char) -> ast::proto {
@@ -335,8 +335,7 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
335335
ret ty::mk_tup(st.tcx, params);
336336
}
337337
'f' {
338-
let proto = parse_proto(next(st));
339-
parse_ty_rust_fn(st, conv, proto)
338+
parse_ty_rust_fn(st, conv)
340339
}
341340
'r' {
342341
assert next(st) == '[';
@@ -441,7 +440,18 @@ fn parse_hex(st: @pstate) -> uint {
441440
};
442441
}
443442

443+
fn parse_purity(c: char) -> purity {
444+
alt check c {
445+
'u' {unsafe_fn}
446+
'p' {pure_fn}
447+
'i' {impure_fn}
448+
'c' {crust_fn}
449+
}
450+
}
451+
444452
fn parse_ty_fn(st: @pstate, conv: conv_did) -> ty::fn_ty {
453+
let proto = parse_proto(next(st));
454+
let purity = parse_purity(next(st));
445455
assert (next(st) == '[');
446456
let mut inputs: [ty::arg] = [];
447457
while peek(st) != ']' {
@@ -458,7 +468,7 @@ fn parse_ty_fn(st: @pstate, conv: conv_did) -> ty::fn_ty {
458468
st.pos += 1u; // eat the ']'
459469
let cs = parse_constrs(st, conv);
460470
let (ret_style, ret_ty) = parse_ret_ty(st, conv);
461-
ret {proto: ast::proto_bare, inputs: inputs, output: ret_ty,
471+
ret {purity: purity, proto: proto, inputs: inputs, output: ret_ty,
462472
ret_style: ret_style, constraints: cs};
463473
}
464474

branches/try/src/rustc/metadata/tyencode.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
262262
w.write_char(']');
263263
}
264264
ty::ty_fn(f) {
265-
enc_proto(w, f.proto);
266265
enc_ty_fn(w, cx, f);
267266
}
268267
ty::ty_res(def, ty, substs) {
@@ -331,7 +330,18 @@ fn enc_mode(w: io::writer, cx: @ctxt, m: mode) {
331330
}
332331
}
333332

333+
fn enc_purity(w: io::writer, p: purity) {
334+
alt p {
335+
pure_fn { w.write_char('p'); }
336+
impure_fn { w.write_char('i'); }
337+
unsafe_fn { w.write_char('u'); }
338+
crust_fn { w.write_char('c'); }
339+
}
340+
}
341+
334342
fn enc_ty_fn(w: io::writer, cx: @ctxt, ft: ty::fn_ty) {
343+
enc_proto(w, ft.proto);
344+
enc_purity(w, ft.purity);
335345
w.write_char('[');
336346
for ft.inputs.each {|arg|
337347
enc_mode(w, cx, arg.mode);

0 commit comments

Comments
 (0)