Skip to content

Commit 7747460

Browse files
committed
---
yaml --- r: 277995 b: refs/heads/auto c: 10737a5 h: refs/heads/master i: 277993: 4f389e0 277991: f3605d3
1 parent 0074307 commit 7747460

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
88
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
99
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1010
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
11-
refs/heads/auto: bf51eafbef4d949673a17ae1f2cc478bcc8c0b58
11+
refs/heads/auto: 10737a5a45ed9a1d9ae73b996fae893da1d62512
1212
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1313
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336
1414
refs/tags/0.2: 1754d02027f2924bed83b0160ee340c7f41d5ea1

branches/auto/src/librustc_const_eval/eval.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ pub enum ErrKind {
408408
TypeMismatch(String, ConstInt),
409409
BadType(ConstVal),
410410
ErroneousReferencedConstant(Box<ConstEvalErr>),
411-
BadCharValue,
411+
CharCast(ConstInt),
412412
}
413413

414414
impl From<ConstMathErr> for ErrKind {
@@ -469,7 +469,9 @@ impl ConstEvalErr {
469469
},
470470
BadType(ref i) => format!("value of wrong type: {:?}", i).into_cow(),
471471
ErroneousReferencedConstant(_) => "could not evaluate referenced constant".into_cow(),
472-
BadCharValue => "invalid numeric value for char".into_cow(),
472+
CharCast(ref got) => {
473+
format!("only `u8` can be cast as `char`, not `{}`", got.description()).into_cow()
474+
},
473475
}
474476
}
475477
}
@@ -1080,16 +1082,19 @@ fn cast_const_int<'tcx>(tcx: &TyCtxt<'tcx>, val: ConstInt, ty: ty::Ty) -> CastRe
10801082
ty::TyFloat(ast::FloatTy::F64) => match val.erase_type() {
10811083
Infer(u) => Ok(Float(u as f64)),
10821084
InferSigned(i) => Ok(Float(i as f64)),
1083-
_ => unreachable!(),
1085+
_ => bug!("ConstInt::erase_type returned something other than Infer/InferSigned"),
10841086
},
10851087
ty::TyFloat(ast::FloatTy::F32) => match val.erase_type() {
10861088
Infer(u) => Ok(Float(u as f32 as f64)),
10871089
InferSigned(i) => Ok(Float(i as f32 as f64)),
1088-
_ => unreachable!(),
1090+
_ => bug!("ConstInt::erase_type returned something other than Infer/InferSigned"),
10891091
},
10901092
ty::TyRawPtr(_) => Err(ErrKind::UnimplementedConstVal("casting an address to a raw ptr")),
1091-
ty::TyChar if v as u32 as u64 == v => ::std::char::from_u32(v as u32).map(Char)
1092-
.ok_or(BadCharValue),
1093+
ty::TyChar => match infer(val, tcx, &ty::TyUint(ast::UintTy::U8)) {
1094+
Ok(U8(u)) => Ok(Char(u as char)),
1095+
// can only occur before typeck, typeck blocks `T as char` for `T` != `u8`
1096+
_ => Err(CharCast(val)),
1097+
},
10931098
_ => Err(CannotCast),
10941099
}
10951100
}

0 commit comments

Comments
 (0)