@@ -4315,23 +4315,30 @@ pub fn normalize_ty(cx: ctxt, t: t) -> t {
4315
4315
pub fn eval_repeat_count ( tcx : ctxt , count_expr : @ast:: expr ) -> uint {
4316
4316
match const_eval:: eval_const_expr_partial ( tcx, count_expr) {
4317
4317
Ok ( ref const_val) => match * const_val {
4318
- const_eval:: const_int( count) => return count as uint ,
4318
+ const_eval:: const_int( count) => if count < 0 {
4319
+ tcx. sess . span_err ( count_expr. span ,
4320
+ "expected positive integer for \
4321
+ repeat count but found negative integer") ;
4322
+ return 0 ;
4323
+ } else {
4324
+ return count as uint
4325
+ } ,
4319
4326
const_eval:: const_uint( count) => return count as uint ,
4320
4327
const_eval:: const_float( count) => {
4321
4328
tcx. sess . span_err ( count_expr. span ,
4322
- "expected signed or unsigned integer for \
4329
+ "expected positive integer for \
4323
4330
repeat count but found float") ;
4324
4331
return count as uint ;
4325
4332
}
4326
4333
const_eval:: const_str( _) => {
4327
4334
tcx. sess . span_err ( count_expr. span ,
4328
- "expected signed or unsigned integer for \
4335
+ "expected positive integer for \
4329
4336
repeat count but found string") ;
4330
4337
return 0 ;
4331
4338
}
4332
4339
const_eval:: const_bool( _) => {
4333
4340
tcx. sess . span_err ( count_expr. span ,
4334
- "expected signed or unsigned integer for \
4341
+ "expected positive integer for \
4335
4342
repeat count but found boolean") ;
4336
4343
return 0 ;
4337
4344
}
0 commit comments