From 30a25a9315427222a8638b658ca22dc9afab242a Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Thu, 13 Feb 2014 00:42:28 +0900 Subject: [PATCH] Resolve type variables when checking casting to char --- src/librustc/middle/typeck/check/mod.rs | 1 + src/test/run-pass/issue-9918.rs | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 src/test/run-pass/issue-9918.rs diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index e2e7a58f5231b..2219c242cfa6a 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -3033,6 +3033,7 @@ pub fn check_expr_with_unifier(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 index 0000000000000..240a134221d34 --- /dev/null +++ b/src/test/run-pass/issue-9918.rs @@ -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 or the MIT license +// , 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'); +}