Skip to content

Commit e19e628

Browse files
committed
Demode iter-trait
1 parent 473a866 commit e19e628

File tree

21 files changed

+70
-68
lines changed

21 files changed

+70
-68
lines changed

src/libcore/iter-trait.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22
// workaround our lack of traits and lack of macros. See core.{rc,rs} for
33
// how this file is used.
44

5+
#[warn(deprecated_mode)];
6+
57
use cmp::{Eq, Ord};
68
use inst::{IMPL_T, EACH, SIZE_HINT};
79
export extensions;
810

911
impl<A> IMPL_T<A>: iter::BaseIter<A> {
10-
pure fn each(blk: fn(v: &A) -> bool) { EACH(self, blk) }
11-
pure fn size_hint() -> Option<uint> { SIZE_HINT(self) }
12+
pure fn each(blk: fn(v: &A) -> bool) { EACH(&self, blk) }
13+
pure fn size_hint() -> Option<uint> { SIZE_HINT(&self) }
1214
}
1315

1416
impl<A> IMPL_T<A>: iter::ExtendedIter<A> {
15-
pure fn eachi(blk: fn(uint, v: &A) -> bool) { iter::eachi(self, blk) }
17+
pure fn eachi(blk: fn(uint, v: &A) -> bool) { iter::eachi(&self, blk) }
1618
pure fn all(blk: fn(A) -> bool) -> bool { iter::all(self, blk) }
1719
pure fn any(blk: fn(A) -> bool) -> bool { iter::any(self, blk) }
1820
pure fn foldl<B>(+b0: B, blk: fn(B, A) -> B) -> B {
@@ -24,8 +26,8 @@ impl<A> IMPL_T<A>: iter::ExtendedIter<A> {
2426
}
2527

2628
impl<A: Eq> IMPL_T<A>: iter::EqIter<A> {
27-
pure fn contains(x: A) -> bool { iter::contains(self, x) }
28-
pure fn count(x: A) -> uint { iter::count(self, x) }
29+
pure fn contains(x: &A) -> bool { iter::contains(self, x) }
30+
pure fn count(x: &A) -> uint { iter::count(self, x) }
2931
}
3032

3133
impl<A: Copy> IMPL_T<A>: iter::CopyableIter<A> {

src/libcore/iter-trait/dlist.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type IMPL_T<A> = dlist::DList<A>;
88
* e.g. breadth-first search with in-place enqueues), but removing the current
99
* node is forbidden.
1010
*/
11-
pure fn EACH<A>(self: IMPL_T<A>, f: fn(v: &A) -> bool) {
11+
pure fn EACH<A>(self: &IMPL_T<A>, f: fn(v: &A) -> bool) {
1212
let mut link = self.peek_n();
1313
while option::is_some(&link) {
1414
let nobe = option::get(&link);
@@ -29,6 +29,6 @@ pure fn EACH<A>(self: IMPL_T<A>, f: fn(v: &A) -> bool) {
2929
}
3030
}
3131

32-
pure fn SIZE_HINT<A>(self: IMPL_T<A>) -> Option<uint> {
32+
pure fn SIZE_HINT<A>(self: &IMPL_T<A>) -> Option<uint> {
3333
Some(self.len())
3434
}

src/libcore/iter-trait/dvec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ type IMPL_T<A> = dvec::DVec<A>;
66
*
77
* Attempts to access this dvec during iteration will fail.
88
*/
9-
pure fn EACH<A>(self: IMPL_T<A>, f: fn(v: &A) -> bool) {
9+
pure fn EACH<A>(self: &IMPL_T<A>, f: fn(v: &A) -> bool) {
1010
unsafe {
1111
do self.swap |v| {
1212
v.each(f);
@@ -15,6 +15,6 @@ pure fn EACH<A>(self: IMPL_T<A>, f: fn(v: &A) -> bool) {
1515
}
1616
}
1717

18-
pure fn SIZE_HINT<A>(self: IMPL_T<A>) -> Option<uint> {
18+
pure fn SIZE_HINT<A>(self: &IMPL_T<A>) -> Option<uint> {
1919
Some(self.len())
2020
}

src/libcore/iter-trait/option.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#[allow(non_camel_case_types)]
22
type IMPL_T<A> = Option<A>;
33

4-
pure fn EACH<A>(self: IMPL_T<A>, f: fn(v: &A) -> bool) {
5-
match self {
4+
pure fn EACH<A>(self: &IMPL_T<A>, f: fn(v: &A) -> bool) {
5+
match *self {
66
None => (),
77
Some(ref a) => { f(a); }
88
}
99
}
1010

11-
pure fn SIZE_HINT<A>(self: IMPL_T<A>) -> Option<uint> {
12-
match self {
13-
None => Some(0u),
14-
Some(_) => Some(1u)
11+
pure fn SIZE_HINT<A>(self: &IMPL_T<A>) -> Option<uint> {
12+
match *self {
13+
None => Some(0),
14+
Some(_) => Some(1)
1515
}
1616
}

src/libcore/iter.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ trait ExtendedIter<A> {
2323
}
2424

2525
trait EqIter<A:Eq> {
26-
pure fn contains(x: A) -> bool;
27-
pure fn count(x: A) -> uint;
26+
pure fn contains(x: &A) -> bool;
27+
pure fn count(x: &A) -> uint;
2828
}
2929

3030
trait Times {
@@ -66,11 +66,11 @@ trait Buildable<A> {
6666
builder: fn(push: pure fn(+v: A))) -> self;
6767
}
6868

69-
pure fn eachi<A,IA:BaseIter<A>>(self: IA, blk: fn(uint, v: &A) -> bool) {
70-
let mut i = 0u;
69+
pure fn eachi<A,IA:BaseIter<A>>(self: &IA, blk: fn(uint, v: &A) -> bool) {
70+
let mut i = 0;
7171
for self.each |a| {
7272
if !blk(i, a) { break; }
73-
i += 1u;
73+
i += 1;
7474
}
7575
}
7676

@@ -130,17 +130,17 @@ pure fn to_vec<A:Copy,IA:BaseIter<A>>(self: IA) -> ~[A] {
130130
foldl::<A,~[A],IA>(self, ~[], |r, a| vec::append(copy r, ~[a]))
131131
}
132132

133-
pure fn contains<A:Eq,IA:BaseIter<A>>(self: IA, x: A) -> bool {
133+
pure fn contains<A:Eq,IA:BaseIter<A>>(self: IA, x: &A) -> bool {
134134
for self.each |a| {
135-
if *a == x { return true; }
135+
if *a == *x { return true; }
136136
}
137137
return false;
138138
}
139139

140-
pure fn count<A:Eq,IA:BaseIter<A>>(self: IA, x: A) -> uint {
141-
do foldl(self, 0u) |count, value| {
142-
if value == x {
143-
count + 1u
140+
pure fn count<A:Eq,IA:BaseIter<A>>(self: IA, x: &A) -> uint {
141+
do foldl(self, 0) |count, value| {
142+
if value == *x {
143+
count + 1
144144
} else {
145145
count
146146
}

src/libcore/str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ fn unshift_char(s: &mut ~str, ch: char) {
377377
pure fn trim_left_chars(s: &str, chars_to_trim: &[char]) -> ~str {
378378
if chars_to_trim.is_empty() { return from_slice(s); }
379379

380-
match find(s, |c| !chars_to_trim.contains(c)) {
380+
match find(s, |c| !chars_to_trim.contains(&c)) {
381381
None => ~"",
382382
Some(first) => unsafe { raw::slice_bytes(s, first, s.len()) }
383383
}
@@ -395,7 +395,7 @@ pure fn trim_left_chars(s: &str, chars_to_trim: &[char]) -> ~str {
395395
pure fn trim_right_chars(s: &str, chars_to_trim: &[char]) -> ~str {
396396
if chars_to_trim.is_empty() { return str::from_slice(s); }
397397

398-
match rfind(s, |c| !chars_to_trim.contains(c)) {
398+
match rfind(s, |c| !chars_to_trim.contains(&c)) {
399399
None => ~"",
400400
Some(last) => {
401401
let {next, _} = char_range_at(s, last);

src/libcore/vec.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,7 +1873,7 @@ impl<A> &[A]: iter::BaseIter<A> {
18731873
}
18741874

18751875
impl<A> &[A]: iter::ExtendedIter<A> {
1876-
pure fn eachi(blk: fn(uint, v: &A) -> bool) { iter::eachi(self, blk) }
1876+
pure fn eachi(blk: fn(uint, v: &A) -> bool) { iter::eachi(&self, blk) }
18771877
pure fn all(blk: fn(A) -> bool) -> bool { iter::all(self, blk) }
18781878
pure fn any(blk: fn(A) -> bool) -> bool { iter::any(self, blk) }
18791879
pure fn foldl<B>(+b0: B, blk: fn(B, A) -> B) -> B {
@@ -1885,8 +1885,8 @@ impl<A> &[A]: iter::ExtendedIter<A> {
18851885
}
18861886

18871887
impl<A: Eq> &[A]: iter::EqIter<A> {
1888-
pure fn contains(x: A) -> bool { iter::contains(self, x) }
1889-
pure fn count(x: A) -> uint { iter::count(self, x) }
1888+
pure fn contains(x: &A) -> bool { iter::contains(self, x) }
1889+
pure fn count(x: &A) -> uint { iter::count(self, x) }
18901890
}
18911891

18921892
impl<A: Copy> &[A]: iter::CopyableIter<A> {

src/libstd/net_url.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ fn get_authority(rawurl: &str) ->
524524

525525
let host_is_end_plus_one: &fn() -> bool = || {
526526
end+1 == len
527-
&& !['?', '#', '/'].contains(rawurl[end] as char)
527+
&& !['?', '#', '/'].contains(&(rawurl[end] as char))
528528
};
529529

530530
// finish up

src/rustc/driver/rustc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ fn run_compiler(args: ~[~str], demitter: diagnostic::emitter) {
140140
141141
let lint_flags = vec::append(getopts::opt_strs(matches, ~"W"),
142142
getopts::opt_strs(matches, ~"warn"));
143-
if lint_flags.contains(~"help") {
143+
if lint_flags.contains(&~"help") {
144144
describe_warnings();
145145
return;
146146
}
147147
148-
if getopts::opt_strs(matches, ~"Z").contains(~"help") {
148+
if getopts::opt_strs(matches, ~"Z").contains(&~"help") {
149149
describe_debug_flags();
150150
return;
151151
}

src/rustc/middle/borrowck/check_loans.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl check_loan_ctxt {
204204
let did = ast_util::def_id_of_def(def);
205205
let is_fn_arg =
206206
did.crate == ast::local_crate &&
207-
(*self.fn_args).contains(did.node);
207+
(*self.fn_args).contains(&(did.node));
208208
if is_fn_arg { return; } // case (a) above
209209
}
210210
ast::expr_fn_block(*) | ast::expr_fn(*) |
@@ -251,7 +251,7 @@ impl check_loan_ctxt {
251251
let def = self.tcx().def_map.get(expr.id);
252252
let did = ast_util::def_id_of_def(def);
253253
did.crate == ast::local_crate &&
254-
(*self.fn_args).contains(did.node)
254+
(*self.fn_args).contains(&(did.node))
255255
}
256256
ast::expr_fn_block(*) | ast::expr_fn(*) => {
257257
self.is_stack_closure(expr.id)

src/rustc/middle/check_alt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ fn missing_ctor(tcx: ty::ctxt, m: matrix, left_ty: ty::t) -> Option<ctor> {
275275
let variants = ty::enum_variants(tcx, eid);
276276
if found.len() != (*variants).len() {
277277
for vec::each(*variants) |v| {
278-
if !found.contains(variant(v.id)) {
278+
if !found.contains(&(variant(v.id))) {
279279
return Some(variant(v.id));
280280
}
281281
}

src/rustc/middle/check_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ fn check_item_recursion(sess: session, ast_map: ast_map::map,
169169
visitor.visit_item(it, env, visitor);
170170

171171
fn visit_item(it: @item, &&env: env, v: visit::vt<env>) {
172-
if (*env.idstack).contains(it.id) {
172+
if (*env.idstack).contains(&(it.id)) {
173173
env.sess.span_fatal(env.root_it.span, ~"recursive constant");
174174
}
175175
(*env.idstack).push(it.id);

src/rustc/middle/kind.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,13 @@ fn check_fn(fk: visit::fn_kind, decl: fn_decl, body: blk, sp: span,
199199
let id = ast_util::def_id_of_def(fv.def).node;
200200

201201
// skip over free variables that appear in the cap clause
202-
if captured_vars.contains(id) { loop; }
202+
if captured_vars.contains(&id) { loop; }
203203

204204
// if this is the last use of the variable, then it will be
205205
// a move and not a copy
206206
let is_move = {
207207
match cx.last_use_map.find(fn_id) {
208-
Some(vars) => (*vars).contains(id),
208+
Some(vars) => (*vars).contains(&id),
209209
None => false
210210
}
211211
};
@@ -588,7 +588,7 @@ fn check_cast_for_escaping_regions(
588588
do ty::walk_ty(source_ty) |ty| {
589589
match ty::get(ty).sty {
590590
ty::ty_param(source_param) => {
591-
if target_params.contains(source_param) {
591+
if target_params.contains(&source_param) {
592592
/* case (2) */
593593
} else {
594594
check_owned(cx.tcx, ty, source.span); /* case (3) */

src/rustc/middle/privacy.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) {
5656
if method.vis == private &&
5757
(impl_id.crate != local_crate ||
5858
!privileged_items
59-
.contains(impl_id.node)) {
59+
.contains(&(impl_id.node))) {
6060
tcx.sess.span_err(span,
6161
fmt!("method `%s` is \
6262
private",
@@ -95,9 +95,9 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) {
9595
}
9696
match methods[method_num] {
9797
provided(method)
98-
if method.vis == private &&
99-
!privileged_items
100-
.contains(trait_id.node) => {
98+
if method.vis == private &&
99+
!privileged_items
100+
.contains(&(trait_id.node)) => {
101101
tcx.sess.span_err(span,
102102
fmt!("method
103103
`%s` \
@@ -157,7 +157,7 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) {
157157
match ty::get(ty::expr_ty(tcx, base)).sty {
158158
ty_class(id, _)
159159
if id.crate != local_crate ||
160-
!privileged_items.contains(id.node) => {
160+
!privileged_items.contains(&(id.node)) => {
161161
match method_map.find(expr.id) {
162162
None => {
163163
debug!("(privacy checking) checking \
@@ -178,7 +178,7 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) {
178178
match ty::get(ty::expr_ty(tcx, expr)).sty {
179179
ty_class(id, _) => {
180180
if id.crate != local_crate ||
181-
!privileged_items.contains(id.node) {
181+
!privileged_items.contains(&(id.node)) {
182182
for fields.each |field| {
183183
debug!("(privacy checking) checking \
184184
field in struct literal");
@@ -205,7 +205,7 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) {
205205
match ty::get(ty::pat_ty(tcx, pattern)).sty {
206206
ty_class(id, _) => {
207207
if id.crate != local_crate ||
208-
!privileged_items.contains(id.node) {
208+
!privileged_items.contains(&(id.node)) {
209209
for fields.each |field| {
210210
debug!("(privacy checking) checking \
211211
struct pattern");

src/rustc/middle/region.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ impl determine_rp_ctxt {
485485
}
486486
};
487487
let dep = {ambient_variance: self.ambient_variance, id: self.item_id};
488-
if !vec.contains(dep) { vec.push(dep); }
488+
if !vec.contains(&dep) { vec.push(dep); }
489489
}
490490

491491
// Determines whether a reference to a region that appears in the

src/rustc/middle/trans/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ fn trans_local_var(bcx: block, ref_id: ast::node_id, def: ast::def) -> Datum {
813813
nid: ast::node_id) -> Datum {
814814
let is_last_use = match bcx.ccx().maps.last_use_map.find(ref_id) {
815815
None => false,
816-
Some(vars) => (*vars).contains(nid)
816+
Some(vars) => (*vars).contains(&nid)
817817
};
818818

819819
let source = if is_last_use {FromLastUseLvalue} else {FromLvalue};

src/rustc/middle/typeck/check/method.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl LookupContext {
182182
ty_enum(did, _) => {
183183
// Watch out for newtype'd enums like "enum t = @T".
184184
// See discussion in typeck::check::do_autoderef().
185-
if enum_dids.contains(did) {
185+
if enum_dids.contains(&did) {
186186
return None;
187187
}
188188
enum_dids.push(did);

src/rustdoc/rustdoc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use config::Config;
55

66
fn main(args: ~[~str]) {
77

8-
if args.contains(~"-h") || args.contains(~"--help") {
8+
if args.contains(&~"-h") || args.contains(&~"--help") {
99
config::usage();
1010
return;
1111
}

src/test/run-pass/early-vtbl-resolution.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn foo_func<A, B: thing<A>>(x: B) -> Option<A> { x.foo() }
99

1010
fn main() {
1111

12-
for iter::eachi(Some({a: 0})) |i, a| {
12+
for iter::eachi(&(Some({a: 0}))) |i, a| {
1313
#debug["%u %d", i, a.a];
1414
}
1515

src/test/run-pass/iter-contains.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
fn main() {
2-
assert []/_.contains(22u) == false;
3-
assert [1u, 3u]/_.contains(22u) == false;
4-
assert [22u, 1u, 3u]/_.contains(22u) == true;
5-
assert [1u, 22u, 3u]/_.contains(22u) == true;
6-
assert [1u, 3u, 22u]/_.contains(22u) == true;
7-
assert None.contains(22u) == false;
8-
assert Some(1u).contains(22u) == false;
9-
assert Some(22u).contains(22u) == true;
2+
assert []/_.contains(&22u) == false;
3+
assert [1u, 3u]/_.contains(&22u) == false;
4+
assert [22u, 1u, 3u]/_.contains(&22u) == true;
5+
assert [1u, 22u, 3u]/_.contains(&22u) == true;
6+
assert [1u, 3u, 22u]/_.contains(&22u) == true;
7+
assert None.contains(&22u) == false;
8+
assert Some(1u).contains(&22u) == false;
9+
assert Some(22u).contains(&22u) == true;
1010
}

src/test/run-pass/iter-count.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
fn main() {
2-
assert []/_.count(22u) == 0u;
3-
assert [1u, 3u]/_.count(22u) == 0u;
4-
assert [22u, 1u, 3u]/_.count(22u) == 1u;
5-
assert [22u, 1u, 22u]/_.count(22u) == 2u;
6-
assert None.count(22u) == 0u;
7-
assert Some(1u).count(22u) == 0u;
8-
assert Some(22u).count(22u) == 1u;
2+
assert []/_.count(&22u) == 0u;
3+
assert [1u, 3u]/_.count(&22u) == 0u;
4+
assert [22u, 1u, 3u]/_.count(&22u) == 1u;
5+
assert [22u, 1u, 22u]/_.count(&22u) == 2u;
6+
assert None.count(&22u) == 0u;
7+
assert Some(1u).count(&22u) == 0u;
8+
assert Some(22u).count(&22u) == 1u;
99
}

0 commit comments

Comments
 (0)