@@ -8152,34 +8152,47 @@ fn create_vtbl(@local_ctxt cx, &span sp, TypeRef llself_ty, ty::t self_ty,
8152
8152
}
8153
8153
}
8154
8154
8155
- // Now, filter out any methods that are being replaced.
8156
- fn filtering_fn( & vtbl_mthd m, vec[ vtbl_mthd] addtl_meths) ->
8157
- option:: t[ vtbl_mthd] {
8158
-
8159
- let option:: t[ vtbl_mthd] rslt;
8160
- if ( std:: vec:: member[ vtbl_mthd] ( m, addtl_meths) ) {
8161
- rslt = none;
8162
- } else {
8163
- rslt = some( m) ;
8155
+ // Now, filter out any methods that we don't need forwarding slots
8156
+ // for, because they're being replaced.
8157
+ fn filtering_fn( @local_ctxt cx, & vtbl_mthd m,
8158
+ ( @ast:: method) [ ] addtl_meths)
8159
+ -> option:: t[ vtbl_mthd] {
8160
+
8161
+ alt ( m) {
8162
+ case ( fwding_mthd( ?fm) ) {
8163
+ // Since fm is a fwding_mthd, and we're checking to
8164
+ // see if it's in addtl_meths (which only contains
8165
+ // normal_mthds), we can't just check if fm is a
8166
+ // member of addtl_meths. Instead, we have to go
8167
+ // through addtl_meths and see if there's some method
8168
+ // in it that has the same name as fm.
8169
+
8170
+ // FIXME (part of #543): We're only checking names
8171
+ // here. If a method is replacing another, it also
8172
+ // needs to have the same type, but this should
8173
+ // probably be enforced in typechecking.
8174
+ for ( @ast:: method am in addtl_meths) {
8175
+ if ( str :: eq( am. node. ident, fm. ident) ) {
8176
+ ret none;
8177
+ }
8178
+ }
8179
+ ret some( fwding_mthd( fm) ) ;
8180
+ }
8181
+ case ( normal_mthd( _) ) {
8182
+ // Should never happen.
8183
+ cx. ccx. sess. bug( "create_vtbl( ) : shouldn' t be any"
8184
+ + " normal_mthds in meths here") ;
8185
+ }
8164
8186
}
8165
- ret rslt;
8166
8187
}
8167
-
8168
- // NB: addtl_meths is just like ob.methods except that it's of
8169
- // type vec[vtbl_mthd], not vec[@ast::method].
8170
- let vec[ vtbl_mthd] addtl_meths = [ ] ;
8171
- for ( @ast:: method m in ob. methods) {
8172
- addtl_meths += [ normal_mthd( m) ] ;
8173
- }
8174
- auto f = bind filtering_fn( _, addtl_meths) ;
8175
-
8176
- // Filter out any methods that we don't need forwarding slots for
8177
- // (namely, those that are being replaced).
8188
+ auto f = bind filtering_fn( cx, _, ob. methods) ;
8178
8189
meths = std:: vec:: filter_map[ vtbl_mthd, vtbl_mthd] ( f, meths) ;
8179
8190
8180
8191
// And now add the additional ones (both replacements and entirely
8181
- // new ones).
8182
- meths += addtl_meths;
8192
+ // new ones). These'll just be normal methods.
8193
+ for ( @ast:: method m in ob. methods) {
8194
+ meths += [ normal_mthd( m) ] ;
8195
+ }
8183
8196
}
8184
8197
}
8185
8198
0 commit comments