Skip to content

Commit 51820b6

Browse files
committed
rollup merge of #17646 : bkoropoff/cast-ice
2 parents 8bb5a67 + 93408be commit 51820b6

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

src/librustc/middle/trans/consts.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,9 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
547547
(expr::cast_integral, expr::cast_pointer) => {
548548
llvm::LLVMConstIntToPtr(v, llty.to_ref())
549549
}
550+
(expr::cast_pointer, expr::cast_integral) => {
551+
llvm::LLVMConstPtrToInt(v, llty.to_ref())
552+
}
550553
_ => {
551554
cx.sess().impossible_case(e.span,
552555
"bad combination of types for cast")

src/librustc/middle/typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,7 @@ fn check_cast(fcx: &FnCtxt,
14681468
// casts to scalars other than `char` and `bare fn` are trivial
14691469
let t_1_is_trivial = t_1_is_scalar && !t_1_is_char && !t_1_is_bare_fn;
14701470
if ty::type_is_c_like_enum(fcx.tcx(), t_e) && t_1_is_trivial {
1471-
if t_1_is_float {
1471+
if t_1_is_float || ty::type_is_unsafe_ptr(t_1) {
14721472
fcx.type_error_message(span, |actual| {
14731473
format!("illegal cast; cast through an \
14741474
integer first: `{}` as `{}`",

src/test/compile-fail/issue-17444.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
enum Test {
12+
Foo = 0
13+
}
14+
15+
fn main() {
16+
let _x = Foo as *const int;
17+
//~^ ERROR illegal cast; cast through an integer first: `Test` as `*const int`
18+
}

src/test/run-pass/issue-17458.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
static X: uint = 0 as *const uint as uint;
12+
13+
fn main() {
14+
assert_eq!(X, 0);
15+
}

0 commit comments

Comments
 (0)