allow zsts in the zero case of a nullable pointer optimized enum

This commit is contained in:
Oliver Schneider 2016-11-15 16:15:17 +01:00
parent 5ee75c0805
commit 1c5c6cd078
No known key found for this signature in database
GPG Key ID: 56D6EEA0FC67AC46
3 changed files with 47 additions and 1 deletions

View File

@ -518,7 +518,11 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
let value_ty = self.operand_ty(operand);
self.write_value(value, dest, value_ty)?;
} else {
assert_eq!(operands.len(), 0);
if let Some(operand) = operands.get(0) {
assert_eq!(operands.len(), 1);
let operand_ty = self.operand_ty(operand);
assert_eq!(self.type_size(operand_ty), Some(0));
}
let value_size = self.type_size(dest_ty).expect("pointer types are sized");
let zero = PrimVal::from_int_with_size(0, value_size);
self.write_primval(dest, zero)?;

View File

@ -0,0 +1,22 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::result::Result;
use std::result::Result::Ok;
static C: Result<(), Box<isize>> = Ok(());
// This is because of yet another bad assertion (ICE) about the null side of a nullable enum.
// So we won't actually compile if the bug is present, but we check the value in main anyway.
pub fn main() {
assert!(C.is_ok());
}

View File

@ -0,0 +1,20 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(box_syntax)]
use std::sync::mpsc::channel;
pub fn main() {
let (tx, rx) = channel::<Box<_>>();
tx.send(box 100).unwrap();
let v = rx.recv().unwrap();
assert_eq!(v, box 100);
}