Skip to content

Commit 70c7590

Browse files
committed
rustc: Alias fix part 2 -- Check that the aliasness of function parameters matches. Add a test case.
1 parent b2b33de commit 70c7590

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

src/comp/middle/ty.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,14 +2098,17 @@ mod Unify {
20982098
auto expected_input = expected_inputs.(i);
20992099
auto actual_input = actual_inputs.(i);
21002100

2101-
// This should be safe, I think?
2102-
// FIXME: It's not. At all.
2101+
// Unify the result modes. "mo_either" unifies with both modes.
21032102
auto result_mode;
2104-
if (expected_input.mode == mo_alias ||
2105-
actual_input.mode == mo_alias) {
2106-
result_mode = mo_alias;
2103+
if (expected_input.mode == mo_either) {
2104+
result_mode = actual_input.mode;
2105+
} else if (actual_input.mode == mo_either) {
2106+
result_mode = expected_input.mode;
2107+
} else if (expected_input.mode != actual_input.mode) {
2108+
ret fn_common_res_err(ures_err(terr_arg_count,
2109+
expected, actual));
21072110
} else {
2108-
result_mode = mo_val;
2111+
result_mode = expected_input.mode;
21092112
}
21102113

21112114
auto result = unify_step(cx, actual_input.ty, expected_input.ty);

src/comp/middle/typeck.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,17 +1766,15 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
17661766
auto a_0 = check_expr(fcx, a);
17671767
args_0 += vec(some[@ast.expr](a_0));
17681768

1769-
// FIXME: this breaks aliases. We need a ty_fn_arg.
1770-
auto arg_ty = rec(mode=mo_val,
1769+
auto arg_ty = rec(mode=mo_either,
17711770
ty=expr_ty(fcx.ccx.tcx, a_0));
17721771
Vec.push[arg](arg_tys_0, arg_ty);
17731772
}
17741773
case (none[@ast.expr]) {
17751774
args_0 += vec(none[@ast.expr]);
17761775

1777-
// FIXME: breaks aliases too?
17781776
auto typ = next_ty_var(fcx.ccx);
1779-
Vec.push[arg](arg_tys_0, rec(mode=mo_val, ty=typ));
1777+
Vec.push[arg](arg_tys_0, rec(mode=mo_either, ty=typ));
17801778
}
17811779
}
17821780
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// -*- rust -*-
2+
// xfail-stage0
3+
4+
// error-pattern: mismatched types
5+
6+
fn f(&int x) { log_err x; }
7+
fn h(int x) { log_err x; }
8+
fn main() {
9+
let fn(int x) g = f;
10+
g(10);
11+
g = h;
12+
g(10);
13+
}
14+
15+

0 commit comments

Comments
 (0)