@@ -305,6 +305,10 @@ fn iter_wrapper(zelf: PyObjectRef, vm: &VirtualMachine) -> PyResult {
305305 vm. call_special_method ( & zelf, identifier ! ( vm, __iter__) , ( ) )
306306}
307307
308+ fn self_iter ( zelf : PyObjectRef , _vm : & VirtualMachine ) -> PyResult {
309+ Ok ( zelf)
310+ }
311+
308312fn iternext_wrapper ( zelf : & PyObject , vm : & VirtualMachine ) -> PyResult < PyIterReturn > {
309313 PyIterReturn :: from_pyresult (
310314 vm. call_special_method ( zelf, identifier ! ( vm, __next__) , ( ) ) ,
@@ -1238,6 +1242,8 @@ pub trait Iterable: PyPayload {
12381242 }
12391243
12401244 fn iter ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> PyResult ;
1245+
1246+ fn extend_slots ( _slots : & mut PyTypeSlots ) { }
12411247}
12421248
12431249// `Iterator` fits better, but to avoid confusion with rust std::iter::Iterator
@@ -1266,13 +1272,18 @@ impl<T> Iterable for T
12661272where
12671273 T : IterNextIterable ,
12681274{
1269- #[ inline ]
1270- fn slot_iter ( zelf : PyObjectRef , _vm : & VirtualMachine ) -> PyResult {
1271- Ok ( zelf )
1275+ #[ cold ]
1276+ fn slot_iter ( _zelf : PyObjectRef , _vm : & VirtualMachine ) -> PyResult {
1277+ unreachable ! ( "slot is overriden" ) ;
12721278 }
12731279
12741280 #[ cold]
12751281 fn iter ( _zelf : PyRef < Self > , _vm : & VirtualMachine ) -> PyResult {
12761282 unreachable ! ( "slot_iter is implemented" ) ;
12771283 }
1284+
1285+ fn extend_slots ( slots : & mut PyTypeSlots ) {
1286+ let prev = slots. iter . swap ( Some ( self_iter) ) ;
1287+ debug_assert ! ( prev. is_some( ) ) ; // slot_iter would be set
1288+ }
12781289}
0 commit comments