]> git.lizzy.rs Git - rust.git/commitdiff
Resolve type variables when checking casting to char
authorSeo Sanghyeon <sanxiyn@gmail.com>
Wed, 12 Feb 2014 15:42:28 +0000 (00:42 +0900)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 13 Feb 2014 20:50:25 +0000 (12:50 -0800)
src/librustc/middle/typeck/check/mod.rs
src/test/run-pass/issue-9918.rs [new file with mode: 0644]

index 9eec804dd2e11932e2a2b37d1d95a8823cf97f8b..68511362f5ffcb59df459d09b45365451ba9189c 100644 (file)
@@ -3035,6 +3035,7 @@ fn check_struct_enum_variant(fcx: @FnCtxt,
                     if type_is_c_like_enum(fcx, expr.span, t_e) && t_1_is_trivial {
                         // casts from C-like enums are allowed
                     } else if t_1_is_char {
+                        let te = fcx.infcx().resolve_type_vars_if_possible(te);
                         if ty::get(te).sty != ty::ty_uint(ast::TyU8) {
                             fcx.type_error_message(expr.span, |actual| {
                                 format!("only `u8` can be cast as `char`, not `{}`", actual)
diff --git a/src/test/run-pass/issue-9918.rs b/src/test/run-pass/issue-9918.rs
new file mode 100644 (file)
index 0000000..240a134
--- /dev/null
@@ -0,0 +1,13 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub fn main() {
+    assert_eq!((0 + 0u8) as char, '\0');
+}