Skip to content

Commit a3be0b1

Browse files
committed
fix classes and parameterized ifaces; remove needless self check
ref #1726, #2434
1 parent bd573be commit a3be0b1

File tree

7 files changed

+39
-78
lines changed

7 files changed

+39
-78
lines changed

src/rustc/driver/driver.rs

-2
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,6 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
192192
bind middle::check_loop::check_crate(ty_cx, crate));
193193
time(time_passes, "alt checking",
194194
bind middle::check_alt::check_crate(ty_cx, crate));
195-
time(time_passes, "self checking",
196-
bind middle::check_self::check_crate(ty_cx, crate));
197195
time(time_passes, "typestate checking",
198196
bind middle::tstate::ck::check_crate(ty_cx, crate));
199197
let (root_map, mutbl_map) = time(

src/rustc/middle/check_self.rs

-60
This file was deleted.

src/rustc/middle/typeck/collect.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,7 @@ fn convert(ccx: @crate_ctxt, it: @ast::item) {
359359
// Write the class type
360360
let tpt = ty_of_item(ccx, it);
361361
write_ty_to_tcx(tcx, it.id, tpt.ty);
362-
tcx.tcache.insert(local_def(it.id), {bounds: tpt.bounds,
363-
rp: rp, ty: tpt.ty});
362+
tcx.tcache.insert(local_def(it.id), tpt);
364363
// Write the ctor type
365364
let t_ctor =
366365
ty::mk_fn(
@@ -416,13 +415,17 @@ fn convert(ccx: @crate_ctxt, it: @ast::item) {
416415
for ifaces.each { |ifce|
417416
check_methods_against_iface(ccx, tps, rp, selfty,
418417
ifce, methods);
419-
let t = ty::node_id_to_type(tcx, ifce.id);
420418

421-
// FIXME: This assumes classes only implement
422-
// non-parameterized ifaces. add a test case for
423-
// a class implementing a parameterized iface.
424-
// -- tjc (#1726)
425-
tcx.tcache.insert(local_def(ifce.id), no_params(t));
419+
// FIXME #2434---this is somewhat bogus, but it seems that
420+
// the id of iface_ref is also the id of the impl, and so
421+
// we want to store the "self type" of the impl---in this
422+
// case, the class. The reason I say this is somewhat
423+
// bogus (and should be refactored) is that the tcache
424+
// stores the class type for ifce.id but the node_type
425+
// table stores the iface type. Weird. Probably just
426+
// adding a "self type" table rather than overloading the
427+
// tcache would be ok, or else adding more than one id.
428+
tcx.tcache.insert(local_def(ifce.id), tpt);
426429
}
427430
}
428431
_ {

src/rustc/rustc.rc

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ mod middle {
6868
mod check_loop;
6969
mod check_alt;
7070
mod check_const;
71-
mod check_self;
7271
mod lint;
7372
mod borrowck;
7473
mod alias;

src/test/compile-fail/issue-2294.rs

-6
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use std;
2+
import std::map::{map, hashmap, int_hash};
3+
4+
class keys<K: copy, V: copy, M: copy map<K,V>>
5+
implements iter::base_iter<K> {
6+
7+
let map: M;
8+
9+
new(map: M) {
10+
self.map = map;
11+
}
12+
13+
fn each(blk: fn(K) -> bool) { self.map.each { |k, _v| blk(k)} }
14+
fn size_hint() -> option<uint> { some(self.map.size()) }
15+
fn eachi(blk: fn(uint, K) -> bool) { iter::eachi(self, blk) }
16+
}
17+
18+
fn main() {
19+
let m = int_hash();
20+
m.insert(1, 2);
21+
m.insert(3, 4);
22+
assert iter::to_vec(keys(m)) == [1, 3];
23+
}

src/test/run-pass/class-implement-ifaces.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ class cat implements noisy {
3535
}
3636
}
3737

38+
fn make_speak<C: noisy>(c: C) {
39+
c.speak();
40+
}
41+
3842
fn main() {
3943
let nyan = cat(0u, 2, "nyan");
4044
nyan.eat();
4145
assert(!nyan.eat());
42-
uint::range(1u, 10u, {|_i| nyan.speak(); });
46+
uint::range(1u, 10u, {|_i| make_speak(nyan); });
4347
assert(nyan.eat());
4448
}

0 commit comments

Comments
 (0)