Skip to content

Commit 9e6f5fe

Browse files
committed
---
yaml --- r: 6573 b: refs/heads/master c: a69eab1 h: refs/heads/master i: 6571: 096c3b8 v: v3
1 parent 7b3e28c commit 9e6f5fe

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: f1eb7ce013526c6ae75e92a31fe3b89b4cf44b3f
2+
refs/heads/master: a69eab16ec3435bd505a7dafcb9a82b5eace49a2

trunk/src/comp/middle/typeck.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,6 +2116,20 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
21162116
let t_1 = ast_ty_to_ty_crate(fcx.ccx, t);
21172117
let t_e = expr_ty(tcx, e);
21182118

2119+
if ty::type_is_nil(tcx, t_e) {
2120+
tcx.sess.span_err(expr.span,
2121+
"cast from nil: " +
2122+
ty_to_str(tcx, expr_ty(tcx, e)) + " as " +
2123+
ty_to_str(tcx, t_1));
2124+
}
2125+
2126+
if ty::type_is_nil(tcx, t_1) {
2127+
tcx.sess.span_err(expr.span,
2128+
"cast to nil: " +
2129+
ty_to_str(tcx, expr_ty(tcx, e)) + " as " +
2130+
ty_to_str(tcx, t_1));
2131+
}
2132+
21192133
// FIXME there are more forms of cast to support, eventually.
21202134
if !( type_is_scalar(fcx, expr.span, t_e)
21212135
&& type_is_scalar(fcx, expr.span, t_1)) {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// error-pattern: cast from nil: () as u32
2+
fn main() { let u = (assert true) as u32; }
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// error-pattern: cast to nil: u32 as ()
2+
fn main() { let u = 0u32 as (); }

0 commit comments

Comments
 (0)