Skip to content

Commit ce7a13f

Browse files
committed
---
yaml --- r: 16081 b: refs/heads/try c: e0f0c5c h: refs/heads/master i: 16079: 8c98f20 v: v3
1 parent 0878399 commit ce7a13f

File tree

6 files changed

+12
-261
lines changed

6 files changed

+12
-261
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: ed5af70a3634915004f24c391a33cbebb8beb7bd
5+
refs/heads/try: e0f0c5c1ab70ad12d7c8f4d8e8c8e40b623e70e3
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/libcore/result.rs

Lines changed: 4 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -107,79 +107,6 @@ fn chain_err<T: copy, U: copy, V: copy>(
107107
}
108108
}
109109

110-
#[doc = "
111-
Call a function based on a previous result
112-
113-
If `res` is `ok` then the value is extracted and passed to `op` whereupon
114-
`op`s result is returned. if `res` is `err` then it is immediately returned.
115-
This function can be used to compose the results of two functions.
116-
117-
Example:
118-
119-
iter(read_file(file)) { |buf|
120-
print_buf(buf)
121-
}
122-
"]
123-
fn iter<T, E>(res: result<T, E>, f: fn(T)) {
124-
alt res {
125-
ok(t) { f(t) }
126-
err(_) { }
127-
}
128-
}
129-
130-
#[doc = "
131-
Call a function based on a previous result
132-
133-
If `res` is `err` then the value is extracted and passed to `op` whereupon
134-
`op`s result is returned. if `res` is `ok` then it is immediately returned.
135-
This function can be used to pass through a successful result while handling
136-
an error.
137-
"]
138-
fn iter_err<T, E>(res: result<T, E>, f: fn(E)) {
139-
alt res {
140-
ok(_) { }
141-
err(e) { f(e) }
142-
}
143-
}
144-
145-
#[doc = "
146-
Call a function based on a previous result
147-
148-
If `res` is `ok` then the value is extracted and passed to `op` whereupon
149-
`op`s result is wrapped in `ok` and returned. if `res` is `err` then it is
150-
immediately returned. This function can be used to compose the results of two
151-
functions.
152-
153-
Example:
154-
155-
let res = map(read_file(file)) { |buf|
156-
parse_buf(buf)
157-
}
158-
"]
159-
fn map<T, E: copy, U: copy>(res: result<T, E>, op: fn(T) -> U)
160-
-> result<U, E> {
161-
alt res {
162-
ok(t) { ok(op(t)) }
163-
err(e) { err(e) }
164-
}
165-
}
166-
167-
#[doc = "
168-
Call a function based on a previous result
169-
170-
If `res` is `err` then the value is extracted and passed to `op` whereupon
171-
`op`s result is wrapped in an `err` and returned. if `res` is `ok` then it is
172-
immediately returned. This function can be used to pass through a successful
173-
result while handling an error.
174-
"]
175-
fn map_err<T: copy, E, F: copy>(res: result<T, E>, op: fn(E) -> F)
176-
-> result<T, F> {
177-
alt res {
178-
ok(t) { ok(t) }
179-
err(e) { err(op(e)) }
180-
}
181-
}
182-
183110
impl extensions<T:copy, E:copy> for result<T,E> {
184111
fn get() -> T { get(self) }
185112

@@ -196,34 +123,6 @@ impl extensions<T:copy, E:copy> for result<T,E> {
196123
fn chain_err<F:copy>(op: fn(E) -> result<T,F>) -> result<T,F> {
197124
chain_err(self, op)
198125
}
199-
200-
fn iter(f: fn(T)) {
201-
alt self {
202-
ok(t) { f(t) }
203-
err(_) { }
204-
}
205-
}
206-
207-
fn iter_err(f: fn(E)) {
208-
alt self {
209-
ok(_) { }
210-
err(e) { f(e) }
211-
}
212-
}
213-
214-
fn map<U:copy>(op: fn(T) -> U) -> result<U,E> {
215-
alt self {
216-
ok(t) { ok(op(t)) }
217-
err(e) { err(e) }
218-
}
219-
}
220-
221-
fn map_err<F:copy>(op: fn(E) -> F) -> result<T,F> {
222-
alt self {
223-
ok(t) { ok(t) }
224-
err(e) { err(op(e)) }
225-
}
226-
}
227126
}
228127

229128
#[doc = "
@@ -243,7 +142,7 @@ checking for overflow:
243142
assert incd == [2u, 3u, 4u];
244143
}
245144
"]
246-
fn map_vec<T,U:copy,V:copy>(
145+
fn map<T,U:copy,V:copy>(
247146
ts: [T], op: fn(T) -> result<V,U>) -> result<[V],U> {
248147

249148
let mut vs: [V] = [];
@@ -278,7 +177,7 @@ length. While we do not often use preconditions in the standard
278177
library, a precondition is used here because result::t is generally
279178
used in 'careful' code contexts where it is both appropriate and easy
280179
to accommodate an error like the vectors being of different lengths."]
281-
fn map_vec2<S,T,U:copy,V:copy>(ss: [S], ts: [T], op: fn(S,T) -> result<V,U>)
180+
fn map2<S,T,U:copy,V:copy>(ss: [S], ts: [T], op: fn(S,T) -> result<V,U>)
282181
: vec::same_length(ss, ts) -> result<[V],U> {
283182

284183
let n = vec::len(ts);
@@ -300,8 +199,8 @@ Applies op to the pairwise elements from `ss` and `ts`, aborting on
300199
error. This could be implemented using `map2()` but it is more efficient
301200
on its own as no result vector is built.
302201
"]
303-
fn iter_vec2<S,T,U:copy>(ss: [S], ts: [T],
304-
op: fn(S,T) -> result<(),U>)
202+
fn iter2<S,T,U:copy>(ss: [S], ts: [T],
203+
op: fn(S,T) -> result<(),U>)
305204
: vec::same_length(ss, ts)
306205
-> result<(),U> {
307206

@@ -349,37 +248,4 @@ mod tests {
349248
fn chain_failure() {
350249
assert get_err(chain(op3(), op2)) == "sadface";
351250
}
352-
353-
#[test]
354-
fn test_impl_iter() {
355-
let mut valid = false;
356-
ok::<str, str>("a").iter { |_x| valid = true; };
357-
assert valid;
358-
359-
err::<str, str>("b").iter { |_x| valid = false; };
360-
assert valid;
361-
}
362-
363-
#[test]
364-
fn test_impl_iter_err() {
365-
let mut valid = true;
366-
ok::<str, str>("a").iter_err { |_x| valid = false; };
367-
assert valid;
368-
369-
valid = false;
370-
err::<str, str>("b").iter_err { |_x| valid = true; };
371-
assert valid;
372-
}
373-
374-
#[test]
375-
fn test_impl_map() {
376-
assert ok::<str, str>("a").map { |_x| "b" } == ok("b");
377-
assert err::<str, str>("a").map { |_x| "b" } == err("a");
378-
}
379-
380-
#[test]
381-
fn test_impl_map_err() {
382-
assert ok::<str, str>("a").map_err { |_x| "b" } == ok("a");
383-
assert err::<str, str>("a").map_err { |_x| "b" } == err("b");
384-
}
385251
}

branches/try/src/libstd/json.rs

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export to_str;
1616
export from_reader;
1717
export from_str;
1818
export eq;
19-
export to_json;
2019

2120
export num;
2221
export string;
@@ -499,110 +498,6 @@ fn eq(value0: json, value1: json) -> bool {
499498
}
500499
}
501500

502-
iface to_json { fn to_json() -> json; }
503-
504-
impl of to_json for json {
505-
fn to_json() -> json { self }
506-
}
507-
508-
impl of to_json for i8 {
509-
fn to_json() -> json { num(self as float) }
510-
}
511-
512-
impl of to_json for i16 {
513-
fn to_json() -> json { num(self as float) }
514-
}
515-
516-
impl of to_json for i32 {
517-
fn to_json() -> json { num(self as float) }
518-
}
519-
520-
impl of to_json for i64 {
521-
fn to_json() -> json { num(self as float) }
522-
}
523-
524-
impl of to_json for u8 {
525-
fn to_json() -> json { num(self as float) }
526-
}
527-
528-
impl of to_json for u16 {
529-
fn to_json() -> json { num(self as float) }
530-
}
531-
532-
impl of to_json for u32 {
533-
fn to_json() -> json { num(self as float) }
534-
}
535-
536-
impl of to_json for u64 {
537-
fn to_json() -> json { num(self as float) }
538-
}
539-
540-
impl of to_json for float {
541-
fn to_json() -> json { num(self) }
542-
}
543-
544-
impl of to_json for f32 {
545-
fn to_json() -> json { num(self as float) }
546-
}
547-
548-
impl of to_json for f64 {
549-
fn to_json() -> json { num(self as float) }
550-
}
551-
552-
impl of to_json for () {
553-
fn to_json() -> json { null }
554-
}
555-
556-
impl of to_json for bool {
557-
fn to_json() -> json { boolean(self) }
558-
}
559-
560-
impl of to_json for str {
561-
fn to_json() -> json { string(self) }
562-
}
563-
564-
impl <A: to_json copy, B: to_json copy> of to_json for (A, B) {
565-
fn to_json() -> json {
566-
let (a, b) = self;
567-
list([a.to_json(), b.to_json()])
568-
}
569-
}
570-
571-
impl <A: to_json copy, B: to_json copy, C: to_json copy>
572-
of to_json for (A, B, C) {
573-
fn to_json() -> json {
574-
let (a, b, c) = self;
575-
list([a.to_json(), b.to_json(), c.to_json()])
576-
}
577-
}
578-
579-
impl <A: to_json> of to_json for [A] {
580-
fn to_json() -> json { list(self.map { |elt| elt.to_json() }) }
581-
}
582-
583-
impl <A: to_json copy> of to_json for hashmap<str, A> {
584-
fn to_json() -> json {
585-
let d = map::str_hash();
586-
for self.each() { |key, value|
587-
d.insert(key, value.to_json());
588-
}
589-
dict(d)
590-
}
591-
}
592-
593-
impl <A: to_json> of to_json for option<A> {
594-
fn to_json() -> json {
595-
alt self {
596-
none { null }
597-
some(value) { value.to_json() }
598-
}
599-
}
600-
}
601-
602-
impl of to_str::to_str for json {
603-
fn to_str() -> str { to_str(self) }
604-
}
605-
606501
#[cfg(test)]
607502
mod tests {
608503
fn mk_dict(items: [(str, json)]) -> json {

branches/try/src/rustc/middle/trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ fn make_visit_glue(bcx: block, v: ValueRef, t: ty::t) {
644644
assert bcx.ccx().tcx.intrinsic_ifaces.contains_key("ty_visitor");
645645
let (iid, ty) = bcx.ccx().tcx.intrinsic_ifaces.get("ty_visitor");
646646
let v = PointerCast(bcx, v, T_ptr(type_of::type_of(bcx.ccx(), ty)));
647-
bcx = reflect::emit_calls_to_iface_visit_ty(bcx, t, Load(bcx, v), iid);
647+
bcx = reflect::emit_calls_to_iface_visit_ty(bcx, t, v, iid);
648648
build_return(bcx);
649649
}
650650

branches/try/src/rustc/middle/typeck/infer.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ import middle::ty::{ty_vid, tys_in_fn_ty, region_vid, vid};
151151
import syntax::{ast, ast_util};
152152
import syntax::ast::{ret_style};
153153
import util::ppaux::{ty_to_str, mt_to_str};
154-
import result::{result, extensions, ok, err, map_vec, map_vec2, iter_vec2};
154+
import result::{result, extensions, ok, err, map, map2, iter2};
155155
import ty::{mk_fn, type_is_bot};
156156
import check::regionmanip::{collect_bound_regions_in_tys,
157157
replace_bound_regions};
@@ -753,7 +753,7 @@ impl unify_methods for infer_ctxt {
753753
as: [@ty::type_constr], bs: [@ty::type_constr]) -> ures {
754754

755755
if check vec::same_length(as, bs) {
756-
iter_vec2(as, bs) {|a,b|
756+
iter2(as, bs) {|a,b|
757757
self.constrs(a, b)
758758
}
759759
} else {
@@ -1237,9 +1237,7 @@ fn super_tps<C:combine>(
12371237
// variance.
12381238

12391239
if check vec::same_length(as, bs) {
1240-
iter_vec2(as, bs) {|a, b|
1241-
self.infcx().eq_tys(a, b)
1242-
}.then {||
1240+
iter2(as, bs) {|a, b| self.infcx().eq_tys(a, b) }.then {||
12431241
ok(as)
12441242
}
12451243
} else {
@@ -1333,7 +1331,7 @@ fn super_fns<C:combine>(
13331331
self: C, a_args: [ty::arg], b_args: [ty::arg]) -> cres<[ty::arg]> {
13341332

13351333
if check vec::same_length(a_args, b_args) {
1336-
map_vec2(a_args, b_args) {|a, b| self.args(a, b) }
1334+
map2(a_args, b_args) {|a, b| self.args(a, b) }
13371335
} else {
13381336
err(ty::terr_arg_count)
13391337
}
@@ -1471,9 +1469,7 @@ fn super_tys<C:combine>(
14711469

14721470
(ty::ty_rec(as), ty::ty_rec(bs)) {
14731471
if check vec::same_length(as, bs) {
1474-
map_vec2(as, bs) {|a,b|
1475-
self.flds(a, b)
1476-
}.chain {|flds|
1472+
map2(as, bs) {|a,b| self.flds(a, b) }.chain {|flds|
14771473
ok(ty::mk_rec(tcx, flds))
14781474
}
14791475
} else {
@@ -1483,7 +1479,7 @@ fn super_tys<C:combine>(
14831479

14841480
(ty::ty_tup(as), ty::ty_tup(bs)) {
14851481
if check vec::same_length(as, bs) {
1486-
map_vec2(as, bs) {|a, b| self.tys(a, b) }.chain {|ts|
1482+
map2(as, bs) {|a, b| self.tys(a, b) }.chain {|ts|
14871483
ok(ty::mk_tup(tcx, ts))
14881484
}
14891485
} else {

branches/try/src/test/run-pass/reflect-visit-type.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
// xfail-test
2-
//
3-
// This doesn't work quite yet. There's something wrong with the callback
4-
// type when dispatching through the visit_glue. Get a GEP crash on the
5-
// callee.
6-
71
enum my_visitor = @{ mut types: [str] };
82

93
impl of intrinsic::ty_visitor for my_visitor {

0 commit comments

Comments
 (0)