Skip to content

Commit

Permalink
Resolve type variables when checking casting to char
Browse files Browse the repository at this point in the history
  • Loading branch information
sanxiyn authored and alexcrichton committed Feb 13, 2014
1 parent 745aa74 commit 606c23a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/librustc/middle/typeck/check/mod.rs
Expand Up @@ -3035,6 +3035,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)
Expand Down
13 changes: 13 additions & 0 deletions 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 <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');
}

0 comments on commit 606c23a

Please sign in to comment.