Uh oh!
There was an error while loading. Please reload this page.
Implement automatic overloaded deref. - #12610
Conversation
alexcrichton
commented
Feb 28, 2014
There's a few travis failures you may be interested in, and I would like to see more description added before merging. |
There was a problem hiding this comment.
Does this mean the &1 + 2 bug is fixed?
(If so, needstest)
There was a problem hiding this comment.
I've only changed x OP y with x &T instead of T where T is a generic type param with the operator overload in its trait bounds, and it wasn't to fix that bug, but prevent nasty recursion in autoderef.
I guess I should fiddle with the lookup code some more to deny more forms, as this is likely to also affect autoderef.
eddyb
commented
Feb 28, 2014
@brson this means I need some kind of writeup... We currently do "autoderef" for expressions like This PR enables the deref overloads introduced by #12491 to be applied in those contexts, allowing one to write |
nikomatsakis
commented
Feb 28, 2014
cc me, I will review |
nikomatsakis
commented
Mar 7, 2014
@eddyb I tried to open a PR with my nits / refactorings / comments that I wrote as I went through, but I was not able to base it against your branch (github didn't give me that option for some reason). Here is a patch: https://gist.github.com/nikomatsakis/9414596 |
nikomatsakis
commented
Mar 7, 2014
Oh, I just thought of a wrinkle while writing out the set of tests. The current field rules autoderef if the outer type does not define the field. But what if the field is private? This seems bad. We have to figure out the right rules for this! |
nikomatsakis
commented
Mar 7, 2014
As I wrote on IRC, we're going to need more tests. At minimum, I would like to see basically the same suite of tests that are present for explicit deref, but with autoderef instead. But autoderef opens up some new fun so it'd also be good to have tests like:
Also, there is some discussion amongst the group about what the right semantics are in the face of method resolution ambiguity (ie, if both |
bill-myers
commented
Mar 9, 2014
This is probably already obvious, but if a private field is reached first, and there is a public field later, it would be a bug to return the private field, since that effectively makes the private field name visible in the API. |
nikomatsakis
commented
Mar 9, 2014
Based on discussion with the group, current plan is to ignore private fields that are not visible during autoderef. But if the autoderef never finds a public field, I'd like to report an error to the effect that the field |
…e borrow mutably twice in a row
Enables the dereference overloads introduced by #12491 to be applied wherever automatic dereferences would be used (field accesses, method calls and indexing).
oblitum
commented
Mar 13, 2014
is this matter for another PR or is it not desired? use std::rc::Rc;structBar{x:int}fnfoo(p:&int){println!("{}", p);}fnbaz(p:&Bar){println!("{}", p.x);}fnmain(){let pi = box 10;let pb = Rc::new(Bar{x:3});foo(pi);// this still doesn't auto borrow://baz(pb);// although this works:println!("{}", pb.x);} |
eddyb
commented
Mar 14, 2014
@oblitum That should be discussed. It's part of the larger auto-ref issue (calling a function taking |
…-12564, r=dswij [`manual_unwrap_or_default`]: Check for Default trait implementation in initial condition when linting and use `IfLetOrMatch` Fixesrust-lang#12564 changelog: Fix [`manual_unwrap_or_default`] false positive when initial `match`/`if let` condition doesn't implement `Default` but the return type does.
Enables the dereference overloads introduced by #12491 to be applied wherever automatic dereferences would be used (field accesses, method calls and indexing).