Skip to content

Commit 925e9e1

Browse files
committed
---
yaml --- r: 15348 b: refs/heads/try c: 586b072 h: refs/heads/master v: v3
1 parent fad5bdf commit 925e9e1

File tree

5 files changed

+77
-9
lines changed

5 files changed

+77
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 9de288c35f3f97025954d1f12bdc6cfcdb78f603
5+
refs/heads/try: 586b072eef6354d1c7b5e0a8fba43842826074c6
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/rustc/middle/infer.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,13 @@ impl unify_methods for infer_ctxt {
534534
}
535535

536536
fn tps(as: [ty::t], bs: [ty::t]) -> ures {
537+
// Note: type parameters are always treated as *invariant*
538+
// (otherwise the type system would be unsound). In the
539+
// future we could allow type parameters to declare a
540+
// variance. In that case, you would have to change c_tps()
541+
// for LUB/GLB, which currently always returns `as`.
537542
if check vec::same_length(as, bs) {
538-
iter2(as, bs) {|a, b| self.tys(a, b) }
543+
iter2(as, bs) {|a, b| self.eq_tys(a, b) }
539544
} else {
540545
self.uerr(ty::terr_ty_param_size(bs.len(), as.len()))
541546
}
@@ -1080,12 +1085,8 @@ fn c_tuptys<C:combine>(self: C, as: [ty::t], bs: [ty::t])
10801085

10811086
fn c_tps<C:combine>(self: C, _did: ast::def_id, as: [ty::t], bs: [ty::t])
10821087
-> cres<[ty::t]> {
1083-
// FIXME #1973 lookup the declared variance of the type parameters
1084-
// based on did
1085-
if check vec::same_length(as, bs) {
1086-
map2(as, bs) {|a,b| self.c_tys(a, b) }
1087-
} else {
1088-
err(ty::terr_ty_param_size(bs.len(), as.len()))
1088+
self.infcx().tps(as, bs).then {||
1089+
ok(as)
10891090
}
10901091
}
10911092

@@ -1228,7 +1229,6 @@ fn c_tys<C:combine>(
12281229

12291230
(ty::ty_class(a_id, a_tps), ty::ty_class(b_id, b_tps))
12301231
if a_id == b_id {
1231-
// FIXME variance
12321232
c_tps(self, a_id, a_tps, b_tps).chain {|tps|
12331233
ok(ty::mk_class(tcx, a_id, tps))
12341234
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class box_impl<T> {
2+
let mut f: T;
3+
4+
new(f: T) {
5+
self.f = f;
6+
}
7+
}
8+
9+
fn set_box_impl<T>(b: box_impl<@const T>, v: @const T) {
10+
b.f = v;
11+
}
12+
13+
fn main() {
14+
let b = box_impl::<@int>(@3);
15+
set_box_impl(b, @mut 5);
16+
//!^ ERROR values differ in mutability
17+
18+
// No error when type of parameter actually IS @const int
19+
let b = box_impl::<@const int>(@3);
20+
set_box_impl(b, @mut 5);
21+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
enum box_impl<T> = {
2+
mut f: T
3+
};
4+
5+
fn set_box_impl<T>(b: box_impl<@const T>, v: @const T) {
6+
b.f = v;
7+
}
8+
9+
fn main() {
10+
let b = box_impl::<@int>({mut f: @3});
11+
set_box_impl(b, @mut 5);
12+
//!^ ERROR values differ in mutability
13+
14+
// No error when type of parameter actually IS @const int
15+
let x: @const int = @3; // only way I could find to upcast
16+
let b = box_impl::<@const int>({mut f: x});
17+
set_box_impl(b, @mut 5);
18+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
iface box_iface<T> {
2+
fn get() -> T;
3+
fn set(t: T);
4+
}
5+
6+
enum box_impl<T> = {
7+
mut f: T
8+
};
9+
10+
impl<T:copy> of box_iface<T> for box_impl<T> {
11+
fn get() -> T { ret self.f; }
12+
fn set(t: T) { self.f = t; }
13+
}
14+
15+
fn set_box_iface<T>(b: box_iface<@const T>, v: @const T) {
16+
b.set(v);
17+
}
18+
19+
fn set_box_impl<T>(b: box_impl<@const T>, v: @const T) {
20+
b.set(v);
21+
}
22+
23+
fn main() {
24+
let b = box_impl::<@int>({mut f: @3});
25+
set_box_iface(b as box_iface::<@int>, @mut 5);
26+
//!^ ERROR values differ in mutability
27+
set_box_impl(b, @mut 5);
28+
//!^ ERROR values differ in mutability
29+
}

0 commit comments

Comments
 (0)