Skip to content

Commit 47c2091

Browse files
committed
Fix an ICE when translating some static expressions.
Creating two identical static expressions involving casts of pointers to arrays caused an assertion failure in librustc_trans.
1 parent eaf4c5c commit 47c2091

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/librustc_trans/trans/consts.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,10 @@ pub fn const_expr<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, e: &ast::Expr)
241241
ty::ty_vec(unit_ty, Some(len)) => {
242242
let llunitty = type_of::type_of(cx, unit_ty);
243243
let llptr = ptrcast(llconst, llunitty.ptr_to());
244-
assert!(cx.const_globals().borrow_mut()
245-
.insert(llptr as int, llconst).is_none());
244+
let prev_const = cx.const_globals().borrow_mut()
245+
.insert(llptr as int, llconst);
246+
assert!(prev_const.is_none() ||
247+
prev_const == Some(llconst));
246248
assert_eq!(abi::FAT_PTR_ADDR, 0);
247249
assert_eq!(abi::FAT_PTR_EXTRA, 1);
248250
llconst = C_struct(cx, &[

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

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2015 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 foo: [uint; 3] = [1, 2, 3];
12+
13+
static slice_1: &'static [uint] = &foo;
14+
static slice_2: &'static [uint] = &foo;
15+
16+
fn main() {}

0 commit comments

Comments
 (0)