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