Skip to content

Commit 154a3fd

Browse files
committed
rustc: Unify impl self types in the opposite order so variance is correct
1 parent 3445454 commit 154a3fd

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/libcore/str.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,7 @@ fn is_utf8(v: [const u8]) -> bool {
11621162

11631163
#[doc = "Determines if a vector of `u16` contains valid UTF-16"]
11641164
fn is_utf16(v: [const u16]) -> bool {
1165-
let len = v.len();
1165+
let len = vec::len(v);
11661166
let mut i = 0u;
11671167
while (i < len) {
11681168
let u = v[i];
@@ -1205,7 +1205,7 @@ fn to_utf16(s: str) -> [u16] {
12051205
}
12061206

12071207
fn utf16_chars(v: [const u16], f: fn(char)) {
1208-
let len = v.len();
1208+
let len = vec::len(v);
12091209
let mut i = 0u;
12101210
while (i < len && v[i] != 0u16) {
12111211
let mut u = v[i];
@@ -1231,7 +1231,7 @@ fn utf16_chars(v: [const u16], f: fn(char)) {
12311231

12321232
fn from_utf16(v: [const u16]) -> str {
12331233
let mut buf = "";
1234-
reserve(buf, v.len());
1234+
reserve(buf, vec::len(v));
12351235
utf16_chars(v) {|ch| push_char(buf, ch); }
12361236
ret buf;
12371237
}

src/rustc/middle/typeck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1909,7 +1909,7 @@ fn lookup_method_inner(fcx: @fn_ctxt, expr: @ast::expr,
19091909

19101910
let ty = universally_quantify_regions(tcx, ty);
19111911

1912-
alt unify::unify(fcx, ty, self_ty) {
1912+
alt unify::unify(fcx, self_ty, ty) {
19131913
result::ok(_) {
19141914
if option::is_some(result) {
19151915
// FIXME[impl] score specificity to resolve ambiguity?

src/test/run-pass/impl-variance.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
impl extensions<T> for [const T] {
2+
fn foo() -> uint { vec::len(self) }
3+
}
4+
5+
fn main() {
6+
let v = [const 0];
7+
assert v.foo() == 1u;
8+
let v = [0];
9+
assert v.foo() == 1u;
10+
let v = [mut 0];
11+
assert v.foo() == 1u;
12+
}

0 commit comments

Comments
 (0)