Skip to content

Commit a4fa065

Browse files
committed
Auto merge of #29409 - arielb1:recursive-arrays, r=eddyb
when evaluating a recursive type, the `type_of` of the interior could be still in progress, so trying to get its size would cause an ICE. Fixes #19001 r? @eddyb
2 parents 7e3c8cf + 7f772bb commit a4fa065

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/librustc_trans/trans/type_of.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,12 @@ pub fn in_memory_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) ->
397397

398398
ty::TyArray(ty, size) => {
399399
let size = size as u64;
400+
// we must use `sizing_type_of` here as the type may
401+
// not be fully initialized.
402+
let szty = sizing_type_of(cx, ty);
403+
ensure_array_fits_in_address_space(cx, szty, size, t);
404+
400405
let llty = in_memory_type_of(cx, ty);
401-
ensure_array_fits_in_address_space(cx, llty, size, t);
402406
Type::array(&llty, size)
403407
}
404408

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

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
// check that we handle recursive arrays correctly in `type_of`
12+
13+
struct Loopy {
14+
ptr: *mut [Loopy; 1]
15+
}
16+
17+
fn main() {
18+
let _t = Loopy { ptr: 0 as *mut _ };
19+
}

0 commit comments

Comments
 (0)