Uh oh!
There was an error while loading. Please reload this page.
DSTify PartialEq, PartialOrd, Eq, Ord - #18467
Conversation
huonw
commented
Oct 30, 2014
Deriving can be fixed when UFCS allows for |
alexcrichton
commented
Oct 30, 2014
@japaric stage0 looks good to me, thanks! If you're feeling up to the task, you may be able to kill two birds with one stone by tweaking how deriving works. Right now We could in theory expand to: impl::std::cmp::PartialEqforFoo{#[inline]fneq(&self,__arg_0:&Foo) -> ::bool{fneq<Sized? T:PartialEq>(a:&T,b:&T){ a.eq(b)}// add this functionmatch*__arg_0 {Foo(ref __self_1_0) =>
match*self{Foo(ref __self_0_0) =>
true && eq(__self_0_0, __self_1_0),// modify function call here},}}// ne method omitted for brevity}That should in theory solve the problem in this PR, as well as the problem for structures with pointers! |
alexcrichton
commented
Oct 30, 2014
Ah and it seems @huonw was thinking what I was as well :) (and it doesn't even introduce a mini function) |
japaric
commented
Oct 30, 2014
Hmm, so I tried the script on #15689, and it actually works with this PR. The expansion looks like this: impl<'a>::std::cmp::PartialEqforTest<'a>{#[inline]fneq(&self,__arg_0:&Test<'a>) -> ::bool{match(&*self,&*__arg_0){(&Slice(ref __self_0),&Slice(ref __arg_1_0)) =>
true && (*__self_0) == (*__arg_1_0),}}// ne omitted} |
aturon
commented
Oct 31, 2014
@nikomatsakis is currently doing some major work on operator overloading. Can we hold off on DST-ifying operators until that's done? Sorry for the delay @japaric. |
aturon
commented
Oct 31, 2014
(I should say: his branch is bootstrapping, and I expect it to land soon.) |
japaric
commented
Oct 31, 2014
@nikomatsakis I tried this branch rebased on top of your operator dispatch PR with and without your Re: It seems that in your patch only coerces the LHS to [T], but leaves the RHS as [T, ..2] which causes the error shown in the gist. I think we should coerce [T, ..N] -> [T] on both sides of A op B. |
nikomatsakis
commented
Nov 3, 2014
@japaric yes over the weekend I realize that the patch was of course not enough to make the RHS coerce. I'm revising my opinion on whether I think this coercion is worthwhile or not. |
japaric
commented
Nov 3, 2014
@nikomatsakis Alright, let's go ahead with the original plan then. I'll leave this ready to be merged after your operator dispatch PR. And, we can do the coercion part (if we decide to do it) in another PR. |
nikomatsakis
commented
Nov 3, 2014
@japaric Sounds good. I'm not sure what the original plan is, actually -- rewrite in terms of Regardless, it does seem best to add the |
japaric
commented
Nov 3, 2014
No, this just needs a rebase + checking that all tests pass. Expanding to the operator sugar works fine, it also partially fixes (the
Ahh, I didn't realize that would happen. I agree, that operation should be a type error. Perhaps, we shouldn't do the coercion, since it's just a workaround until we allow integers as generic parameters, and the impls for up to |
japaric
commented
Nov 3, 2014
😢 Some run-pass tests are running into SIGILL (I have compiled the details here). I have no idea what could be happening. I'll ask on IRC later. |
alexcrichton
commented
Nov 3, 2014
@japaric have you tried getting a backtrace in gdb when you hit the |
japaric
commented
Nov 3, 2014
@alexcrichton Yeah, the problem was infinite recursion. I couldn't pinpoint the source, but it was one of the method definitions that used the method notation in its definition, like this one: impl<'a,T:Ord>Ordfor&'aT{#[inline]fncmp(&self,other:&&'aT) -> Ordering{(**self).cmp(*other)}}I have changed all these to use UCFS syntax (which looks more readable IMO): impl<'a,T:Ord>Ordfor&'aT{#[inline]fncmp(&self,other:&&'aT) -> Ordering{Ord::cmp(*self,*other)}}And now the infinite recursion problem is gone. OK. This is ready for review, all tests pass locally. This PR is rebased on top of #18486, so you can skip @nikomatsakis commits. (This also needs #18523, or it'll ICE during re-r? @aturon |
alexcrichton
commented
Nov 5, 2014
ping @japaric, needs a rebase? |
aturon
commented
Nov 5, 2014
@japaric@alexcrichton I've reviewed the library changes, and they all look good to me. @alexcrichton Can you review the changes to deriving and make sure you're happy with them? Feel free to r+ if/when so. |
alexcrichton
commented
Nov 5, 2014
Seems good to me! |
japaric
commented
Nov 5, 2014
@alexcrichton Rebased. (I can squash afterwards) |
alexcrichton
commented
Nov 5, 2014
we're gonna have to make a snapshot real soon after this! |
japaric
commented
Nov 6, 2014
Had to rebase after #18486 landed. (I also squashed the commits) re-r? @alexcrichton |
`eq`, `ne`, `cmp`, etc methods now require one less level of indirection when dealing with `&str`/`&[T]`
``` rust
"foo".ne(&"bar") -> "foo".ne("bar")
slice.cmp(&another_slice) -> slice.cmp(another_slice)
// slice and another_slice have type `&[T]`
```
[breaking-change]
eq,ne,cmp, etc methods now require one less level of indirection when dealing with&str/&[T][breaking-change]