Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upImprove method lookup auto-deref behavior (subissue of trait reform) #12825
Comments
This comment has been minimized.
This comment has been minimized.
|
cc me |
alexcrichton
referenced this issue
Mar 22, 2014
Closed
Autoderef requests a mutable slot when it shouldn't #13066
This comment has been minimized.
This comment has been minimized.
|
Another test case: use std::cell::RefCell;
fn main() {
let a = RefCell::new((1i, 2i));
match *a.borrow_mut() {
(ref mut a, ref mut b) => { *a += *b; *b += *a; }
}
}This fail to compile, but if it's changed to |
This comment has been minimized.
This comment has been minimized.
|
I've been working, by the way, on a prototype of a new trait / method resolution algorithm that resolves issue (among many others). I hope to include it in a general RFC for #5527 very shortly. |
mbrubeck
referenced this issue
Apr 9, 2014
Closed
Implement Deref<T> and DerefMut<T> for JS<T> #2078
oblitum
referenced this issue
May 6, 2014
Closed
auto-borrow and consistent behavior of pointers #13988
This comment has been minimized.
This comment has been minimized.
|
Same issue with Index/IndexMut, ftr. |
This comment has been minimized.
This comment has been minimized.
|
Nominating, if this is going to block vec switching to |
alexcrichton
added
the
I-nominated
label
Jul 14, 2014
This comment has been minimized.
This comment has been minimized.
|
Assigning 1.0 milestone, P-backcompat-lang. |
pnkfelix
added
P-backcompat-lang
and removed
I-nominated
labels
Jul 17, 2014
pnkfelix
added this to the 1.0 milestone
Jul 17, 2014
This was referenced Jul 19, 2014
This comment has been minimized.
This comment has been minimized.
|
I'm going to go ahead and assign this to @nikomatsakis. |
pcwalton
assigned
nikomatsakis
Jul 24, 2014
huonw
referenced this issue
Jul 30, 2014
Closed
Implementing Deref and DerefMut for the same type makes it impossible to call &self methods through immutable refs of that type #16099
pcwalton
changed the title
Improve method lookup auto-deref behavior.
Improve method lookup auto-deref behavior (subissue of trait reform)
Sep 9, 2014
This comment has been minimized.
This comment has been minimized.
|
We need to change precedence so that inherent and trait impls are on equal footing instead of having inherent impls be first. |
pcwalton
added a commit
to pcwalton/rust
that referenced
this issue
Sep 24, 2014
pcwalton
added a commit
to pcwalton/rust
that referenced
this issue
Sep 24, 2014
pcwalton
referenced this issue
Sep 24, 2014
Merged
librustc: Fix up mutability in method autoderefs if incorrect, and #17501
pcwalton
added a commit
to pcwalton/rust
that referenced
this issue
Sep 26, 2014
pcwalton
added a commit
to pcwalton/rust
that referenced
this issue
Sep 27, 2014
pcwalton
added a commit
to pcwalton/rust
that referenced
this issue
Sep 30, 2014
pcwalton
added a commit
to pcwalton/rust
that referenced
this issue
Sep 30, 2014
pcwalton
added a commit
to pcwalton/rust
that referenced
this issue
Sep 30, 2014
bors
added a commit
that referenced
this issue
Oct 1, 2014
bors
added a commit
that referenced
this issue
Oct 1, 2014
bors
closed this
in
#17501
Oct 1, 2014
This comment has been minimized.
This comment has been minimized.
|
Is this really fixed? @alexcrichton’s example from above still fails to compile, and is incidentally very similar to the example in #15609, which also does not compile. |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
I've confirmed that @pcwalton, would you prefer me to re-open this issue or create a new one? |
This comment has been minimized.
This comment has been minimized.
|
Reopening. |
eddyb commentedMar 11, 2014
Previously to #12491, there were no real issues with the current method lookup implementation, which collects candidates and picks the first one in the auto-deref chain, without caring too much about mutability.
The problematic case #12491 introduces was
(*x).foo()where*xis an overloaded dereference, calling eitherDeref::dereforDerefMut::deref_mut.However, the method could take
&mut self- which we can't know until we've picked one ofdereforderef_mutand continued to the lookup of.foo.The choice I've made was to always try
deref_mut(if not obviously immutable, e.g. x having a type of&Tinstead of&mut TorT) first, and that will work forRefCell'sRefMut, which only had a mutable.get()method previously.In #12610 it gets worse as the issue can happen at any auto-deref level, and here's a test case that fails to compile:
cc @nikomatsakis