diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 71bf333a8c612..2fa44c5b964c2 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -1083,7 +1083,9 @@ impl<'a, 'tcx> LayoutDetails { // We have exactly one non-ZST field. (Some((i, field)), None, None) => { // Field fills the struct and it has a scalar or scalar pair ABI. - if offsets[i].bytes() == 0 && size == field.size { + if offsets[i].bytes() == 0 && + align.abi() == field.align.abi() && + size == field.size { match field.abi { // For plain scalars we can't unpack newtypes // for `#[repr(C)]`, as that affects C ABIs. diff --git a/src/librustc_trans/abi.rs b/src/librustc_trans/abi.rs index 54828044de670..1cd138d4ee6e9 100644 --- a/src/librustc_trans/abi.rs +++ b/src/librustc_trans/abi.rs @@ -792,7 +792,8 @@ impl<'a, 'tcx> FnType<'tcx> { // dependencies rather than pointer equality let no_alias = match kind { PointerKind::Shared => false, - PointerKind::Frozen | PointerKind::UniqueOwned => true, + PointerKind::UniqueOwned => true, + PointerKind::Frozen | PointerKind::UniqueBorrowed => !is_return }; if no_alias { diff --git a/src/librustc_trans/mir/lvalue.rs b/src/librustc_trans/mir/lvalue.rs index 891d52045c217..91555f97b107e 100644 --- a/src/librustc_trans/mir/lvalue.rs +++ b/src/librustc_trans/mir/lvalue.rs @@ -359,14 +359,12 @@ impl<'a, 'tcx> LvalueRef<'tcx> { /// Set the discriminant for a new value of the given case of the given /// representation. pub fn trans_set_discr(&self, bcx: &Builder<'a, 'tcx>, variant_index: usize) { - match self.layout.variants { + if self.layout.for_variant(bcx.ccx, variant_index).abi == layout::Abi::Uninhabited { + return; + } + match self.layout.variants { layout::Variants::Single { index } => { - if index != variant_index { - // If the layout of an enum is `Single`, all - // other variants are necessarily uninhabited. - assert_eq!(self.layout.for_variant(bcx.ccx, variant_index).abi, - layout::Abi::Uninhabited); - } + assert_eq!(index, variant_index); } layout::Variants::Tagged { .. } => { let ptr = self.project_field(bcx, 0); diff --git a/src/test/codegen/packed.rs b/src/test/codegen/packed.rs index dd530cf03cd41..022f581278c2f 100644 --- a/src/test/codegen/packed.rs +++ b/src/test/codegen/packed.rs @@ -57,3 +57,14 @@ pub fn pkd_pair(pair1: &mut PackedPair, pair2: &mut PackedPair) { // CHECK: call void @llvm.memcpy.{{.*}}(i8* %{{.*}}, i8* %{{.*}}, i{{[0-9]+}} 5, i32 1, i1 false) *pair2 = *pair1; } + +#[repr(packed)] +#[derive(Copy, Clone)] +pub struct PackedNestedPair((u32, u32)); + +// CHECK-LABEL: @pkd_nested_pair +#[no_mangle] +pub fn pkd_nested_pair(pair1: &mut PackedNestedPair, pair2: &mut PackedNestedPair) { +// CHECK: call void @llvm.memcpy.{{.*}}(i8* %{{.*}}, i8* %{{.*}}, i{{[0-9]+}} 8, i32 1, i1 false) + *pair2 = *pair1; +} diff --git a/src/test/run-make/issue-46239/Makefile b/src/test/run-make/issue-46239/Makefile new file mode 100644 index 0000000000000..698a605f7e9ba --- /dev/null +++ b/src/test/run-make/issue-46239/Makefile @@ -0,0 +1,5 @@ +-include ../tools.mk + +all: + $(RUSTC) main.rs -C opt-level=1 + $(call RUN,main) diff --git a/src/test/run-make/issue-46239/main.rs b/src/test/run-make/issue-46239/main.rs new file mode 100644 index 0000000000000..3b3289168abe9 --- /dev/null +++ b/src/test/run-make/issue-46239/main.rs @@ -0,0 +1,18 @@ +// Copyright 2017 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn project(x: &(T,)) -> &T { &x.0 } + +fn dummy() {} + +fn main() { + let f = (dummy as fn(),); + (*project(&f))(); +} diff --git a/src/test/run-pass/issue-46519.rs b/src/test/run-pass/issue-46519.rs new file mode 100644 index 0000000000000..878cae4e387f4 --- /dev/null +++ b/src/test/run-pass/issue-46519.rs @@ -0,0 +1,37 @@ +// Copyright 2017 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags:--test -O + +#[test] +#[should_panic(expected = "creating inhabited type")] +fn test() { + FontLanguageOverride::system_font(SystemFont::new()); +} + +pub enum FontLanguageOverride { + Normal, + Override(&'static str), + System(SystemFont) +} + +pub enum SystemFont {} + +impl FontLanguageOverride { + fn system_font(f: SystemFont) -> Self { + FontLanguageOverride::System(f) + } +} + +impl SystemFont { + fn new() -> Self { + panic!("creating inhabited type") + } +}