Skip to content

Commit 347d199

Browse files
committed
auto merge of #5198 : youknowone/rust/repeat-count, r=brson
Before: ```` test.rs:3:21: 3:30 error: expected constant integer for repeat count but found variable test.rs:3 let a = ~[0, ..n]; //~ ERROR expected constant integer for repeat count but found variable ^~~~~~~~~ ```` After: ```` test.rs:3:27: 3:28 error: expected constant integer for repeat count but found variable test.rs:3 let a = ~[0, ..n]; //~ ERROR expected constant integer for repeat count but found variable ^ ````
2 parents d19cbf8 + b662d3c commit 347d199

File tree

4 files changed

+10
-14
lines changed

4 files changed

+10
-14
lines changed

src/librustc/middle/kind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ pub fn check_expr(e: @expr, cx: Context, v: visit::vt<Context>) {
240240
"explicit copy requires a copyable argument");
241241
}
242242
expr_repeat(element, count_expr, _) => {
243-
let count = ty::eval_repeat_count(cx.tcx, count_expr, e.span);
243+
let count = ty::eval_repeat_count(cx.tcx, count_expr);
244244
if count > 1 {
245245
let element_ty = ty::expr_ty(cx.tcx, element);
246246
check_copy(cx, element_ty, element.span,

src/librustc/middle/trans/tvec.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,7 @@ pub fn write_content(bcx: block,
410410
return expr::trans_into(bcx, element, Ignore);
411411
}
412412
SaveIn(lldest) => {
413-
let count = ty::eval_repeat_count(bcx.tcx(), count_expr,
414-
count_expr.span);
413+
let count = ty::eval_repeat_count(bcx.tcx(), count_expr);
415414
if count == 0 {
416415
return bcx;
417416
}
@@ -476,7 +475,7 @@ pub fn elements_required(bcx: block, content_expr: @ast::expr) -> uint {
476475
},
477476
ast::expr_vec(es, _) => es.len(),
478477
ast::expr_repeat(_, count_expr, _) => {
479-
ty::eval_repeat_count(bcx.tcx(), count_expr, content_expr.span)
478+
ty::eval_repeat_count(bcx.tcx(), count_expr)
480479
}
481480
_ => bcx.tcx().sess.span_bug(content_expr.span,
482481
~"Unexpected evec content")

src/librustc/middle/ty.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4247,35 +4247,32 @@ pub fn normalize_ty(cx: ctxt, t: t) -> t {
42474247
}
42484248
42494249
// Returns the repeat count for a repeating vector expression.
4250-
pub fn eval_repeat_count(tcx: ctxt,
4251-
count_expr: @ast::expr,
4252-
span: span)
4253-
-> uint {
4250+
pub fn eval_repeat_count(tcx: ctxt, count_expr: @ast::expr) -> uint {
42544251
match const_eval::eval_const_expr_partial(tcx, count_expr) {
42554252
Ok(ref const_val) => match *const_val {
42564253
const_eval::const_int(count) => return count as uint,
42574254
const_eval::const_uint(count) => return count as uint,
42584255
const_eval::const_float(count) => {
4259-
tcx.sess.span_err(span,
4256+
tcx.sess.span_err(count_expr.span,
42604257
~"expected signed or unsigned integer for \
42614258
repeat count but found float");
42624259
return count as uint;
42634260
}
42644261
const_eval::const_str(_) => {
4265-
tcx.sess.span_err(span,
4262+
tcx.sess.span_err(count_expr.span,
42664263
~"expected signed or unsigned integer for \
42674264
repeat count but found string");
42684265
return 0;
42694266
}
42704267
const_eval::const_bool(_) => {
4271-
tcx.sess.span_err(span,
4268+
tcx.sess.span_err(count_expr.span,
42724269
~"expected signed or unsigned integer for \
42734270
repeat count but found boolean");
42744271
return 0;
42754272
}
42764273
},
42774274
Err(*) => {
4278-
tcx.sess.span_err(span,
4275+
tcx.sess.span_err(count_expr.span,
42794276
~"expected constant integer for repeat count \
42804277
but found variable");
42814278
return 0;

src/librustc/middle/typeck/check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,7 +2157,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
21572157
ty::mk_evec(tcx, ty::mt {ty: t, mutbl: mutability}, tt)
21582158
}
21592159
ast::expr_repeat(element, count_expr, mutbl) => {
2160-
let count = ty::eval_repeat_count(tcx, count_expr, expr.span);
2160+
let count = ty::eval_repeat_count(tcx, count_expr);
21612161
fcx.write_ty(count_expr.id, ty::mk_uint(tcx));
21622162
let tt = ast_expr_vstore_to_vstore(fcx, ev, count, vst);
21632163
let t: ty::t = fcx.infcx().next_ty_var();
@@ -2484,7 +2484,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
24842484
fcx.write_ty(id, typ);
24852485
}
24862486
ast::expr_repeat(element, count_expr, mutbl) => {
2487-
let count = ty::eval_repeat_count(tcx, count_expr, expr.span);
2487+
let count = ty::eval_repeat_count(tcx, count_expr);
24882488
fcx.write_ty(count_expr.id, ty::mk_uint(tcx));
24892489
let t: ty::t = fcx.infcx().next_ty_var();
24902490
bot |= check_expr_has_type(fcx, element, t);

0 commit comments

Comments
 (0)