Make auto-slice, auto-ptr not exclusive (fixes #3514)

This commit is contained in:
Niko Matsakis 2012-09-17 11:00:50 -07:00
parent 527a6f60f1
commit 2469cba0b1
2 changed files with 23 additions and 7 deletions

View File

@ -168,8 +168,8 @@ impl LookupContext {
// around newtype enums. They can be further
// deref'd, but they may also have intrinsic
// methods hanging off of them with interior type.
match self.search_for_appr_autorefd_method(self_ty,
autoderefs) {
match self.search_for_any_autorefd_method(self_ty,
autoderefs) {
Some(move mme) => { return Some(mme); }
None => {}
}
@ -186,7 +186,7 @@ impl LookupContext {
}
}
self.search_for_appr_autorefd_method(self_ty, autoderefs)
self.search_for_any_autorefd_method(self_ty, autoderefs)
}
fn deref(ty: ty::t, enum_dids: &DVec<ast::def_id>) -> Option<ty::t> {
@ -527,15 +527,13 @@ impl LookupContext {
* Attempts both auto-slice and auto-ptr, as appropriate.
*/
let tcx = self.tcx();
match self.search_for_autosliced_method(self_ty, autoderefs) {
Some(mme) => { return mme; }
Some(move mme) => { return Some(move mme); }
None => {}
}
match self.search_for_autoptrd_method(self_ty, autoderefs) {
Some(mme) => { return mme; }
Some(move mme) => { return Some(move mme); }
None => {}
}
@ -553,6 +551,7 @@ impl LookupContext {
* Searches for a candidate by converting things like
* `~[]` to `&[]`. */
let tcx = self.tcx();
match ty::get(self_ty).sty {
ty_evec(mt, vstore_box) |
ty_evec(mt, vstore_uniq) |
@ -593,6 +592,7 @@ impl LookupContext {
* appropriate mutability.
*/
let tcx = self.tcx();
match ty::get(self_ty).sty {
ty_box(*) | ty_uniq(*) | ty_rptr(*) => {
// we should be fully autoderef'd

View File

@ -0,0 +1,16 @@
trait Pushable<T> {
fn push_val(&mut self, +t: T);
}
impl<T> ~[T]: Pushable<T> {
fn push_val(&mut self, +t: T) {
vec::push(*self, t);
}
}
fn main() {
let mut v = ~[1];
v.push_val(2);
v.push_val(3);
assert v == ~[1, 2, 3];
}