You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
not sure I can make a lot of sense out of this one. basically, moving around the usage of our Weird type causes a failure in the type resolver. I'm having a hard time reducing the testcase further so any help is appreciated.
#![feature(intrinsics)]#![feature(lang_items)]#[lang = "sized"]traitSized{}extern"rust-intrinsic"{fntransmute<T,U>(_:T) -> U;fnoffset<T>(src:*constT,offset:isize) -> *constT;}pubmod core {pubmod marker {#[lang = "phantom_data"]pubstructPhantomData<T>;}pubmod slice {use core::marker::PhantomData;use core::option::Option;impl<T> core::iter::IntoIteratorfor&[T]{typeItem = &T;typeIntoIter = Weird<T>;fninto_iter(self) -> Weird<T>{self.iter()}}pubstructWeird<T>{ptr:*constT,// should be NonNull<T> but here it does not matterend:*constT,_marker:PhantomData<&T>,}impl<T>Weird<T>{pub(super)fnnew(slice:&[T]) -> Self{let ptr = slice.as_ptr();// SAFETY: Similar to `IterMut::new`.unsafe{// should be: ptr.add(slice.len())let end = transmute::<*constT,usize>(ptr) + slice.len();// TODO(Arthur): Missing `* size_of::<T>()`?let end = transmute::<usize,*constT>(end);Self{
ptr,
end,_marker:PhantomData,}}}fnis_empty(&self) -> bool{self.ptr == self.end}fnnext_unchecked(&mutself) -> *constT{let old = self.ptr;self.ptr = unsafe{offset(self.ptr,1)};
old
}}traitFoo{}impl<T>FooforWeird<T>{}// impl<T> core::iter::Iterator for Iter<T> {// type Item = &T;// fn next(&mut self) -> Option<&T> {// if self.is_empty() {// Option::None// } else {// Option::Some(&*self.next_unchecked())// }// }// }unionRepr<T>{pub(crate)rust:*const[T],rust_mut:*mut[T],pub(crate)raw:FatPtr<T>,}structFatPtr<T>{data:*constT,pub(crate)len:usize,}impl<T>[T]{pubfniter(&self) -> Weird<T>{Weird::new(self)}pubfnas_ptr(&self) -> *constT{selfas*const[T]as*constT}pubfnlen(&self) -> usize{unsafe{Repr{rust:self}.raw.len}}}}pubmod iter {use option::Option;pubtraitIntoIterator{typeItem;typeIntoIter:Iterator<Item = Self::Item>;fninto_iter(self) -> Self::IntoIter;}pubtraitIterator{typeItem;fnnext(&mutself) -> Option<Self::Item>;}}pubmod option {pubenumOption<T>{Some(T),None,}}}fnmain(){}
causes the following errors:
root-seg.rs:69:25: error: failed to resolve root segment:Weird<T>
69 | impl<T> Foo for Weird<T> {}
| ^~~~~
root-seg.rs:69:17: error: failed to resolve type arguments
69 | impl<T> Foo for Weird<T> {}
| ^~~
but moving the definition of Weirdabove the implementation of IntoIterator for &[T] results in a successful compilation:
#![feature(intrinsics)]#![feature(lang_items)]#[lang = "sized"]traitSized{}extern"rust-intrinsic"{fntransmute<T,U>(_:T) -> U;fnoffset<T>(src:*constT,offset:isize) -> *constT;}pubmod core {pubmod marker {#[lang = "phantom_data"]pubstructPhantomData<T>;}pubmod slice {use core::marker::PhantomData;use core::option::Option;pubstructWeird<T>{ptr:*constT,// should be NonNull<T> but here it does not matterend:*constT,_marker:PhantomData<&T>,}impl<T> core::iter::IntoIteratorfor&[T]{typeItem = &T;typeIntoIter = Weird<T>;fninto_iter(self) -> Weird<T>{self.iter()}}impl<T>Weird<T>{pub(super)fnnew(slice:&[T]) -> Self{let ptr = slice.as_ptr();// SAFETY: Similar to `IterMut::new`.unsafe{// should be: ptr.add(slice.len())let end = transmute::<*constT,usize>(ptr) + slice.len();// TODO(Arthur): Missing `* size_of::<T>()`?let end = transmute::<usize,*constT>(end);Self{
ptr,
end,_marker:PhantomData,}}}fnis_empty(&self) -> bool{self.ptr == self.end}fnnext_unchecked(&mutself) -> *constT{let old = self.ptr;self.ptr = unsafe{offset(self.ptr,1)};
old
}}traitFoo{}impl<T>FooforWeird<T>{}// impl<T> core::iter::Iterator for Iter<T> {// type Item = &T;// fn next(&mut self) -> Option<&T> {// if self.is_empty() {// Option::None// } else {// Option::Some(&*self.next_unchecked())// }// }// }unionRepr<T>{pub(crate)rust:*const[T],rust_mut:*mut[T],pub(crate)raw:FatPtr<T>,}structFatPtr<T>{data:*constT,pub(crate)len:usize,}impl<T>[T]{pubfniter(&self) -> Weird<T>{Weird::new(self)}pubfnas_ptr(&self) -> *constT{selfas*const[T]as*constT}pubfnlen(&self) -> usize{unsafe{Repr{rust:self}.raw.len}}}}pubmod iter {use option::Option;pubtraitIntoIterator{typeItem;typeIntoIter:Iterator<Item = Self::Item>;fninto_iter(self) -> Self::IntoIter;}pubtraitIterator{typeItem;fnnext(&mutself) -> Option<Self::Item>;}}pubmod option {pubenumOption<T>{Some(T),None,}}}fnmain(){}
arthur@platypus ~/G/r/gccrs (desugar-for-loops) [1]> diff root-seg.rs root-seg-broken.rs
22,27d21< pub struct Weird<T> {< ptr: *const T, // should be NonNull<T> but here it does not matter< end: *const T,< _marker: PhantomData<&T>,< }<34a29,34> }>> pub struct Weird<T> {> ptr: *const T, // should be NonNull<T> but here it does not matter> end: *const T,> _marker: PhantomData<&T>,
The text was updated successfully, but these errors were encountered:
not sure I can make a lot of sense out of this one. basically, moving around the usage of our
Weird
type causes a failure in the type resolver. I'm having a hard time reducing the testcase further so any help is appreciated.causes the following errors:
but moving the definition of
Weird
above the implementation ofIntoIterator
for&[T]
results in a successful compilation:The text was updated successfully, but these errors were encountered: