Skip to content

Commit 4f56801

Browse files
committed
Auto merge of #46516 - michaelwoerister:backport-46428-and-46253, r=nmatsakis
Backport #46428 and #46253
2 parents 6b15f7d + 4e28c61 commit 4f56801

File tree

7 files changed

+81
-9
lines changed

7 files changed

+81
-9
lines changed

src/librustc/ty/layout.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,9 @@ impl<'a, 'tcx> LayoutDetails {
10831083
// We have exactly one non-ZST field.
10841084
(Some((i, field)), None, None) => {
10851085
// Field fills the struct and it has a scalar or scalar pair ABI.
1086-
if offsets[i].bytes() == 0 && size == field.size {
1086+
if offsets[i].bytes() == 0 &&
1087+
align.abi() == field.align.abi() &&
1088+
size == field.size {
10871089
match field.abi {
10881090
// For plain scalars we can't unpack newtypes
10891091
// for `#[repr(C)]`, as that affects C ABIs.

src/librustc_trans/abi.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,8 @@ impl<'a, 'tcx> FnType<'tcx> {
792792
// dependencies rather than pointer equality
793793
let no_alias = match kind {
794794
PointerKind::Shared => false,
795-
PointerKind::Frozen | PointerKind::UniqueOwned => true,
795+
PointerKind::UniqueOwned => true,
796+
PointerKind::Frozen |
796797
PointerKind::UniqueBorrowed => !is_return
797798
};
798799
if no_alias {

src/librustc_trans/mir/lvalue.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,12 @@ impl<'a, 'tcx> LvalueRef<'tcx> {
359359
/// Set the discriminant for a new value of the given case of the given
360360
/// representation.
361361
pub fn trans_set_discr(&self, bcx: &Builder<'a, 'tcx>, variant_index: usize) {
362-
match self.layout.variants {
362+
if self.layout.for_variant(bcx.ccx, variant_index).abi == layout::Abi::Uninhabited {
363+
return;
364+
}
365+
match self.layout.variants {
363366
layout::Variants::Single { index } => {
364-
if index != variant_index {
365-
// If the layout of an enum is `Single`, all
366-
// other variants are necessarily uninhabited.
367-
assert_eq!(self.layout.for_variant(bcx.ccx, variant_index).abi,
368-
layout::Abi::Uninhabited);
369-
}
367+
assert_eq!(index, variant_index);
370368
}
371369
layout::Variants::Tagged { .. } => {
372370
let ptr = self.project_field(bcx, 0);

src/test/codegen/packed.rs

+11
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,14 @@ pub fn pkd_pair(pair1: &mut PackedPair, pair2: &mut PackedPair) {
5757
// CHECK: call void @llvm.memcpy.{{.*}}(i8* %{{.*}}, i8* %{{.*}}, i{{[0-9]+}} 5, i32 1, i1 false)
5858
*pair2 = *pair1;
5959
}
60+
61+
#[repr(packed)]
62+
#[derive(Copy, Clone)]
63+
pub struct PackedNestedPair((u32, u32));
64+
65+
// CHECK-LABEL: @pkd_nested_pair
66+
#[no_mangle]
67+
pub fn pkd_nested_pair(pair1: &mut PackedNestedPair, pair2: &mut PackedNestedPair) {
68+
// CHECK: call void @llvm.memcpy.{{.*}}(i8* %{{.*}}, i8* %{{.*}}, i{{[0-9]+}} 8, i32 1, i1 false)
69+
*pair2 = *pair1;
70+
}
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(RUSTC) main.rs -C opt-level=1
5+
$(call RUN,main)

src/test/run-make/issue-46239/main.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2017 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+
fn project<T>(x: &(T,)) -> &T { &x.0 }
12+
13+
fn dummy() {}
14+
15+
fn main() {
16+
let f = (dummy as fn(),);
17+
(*project(&f))();
18+
}

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

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2017 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+
// compile-flags:--test -O
12+
13+
#[test]
14+
#[should_panic(expected = "creating inhabited type")]
15+
fn test() {
16+
FontLanguageOverride::system_font(SystemFont::new());
17+
}
18+
19+
pub enum FontLanguageOverride {
20+
Normal,
21+
Override(&'static str),
22+
System(SystemFont)
23+
}
24+
25+
pub enum SystemFont {}
26+
27+
impl FontLanguageOverride {
28+
fn system_font(f: SystemFont) -> Self {
29+
FontLanguageOverride::System(f)
30+
}
31+
}
32+
33+
impl SystemFont {
34+
fn new() -> Self {
35+
panic!("creating inhabited type")
36+
}
37+
}

0 commit comments

Comments
 (0)