rustc: Unify impl self types in the opposite order so variance is correct

This commit is contained in:
Brian Anderson 2012-03-16 16:49:11 -07:00
parent 3445454e79
commit 154a3fdf44
3 changed files with 16 additions and 4 deletions

View File

@ -1162,7 +1162,7 @@ fn is_utf8(v: [const u8]) -> bool {
#[doc = "Determines if a vector of `u16` contains valid UTF-16"]
fn is_utf16(v: [const u16]) -> bool {
let len = v.len();
let len = vec::len(v);
let mut i = 0u;
while (i < len) {
let u = v[i];
@ -1205,7 +1205,7 @@ fn to_utf16(s: str) -> [u16] {
}
fn utf16_chars(v: [const u16], f: fn(char)) {
let len = v.len();
let len = vec::len(v);
let mut i = 0u;
while (i < len && v[i] != 0u16) {
let mut u = v[i];
@ -1231,7 +1231,7 @@ fn utf16_chars(v: [const u16], f: fn(char)) {
fn from_utf16(v: [const u16]) -> str {
let mut buf = "";
reserve(buf, v.len());
reserve(buf, vec::len(v));
utf16_chars(v) {|ch| push_char(buf, ch); }
ret buf;
}

View File

@ -1909,7 +1909,7 @@ fn lookup_method_inner(fcx: @fn_ctxt, expr: @ast::expr,
let ty = universally_quantify_regions(tcx, ty);
alt unify::unify(fcx, ty, self_ty) {
alt unify::unify(fcx, self_ty, ty) {
result::ok(_) {
if option::is_some(result) {
// FIXME[impl] score specificity to resolve ambiguity?

View File

@ -0,0 +1,12 @@
impl extensions<T> for [const T] {
fn foo() -> uint { vec::len(self) }
}
fn main() {
let v = [const 0];
assert v.foo() == 1u;
let v = [0];
assert v.foo() == 1u;
let v = [mut 0];
assert v.foo() == 1u;
}