rustc: Unify impl self types in the opposite order so variance is correct
This commit is contained in:
@@ -1162,7 +1162,7 @@ fn is_utf8(v: [const u8]) -> bool {
|
|||||||
|
|
||||||
#[doc = "Determines if a vector of `u16` contains valid UTF-16"]
|
#[doc = "Determines if a vector of `u16` contains valid UTF-16"]
|
||||||
fn is_utf16(v: [const u16]) -> bool {
|
fn is_utf16(v: [const u16]) -> bool {
|
||||||
let len = v.len();
|
let len = vec::len(v);
|
||||||
let mut i = 0u;
|
let mut i = 0u;
|
||||||
while (i < len) {
|
while (i < len) {
|
||||||
let u = v[i];
|
let u = v[i];
|
||||||
@@ -1205,7 +1205,7 @@ fn to_utf16(s: str) -> [u16] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn utf16_chars(v: [const u16], f: fn(char)) {
|
fn utf16_chars(v: [const u16], f: fn(char)) {
|
||||||
let len = v.len();
|
let len = vec::len(v);
|
||||||
let mut i = 0u;
|
let mut i = 0u;
|
||||||
while (i < len && v[i] != 0u16) {
|
while (i < len && v[i] != 0u16) {
|
||||||
let mut u = v[i];
|
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 {
|
fn from_utf16(v: [const u16]) -> str {
|
||||||
let mut buf = "";
|
let mut buf = "";
|
||||||
reserve(buf, v.len());
|
reserve(buf, vec::len(v));
|
||||||
utf16_chars(v) {|ch| push_char(buf, ch); }
|
utf16_chars(v) {|ch| push_char(buf, ch); }
|
||||||
ret buf;
|
ret buf;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1909,7 +1909,7 @@ fn lookup_method_inner(fcx: @fn_ctxt, expr: @ast::expr,
|
|||||||
|
|
||||||
let ty = universally_quantify_regions(tcx, ty);
|
let ty = universally_quantify_regions(tcx, ty);
|
||||||
|
|
||||||
alt unify::unify(fcx, ty, self_ty) {
|
alt unify::unify(fcx, self_ty, ty) {
|
||||||
result::ok(_) {
|
result::ok(_) {
|
||||||
if option::is_some(result) {
|
if option::is_some(result) {
|
||||||
// FIXME[impl] score specificity to resolve ambiguity?
|
// FIXME[impl] score specificity to resolve ambiguity?
|
||||||
|
|||||||
12
src/test/run-pass/impl-variance.rs
Normal file
12
src/test/run-pass/impl-variance.rs
Normal 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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user