Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 17 pull requests #56026

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
e753d21
miri: accept extern types in structs if they are the only field
RalfJung Nov 4, 2018
aca76d4
test for offset and alignment of the sized part, instead of field count
RalfJung Nov 4, 2018
bb17f71
also test with PhantomData
RalfJung Nov 4, 2018
5ebd077
make it more obvious that the size is not relevant
RalfJung Nov 5, 2018
a6622c2
note some FIXMEs
RalfJung Nov 5, 2018
ba0bab3
make sure we only guess field alignment at offset 0
RalfJung Nov 6, 2018
b7c319c
do not panic just because cargo failed
RalfJung Nov 11, 2018
0c08529
A few tweaks to iterations/collecting
ljedrz Nov 5, 2018
562be7e
Forward the ABI of the non-zero sized fields of an union if they have…
ogoffart Nov 8, 2018
cfbae3e
core/tests/num: Simplify `test_int_from_str_overflow()` test code
Turbo87 Nov 13, 2018
1ca505a
capture_disjoint_fields(rust-lang#53488)
blitzerr Nov 14, 2018
c040a48
Remove extern and some return value as an attempt to make the test pa…
ogoffart Nov 14, 2018
aa3d7a4
properly calculate spans for intra-doc link resolution errors
QuietMisdreavus Nov 15, 2018
a1f83e7
Stress test for MPSC
stepancheg Nov 15, 2018
6779bb4
capture_disjoint_fields(rust-lang#53488)
blitzerr Nov 15, 2018
c5bc83b
expose MutValueVisitor
RalfJung Nov 13, 2018
e4d03f8
miri value visitor: provide place when visiting a primitive
RalfJung Nov 13, 2018
e6e5635
ty: return impl Iterator from Predicate::walk_tys
ljedrz Nov 14, 2018
8c8ff6a
test/linkage-visibility: Ignore on musl targets
smaeul Sep 16, 2018
764e2a7
Disable some pretty-printers when gdb is rust-enabled
tromey Nov 7, 2018
03aaa4b
remove unused dependency
andjo403 Nov 10, 2018
c1221e2
Replace data.clone() by Arc::clone(&data) in mutex doc.
CBenoit Nov 16, 2018
41434e0
avoid shared ref in UnsafeCell::get
RalfJung Nov 16, 2018
a7b312f
erase the tag on casts involving (raw) pointers
RalfJung Nov 17, 2018
01127ca
Update Cargo submodule
alexcrichton Nov 16, 2018
25d46f3
add comment explaining why what we do is legal
RalfJung Nov 17, 2018
d12de8f
std: Add debugging for a failing test on appveyor
alexcrichton Nov 17, 2018
be2305d
Rollup merge of #55564 - smaeul:test-fixes-2, r=alexcrichton
kennytm Nov 17, 2018
0c5947a
Rollup merge of #55672 - RalfJung:miri-extern-types, r=eddyb
kennytm Nov 17, 2018
f6d9029
Rollup merge of #55767 - tromey:disable-some-pretty-printers, r=nikom…
kennytm Nov 17, 2018
eef30d2
Rollup merge of #55827 - ljedrz:various_stashed, r=alexcrichton
kennytm Nov 17, 2018
7ef5c99
Rollup merge of #55834 - ogoffart:union-abi, r=eddyb
kennytm Nov 17, 2018
3556d98
Rollup merge of #55857 - andjo403:rmdep, r=Mark-Simulacrum
kennytm Nov 17, 2018
95795ca
Rollup merge of #55867 - RalfJung:dont-panic, r=Mark-Simulacrum
kennytm Nov 17, 2018
cf221de
Rollup merge of #55916 - RalfJung:mut-visitor, r=oli-obk
kennytm Nov 17, 2018
08a8076
Rollup merge of #55919 - Turbo87:num-tests, r=dtolnay
kennytm Nov 17, 2018
3fa7798
Rollup merge of #55949 - ljedrz:return_impl_Iterator_from_Predicate_w…
kennytm Nov 17, 2018
1a662d2
Rollup merge of #55953 - blitzerr:master, r=nikomatsakis
kennytm Nov 17, 2018
5f3bf9d
Rollup merge of #55962 - QuietMisdreavus:tricky-spans, r=GuillaumeGomez
kennytm Nov 17, 2018
c3d92b4
Rollup merge of #55963 - stepancheg:mpsc-take-2, r=alexcrichton
kennytm Nov 17, 2018
bc7d2cf
Rollup merge of #55999 - alexcrichton:update-cargo, r=nrc
kennytm Nov 17, 2018
577c360
Rollup merge of #56011 - CBenoit:master, r=QuietMisdreavus
kennytm Nov 17, 2018
a818165
Rollup merge of #56012 - RalfJung:unsafe-cell, r=nikomatsakis
kennytm Nov 17, 2018
db99aa8
Rollup merge of #56017 - alexcrichton:debug-test, r=alexcrichton
kennytm Nov 17, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions src/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ dependencies = [
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
"core-foundation 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"crates-io 0.21.0",
"crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam-utils 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"crypto-hash 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"curl 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)",
"curl-sys 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.5.12 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"filetime 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"flate2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down Expand Up @@ -539,6 +539,14 @@ name = "crossbeam-utils"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "crossbeam-utils"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "crypto-hash"
version = "0.3.1"
Expand Down Expand Up @@ -662,6 +670,18 @@ dependencies = [
"termcolor 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "env_logger"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"humantime 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"termcolor 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "environment"
version = "0.1.1"
Expand Down Expand Up @@ -731,6 +751,7 @@ version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
"libz-sys 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
"miniz-sys 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
]

Expand Down Expand Up @@ -2170,7 +2191,6 @@ dependencies = [
"graphviz 0.0.0",
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-rayon 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-rayon-core 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down Expand Up @@ -3211,6 +3231,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum crossbeam-epoch 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9c90f1474584f38e270b5b613e898c8c328aa4f3dea85e0a27ac2e642f009416"
"checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9"
"checksum crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "677d453a17e8bd2b913fa38e8b9cf04bcdbb5be790aa294f2389661d72036015"
"checksum crossbeam-utils 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c55913cc2799171a550e307918c0a360e8c16004820291bf3b638969b4a01816"
"checksum crypto-hash 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "09de9ee0fc255ace04c7fa0763c9395a945c37c8292bb554f8d48361d1dcf1b4"
"checksum curl 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)" = "c7c9d851c825e0c033979d4516c9173bc19a78a96eb4d6ae51d4045440eafa16"
"checksum curl-sys 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)" = "721c204978be2143fab0a84b708c49d79d1f6100b8785610f456043a90708870"
Expand All @@ -3223,6 +3244,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum elasticlunr-rs 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4837d77a1e157489a3933b743fd774ae75074e0e390b2b7f071530048a0d87ee"
"checksum ena 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "88dc8393b3c7352f94092497f6b52019643e493b6b890eb417cdb7c46117e621"
"checksum env_logger 0.5.12 (registry+https://github.com/rust-lang/crates.io-index)" = "f4d7e69c283751083d53d01eac767407343b8b69c4bd70058e08adc2637cb257"
"checksum env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "afb070faf94c85d17d50ca44f6ad076bce18ae92f0037d350947240a36e9d42e"
"checksum environment 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1f4b14e20978669064c33b4c1e0fb4083412e40fe56cbea2eae80fd7591503ee"
"checksum error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff511d5dc435d703f4971bc399647c9bc38e20cb41452e3b9feb4765419ed3f3"
"checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02"
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::fs::{self, File};
use std::io::BufReader;
use std::io::prelude::*;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::process::{Command, Stdio, exit};
use std::str;

use build_helper::{output, mtime, up_to_date};
Expand Down Expand Up @@ -1098,7 +1098,7 @@ pub fn run_cargo(builder: &Builder,
});

if !ok {
panic!("cargo must succeed");
exit(1);
}

// Ok now we need to actually find all the files listed in `toplevel`. We've
Expand Down
43 changes: 25 additions & 18 deletions src/etc/gdb_rust_pretty_printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
if sys.version_info[0] >= 3:
xrange = range

rust_enabled = 'set language rust' in gdb.execute('complete set language ru', to_string = True)

#===============================================================================
# GDB Pretty Printing Module for Rust
#===============================================================================
Expand Down Expand Up @@ -99,27 +101,9 @@ def rust_pretty_printer_lookup_function(gdb_val):
val = GdbValue(gdb_val)
type_kind = val.type.get_type_kind()

if type_kind == rustpp.TYPE_KIND_EMPTY:
return RustEmptyPrinter(val)

if type_kind == rustpp.TYPE_KIND_REGULAR_STRUCT:
return RustStructPrinter(val,
omit_first_field = False,
omit_type_name = False,
is_tuple_like = False)

if type_kind == rustpp.TYPE_KIND_STRUCT_VARIANT:
return RustStructPrinter(val,
omit_first_field = True,
omit_type_name = False,
is_tuple_like = False)

if type_kind == rustpp.TYPE_KIND_SLICE:
return RustSlicePrinter(val)

if type_kind == rustpp.TYPE_KIND_STR_SLICE:
return RustStringSlicePrinter(val)

if type_kind == rustpp.TYPE_KIND_STD_VEC:
return RustStdVecPrinter(val)

Expand All @@ -138,6 +122,29 @@ def rust_pretty_printer_lookup_function(gdb_val):
if type_kind == rustpp.TYPE_KIND_OS_STRING:
return RustOsStringPrinter(val)

# Checks after this point should only be for "compiler" types --
# things that gdb's Rust language support knows about.
if rust_enabled:
return None

if type_kind == rustpp.TYPE_KIND_EMPTY:
return RustEmptyPrinter(val)

if type_kind == rustpp.TYPE_KIND_REGULAR_STRUCT:
return RustStructPrinter(val,
omit_first_field = False,
omit_type_name = False,
is_tuple_like = False)

if type_kind == rustpp.TYPE_KIND_STRUCT_VARIANT:
return RustStructPrinter(val,
omit_first_field = True,
omit_type_name = False,
is_tuple_like = False)

if type_kind == rustpp.TYPE_KIND_STR_SLICE:
return RustStringSlicePrinter(val)

if type_kind == rustpp.TYPE_KIND_TUPLE:
return RustStructPrinter(val,
omit_first_field = False,
Expand Down
4 changes: 3 additions & 1 deletion src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,9 @@ impl<T: ?Sized> UnsafeCell<T> {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub const fn get(&self) -> *mut T {
&self.value as *const T as *mut T
// We can just cast the pointer from `UnsafeCell<T>` to `T` because of
// #[repr(transparent)]
self as *const UnsafeCell<T> as *const T as *mut T
}
}

Expand Down
24 changes: 8 additions & 16 deletions src/libcore/tests/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,36 +82,28 @@ fn from_str_issue7588() {

#[test]
fn test_int_from_str_overflow() {
let mut i8_val: i8 = 127;
assert_eq!("127".parse::<i8>().ok(), Some(i8_val));
assert_eq!("127".parse::<i8>().ok(), Some(127i8));
assert_eq!("128".parse::<i8>().ok(), None);

i8_val = i8_val.wrapping_add(1);
assert_eq!("-128".parse::<i8>().ok(), Some(i8_val));
assert_eq!("-128".parse::<i8>().ok(), Some(-128i8));
assert_eq!("-129".parse::<i8>().ok(), None);

let mut i16_val: i16 = 32_767;
assert_eq!("32767".parse::<i16>().ok(), Some(i16_val));
assert_eq!("32767".parse::<i16>().ok(), Some(32_767i16));
assert_eq!("32768".parse::<i16>().ok(), None);

i16_val = i16_val.wrapping_add(1);
assert_eq!("-32768".parse::<i16>().ok(), Some(i16_val));
assert_eq!("-32768".parse::<i16>().ok(), Some(-32_768i16));
assert_eq!("-32769".parse::<i16>().ok(), None);

let mut i32_val: i32 = 2_147_483_647;
assert_eq!("2147483647".parse::<i32>().ok(), Some(i32_val));
assert_eq!("2147483647".parse::<i32>().ok(), Some(2_147_483_647i32));
assert_eq!("2147483648".parse::<i32>().ok(), None);

i32_val = i32_val.wrapping_add(1);
assert_eq!("-2147483648".parse::<i32>().ok(), Some(i32_val));
assert_eq!("-2147483648".parse::<i32>().ok(), Some(-2_147_483_648i32));
assert_eq!("-2147483649".parse::<i32>().ok(), None);

let mut i64_val: i64 = 9_223_372_036_854_775_807;
assert_eq!("9223372036854775807".parse::<i64>().ok(), Some(i64_val));
assert_eq!("9223372036854775807".parse::<i64>().ok(), Some(9_223_372_036_854_775_807i64));
assert_eq!("9223372036854775808".parse::<i64>().ok(), None);

i64_val = i64_val.wrapping_add(1);
assert_eq!("-9223372036854775808".parse::<i64>().ok(), Some(i64_val));
assert_eq!("-9223372036854775808".parse::<i64>().ok(), Some(-9_223_372_036_854_775_808i64));
assert_eq!("-9223372036854775809".parse::<i64>().ok(), None);
}

Expand Down
3 changes: 1 addition & 2 deletions src/librustc/cfg/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ impl<'a> dot::GraphWalk<'a> for &'a cfg::CFG {
type Node = Node<'a>;
type Edge = Edge<'a>;
fn nodes(&'a self) -> dot::Nodes<'a, Node<'a>> {
let mut v = Vec::new();
self.graph.each_node(|i, nd| { v.push((i, nd)); true });
let v: Vec<_> = self.graph.enumerated_nodes().collect();
v.into()
}
fn edges(&'a self) -> dot::Edges<'a, Edge<'a>> {
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1062,8 +1062,7 @@ impl<'a> LoweringContext<'a> {
attrs
.iter()
.map(|a| self.lower_attr(a))
.collect::<Vec<_>>()
.into()
.collect()
}

fn lower_attr(&mut self, attr: &Attribute) -> Attribute {
Expand Down
4 changes: 3 additions & 1 deletion src/librustc/ich/impls_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::adjustment::AutoBorrow
}
}

impl_stable_hash_for!(struct ty::UpvarId { var_id, closure_expr_id });
impl_stable_hash_for!(struct ty::UpvarPath { hir_id });

impl_stable_hash_for!(struct ty::UpvarId { var_path, closure_expr_id });

impl_stable_hash_for!(enum ty::BorrowKind {
ImmBorrow,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
format!(" for lifetime parameter `{}` in coherence check", name)
}
infer::UpvarRegion(ref upvar_id, _) => {
let var_node_id = self.tcx.hir.hir_to_node_id(upvar_id.var_id);
let var_node_id = self.tcx.hir.hir_to_node_id(upvar_id.var_path.hir_id);
let var_name = self.tcx.hir.name(var_node_id);
format!(" for capture of `{}` by closure", var_name)
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/error_reporting/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
"...so that reference does not outlive borrowed content");
}
infer::ReborrowUpvar(span, ref upvar_id) => {
let var_node_id = self.tcx.hir.hir_to_node_id(upvar_id.var_id);
let var_node_id = self.tcx.hir.hir_to_node_id(upvar_id.var_path.hir_id);
let var_name = self.tcx.hir.name(var_node_id);
err.span_note(span,
&format!("...so that closure can access `{}`", var_name));
Expand Down Expand Up @@ -174,7 +174,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
err
}
infer::ReborrowUpvar(span, ref upvar_id) => {
let var_node_id = self.tcx.hir.hir_to_node_id(upvar_id.var_id);
let var_node_id = self.tcx.hir.hir_to_node_id(upvar_id.var_path.hir_id);
let var_name = self.tcx.hir.name(var_node_id);
let mut err = struct_span_err!(self.tcx.sess,
span,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
let var_hir_id = self.tcx().hir.node_to_hir_id(freevar.var_id());
let closure_def_id = self.tcx().hir.local_def_id(closure_expr.id);
let upvar_id = ty::UpvarId {
var_id: var_hir_id,
var_path: ty::UpvarPath { hir_id: var_hir_id },
closure_expr_id: closure_def_id.to_local(),
};
let upvar_capture = self.mc.tables.upvar_capture(upvar_id);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
let closure_expr_def_id = self.tcx.hir.local_def_id(fn_node_id);
let var_hir_id = self.tcx.hir.node_to_hir_id(var_id);
let upvar_id = ty::UpvarId {
var_id: var_hir_id,
var_path: ty::UpvarPath { hir_id: var_hir_id },
closure_expr_id: closure_expr_def_id.to_local(),
};

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for TypeckTables<'gcx> {
pat_adjustments.hash_stable(hcx, hasher);
hash_stable_hashmap(hcx, hasher, upvar_capture_map, |up_var_id, hcx| {
let ty::UpvarId {
var_id,
var_path,
closure_expr_id
} = *up_var_id;

Expand All @@ -798,14 +798,14 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for TypeckTables<'gcx> {

let var_owner_def_id = DefId {
krate: local_id_root.krate,
index: var_id.owner,
index: var_path.hir_id.owner,
};
let closure_def_id = DefId {
krate: local_id_root.krate,
index: closure_expr_id.to_def_id().index,
};
(hcx.def_path_hash(var_owner_def_id),
var_id.local_id,
var_path.hir_id.local_id,
hcx.def_path_hash(closure_def_id))
});

Expand Down
35 changes: 34 additions & 1 deletion src/librustc/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,9 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
Align::from_bytes(repr_align, repr_align).unwrap());
}

let optimize = !def.repr.inhibit_union_abi_opt();
let mut size = Size::ZERO;
let mut abi = Abi::Aggregate { sized: true };
let index = VariantIdx::new(0);
for field in &variants[index] {
assert!(!field.is_unsized());
Expand All @@ -708,13 +710,44 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
} else {
align = align.max(field.align);
}

// If all non-ZST fields have the same ABI, forward this ABI
if optimize && !field.is_zst() {
// Normalize scalar_unit to the maximal valid range
let field_abi = match &field.abi {
Abi::Scalar(x) => Abi::Scalar(scalar_unit(x.value)),
Abi::ScalarPair(x, y) => {
Abi::ScalarPair(
scalar_unit(x.value),
scalar_unit(y.value),
)
}
Abi::Vector { element: x, count } => {
Abi::Vector {
element: scalar_unit(x.value),
count: *count,
}
}
Abi::Uninhabited |
Abi::Aggregate { .. } => Abi::Aggregate { sized: true },
};

if size == Size::ZERO {
// first non ZST: initialize 'abi'
abi = field_abi;
} else if abi != field_abi {
// different fields have different ABI: reset to Aggregate
abi = Abi::Aggregate { sized: true };
}
}

size = cmp::max(size, field.size);
}

return Ok(tcx.intern_layout(LayoutDetails {
variants: Variants::Single { index },
fields: FieldPlacement::Union(variants[index].len()),
abi: Abi::Aggregate { sized: true },
abi,
align,
size: size.abi_align(align)
}));
Expand Down
Loading