rustc: Make vtable do duplicate-impl checking. Closes #2958.
This commit is contained in:
parent
3119afc6e8
commit
f48dcaaae3
1 changed files with 12 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
||||||
import check::{fn_ctxt, impl_self_ty, methods};
|
import check::{fn_ctxt, impl_self_ty, methods};
|
||||||
import infer::{resolve_type, resolve_all, force_all, fixup_err_to_str};
|
import infer::{resolve_type, resolve_all, force_all, fixup_err_to_str};
|
||||||
|
import ast_util::new_def_hash;
|
||||||
|
|
||||||
fn has_trait_bounds(tps: ~[ty::param_bounds]) -> bool {
|
fn has_trait_bounds(tps: ~[ty::param_bounds]) -> bool {
|
||||||
vec::any(tps, |bs| {
|
vec::any(tps, |bs| {
|
||||||
|
@ -49,6 +50,8 @@ fn relate_trait_tys(fcx: @fn_ctxt, sp: span,
|
||||||
/*
|
/*
|
||||||
Look up the vtable to use when treating an item of type <t>
|
Look up the vtable to use when treating an item of type <t>
|
||||||
as if it has type <trait_ty>
|
as if it has type <trait_ty>
|
||||||
|
|
||||||
|
XXX: This doesn't use the coherence tables yet.
|
||||||
*/
|
*/
|
||||||
fn lookup_vtable(fcx: @fn_ctxt, isc: resolve::iscopes, sp: span,
|
fn lookup_vtable(fcx: @fn_ctxt, isc: resolve::iscopes, sp: span,
|
||||||
ty: ty::t, trait_ty: ty::t, allow_unsafe: bool)
|
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,
|
||||||
_ {
|
_ {
|
||||||
let mut found = ~[];
|
let mut found = ~[];
|
||||||
|
|
||||||
|
let mut impls_seen = new_def_hash();
|
||||||
|
|
||||||
for list::each(isc) |impls| {
|
for list::each(isc) |impls| {
|
||||||
/* For each impl in scope... */
|
/* For each impl in scope... */
|
||||||
for vec::each(*impls) |im| {
|
for vec::each(*impls) |im| {
|
||||||
// im = one specific impl
|
// im = one specific impl
|
||||||
|
|
||||||
|
// First, ensure that we haven't processed this impl yet.
|
||||||
|
if impls_seen.contains_key(im.did) {
|
||||||
|
again;
|
||||||
|
}
|
||||||
|
impls_seen.insert(im.did, ());
|
||||||
|
|
||||||
// find the trait that im implements (if any)
|
// find the trait that im implements (if any)
|
||||||
for vec::each(ty::impl_traits(tcx, im.did)) |of_ty| {
|
for vec::each(ty::impl_traits(tcx, im.did)) |of_ty| {
|
||||||
// it must have the same id as the expected one
|
// it must have the same id as the expected one
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue