Skip to content

Commit 7f772bb

Browse files
committed
type_of: use sizing_type_of to check the size of arrays
when evaluating a recursive type, the type_of of the interior could be still in progress, so we can't use that. Fixes #19001
1 parent 2c42c98 commit 7f772bb

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
@@ -395,8 +395,12 @@ pub fn in_memory_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) ->
395395

396396
ty::TyArray(ty, size) => {
397397
let size = size as u64;
398+
// we must use `sizing_type_of` here as the type may
399+
// not be fully initialized.
400+
let szty = sizing_type_of(cx, ty);
401+
ensure_array_fits_in_address_space(cx, szty, size, t);
402+
398403
let llty = in_memory_type_of(cx, ty);
399-
ensure_array_fits_in_address_space(cx, llty, size, t);
400404
Type::array(&llty, size)
401405
}
402406

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)