Skip to content

Commit b662d3c

Browse files
committed
Better highlight for repeat count error
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 ^ ````
1 parent 36e8989 commit b662d3c

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
@@ -234,7 +234,7 @@ pub fn check_expr(e: @expr, cx: Context, v: visit::vt<Context>) {
234234
"explicit copy requires a copyable argument");
235235
}
236236
expr_repeat(element, count_expr, _) => {
237-
let count = ty::eval_repeat_count(cx.tcx, count_expr, e.span);
237+
let count = ty::eval_repeat_count(cx.tcx, count_expr);
238238
if count > 1 {
239239
let element_ty = ty::expr_ty(cx.tcx, element);
240240
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
@@ -2147,7 +2147,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
21472147
ty::mk_evec(tcx, ty::mt {ty: t, mutbl: mutability}, tt)
21482148
}
21492149
ast::expr_repeat(element, count_expr, mutbl) => {
2150-
let count = ty::eval_repeat_count(tcx, count_expr, expr.span);
2150+
let count = ty::eval_repeat_count(tcx, count_expr);
21512151
fcx.write_ty(count_expr.id, ty::mk_uint(tcx));
21522152
let tt = ast_expr_vstore_to_vstore(fcx, ev, count, vst);
21532153
let t: ty::t = fcx.infcx().next_ty_var();
@@ -2474,7 +2474,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
24742474
fcx.write_ty(id, typ);
24752475
}
24762476
ast::expr_repeat(element, count_expr, mutbl) => {
2477-
let count = ty::eval_repeat_count(tcx, count_expr, expr.span);
2477+
let count = ty::eval_repeat_count(tcx, count_expr);
24782478
fcx.write_ty(count_expr.id, ty::mk_uint(tcx));
24792479
let t: ty::t = fcx.infcx().next_ty_var();
24802480
bot |= check_expr_has_type(fcx, element, t);

0 commit comments

Comments
 (0)