Skip to content

Commit f48dcaa

Browse files
committed
rustc: Make vtable do duplicate-impl checking. Closes #2958.
1 parent 3119afc commit f48dcaa

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import check::{fn_ctxt, impl_self_ty, methods};
22
import infer::{resolve_type, resolve_all, force_all, fixup_err_to_str};
3+
import ast_util::new_def_hash;
34

45
fn has_trait_bounds(tps: ~[ty::param_bounds]) -> bool {
56
vec::any(tps, |bs| {
@@ -49,6 +50,8 @@ fn relate_trait_tys(fcx: @fn_ctxt, sp: span,
4950
/*
5051
Look up the vtable to use when treating an item of type <t>
5152
as if it has type <trait_ty>
53+
54+
XXX: This doesn't use the coherence tables yet.
5255
*/
5356
fn lookup_vtable(fcx: @fn_ctxt, isc: resolve::iscopes, sp: span,
5457
ty: ty::t, trait_ty: ty::t, allow_unsafe: bool)
@@ -114,10 +117,19 @@ fn lookup_vtable(fcx: @fn_ctxt, isc: resolve::iscopes, sp: span,
114117
_ {
115118
let mut found = ~[];
116119

120+
let mut impls_seen = new_def_hash();
121+
117122
for list::each(isc) |impls| {
118123
/* For each impl in scope... */
119124
for vec::each(*impls) |im| {
120125
// im = one specific impl
126+
127+
// First, ensure that we haven't processed this impl yet.
128+
if impls_seen.contains_key(im.did) {
129+
again;
130+
}
131+
impls_seen.insert(im.did, ());
132+
121133
// find the trait that im implements (if any)
122134
for vec::each(ty::impl_traits(tcx, im.did)) |of_ty| {
123135
// it must have the same id as the expected one

0 commit comments

Comments
 (0)