Skip to content

Commit 60a6582

Browse files
committed
Don't force resolution of integral type vars in unary minus exprs
These were getting resolved too early, when they were still unconstrained by the rest of the typing context. Waiting a bit longer to resolve them gives the rest of the typing context a chance to come into play, so that they don't default to `int`.
1 parent 64912c9 commit 60a6582

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/rustc/middle/typeck/check.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,14 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
11981198
}
11991199
}
12001200
ast::neg {
1201-
oprnd_t = structurally_resolved_type(fcx, oprnd.span, oprnd_t);
1201+
// If the operand's type is an integral type variable, we
1202+
// don't want to resolve it yet, because the rest of the
1203+
// typing context might not have had the opportunity to
1204+
// constrain it yet.
1205+
if !(ty::type_is_var_integral(oprnd_t)) {
1206+
oprnd_t = structurally_resolved_type(fcx, oprnd.span,
1207+
oprnd_t);
1208+
}
12021209
if !(ty::type_is_integral(oprnd_t) ||
12031210
ty::type_is_fp(oprnd_t)) {
12041211
oprnd_t = check_user_unop(fcx, "-", "unary-", expr,

src/test/run-pass/integer-literal-suffix-inference.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ fn main() {
1616

1717
let _i: i8 = -128;
1818
let j = -128;
19-
// id_i8(j);
19+
id_i8(j);
2020
id_i8(-128);
2121

2222
let _i: i16 = -32_768;
2323
let j = -32_768;
24-
// id_i16(j);
24+
id_i16(j);
2525
id_i16(-32_768);
2626

2727
let _i: i32 = -2_147_483_648;
2828
let j = -2_147_483_648;
29-
// id_i32(j);
29+
id_i32(j);
3030
id_i32(-2_147_483_648);
3131

3232
let _i: i64 = -9_223_372_036_854_775_808;
3333
let j = -9_223_372_036_854_775_808;
34-
// id_i64(j);
34+
id_i64(j);
3535
id_i64(-9_223_372_036_854_775_808);
3636

3737
let _i: uint = 1;

0 commit comments

Comments
 (0)