Skip to content

Commit 66c2e46

Browse files
committed
librustc_trans: Don't ICE on unsized type behind raw pointer in nullable pointer opt.
1 parent 54d6509 commit 66c2e46

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/librustc_trans/trans/adt.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,10 @@ fn find_discr_field_candidate<'tcx>(tcx: &ty::ctxt<'tcx>,
414414
assert_eq!(nonzero_fields.len(), 1);
415415
let nonzero_field = ty::lookup_field_type(tcx, did, nonzero_fields[0].id, substs);
416416
match nonzero_field.sty {
417+
ty::ty_ptr(ty::mt { ty, .. }) if !type_is_sized(tcx, ty) => {
418+
path.push_all(&[0, FAT_PTR_ADDR]);
419+
Some(path)
420+
},
417421
ty::ty_ptr(..) | ty::ty_int(..) | ty::ty_uint(..) => {
418422
path.push(0);
419423
Some(path)

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
// Don't fail if we encounter a NonZero<*T> where T is an unsized type
12+
13+
#![feature(unique)]
14+
15+
use std::ptr::Unique;
16+
17+
fn main() {
18+
let mut a = [0u8; 5];
19+
let b: Option<Unique<[u8]>> = unsafe { Some(Unique::new(&mut a)) };
20+
match b {
21+
Some(_) => println!("it's a some"),
22+
None => println!("it's a none"),
23+
}
24+
}

0 commit comments

Comments
 (0)