Skip to content

Backporting PRs to beta #38716

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

Merged
merged 8 commits into from
Dec 30, 2016
Merged
Changes from all commits
Commits
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
22 changes: 9 additions & 13 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ def verify(path, sha_path, verbose):
with open(path, "rb") as f:
found = hashlib.sha256(f.read()).hexdigest()
with open(sha_path, "r") as f:
expected, _ = f.readline().split()
expected = f.readline().split()[0]
verified = found == expected
if not verified:
print("invalid checksum:\n"
@@ -146,7 +146,7 @@ class RustBuild(object):
def download_stage0(self):
cache_dst = os.path.join(self.build_dir, "cache")
rustc_cache = os.path.join(cache_dst, self.stage0_rustc_date())
cargo_cache = os.path.join(cache_dst, self.stage0_cargo_date())
cargo_cache = os.path.join(cache_dst, self.stage0_cargo_rev())
if not os.path.exists(rustc_cache):
os.makedirs(rustc_cache)
if not os.path.exists(cargo_cache):
@@ -179,21 +179,17 @@ def download_stage0(self):
if self.cargo().startswith(self.bin_root()) and \
(not os.path.exists(self.cargo()) or self.cargo_out_of_date()):
self.print_what_it_means_to_bootstrap()
channel = self.stage0_cargo_channel()
filename = "cargo-{}-{}.tar.gz".format(channel, self.build)
url = "https://static.rust-lang.org/cargo-dist/" + self.stage0_cargo_date()
filename = "cargo-nightly-{}.tar.gz".format(self.build)
url = "https://s3.amazonaws.com/rust-lang-ci/cargo-builds/" + self.stage0_cargo_rev()
tarball = os.path.join(cargo_cache, filename)
if not os.path.exists(tarball):
get("{}/{}".format(url, filename), tarball, verbose=self.verbose)
unpack(tarball, self.bin_root(), match="cargo", verbose=self.verbose)
with open(self.cargo_stamp(), 'w') as f:
f.write(self.stage0_cargo_date())
f.write(self.stage0_cargo_rev())

def stage0_cargo_date(self):
return self._cargo_date

def stage0_cargo_channel(self):
return self._cargo_channel
def stage0_cargo_rev(self):
return self._cargo_rev

def stage0_rustc_date(self):
return self._rustc_date
@@ -217,7 +213,7 @@ def cargo_out_of_date(self):
if not os.path.exists(self.cargo_stamp()) or self.clean:
return True
with open(self.cargo_stamp(), 'r') as f:
return self.stage0_cargo_date() != f.read()
return self.stage0_cargo_rev() != f.read()

def bin_root(self):
return os.path.join(self.build_dir, self.build, "stage0")
@@ -467,7 +463,7 @@ def main():

data = stage0_data(rb.rust_root)
rb._rustc_channel, rb._rustc_date = data['rustc'].split('-', 1)
rb._cargo_channel, rb._cargo_date = data['cargo'].split('-', 1)
rb._cargo_rev = data['cargo']

start_time = time()

3 changes: 2 additions & 1 deletion src/bootstrap/doc.rs
Original file line number Diff line number Diff line change
@@ -146,7 +146,8 @@ pub fn std(build: &Build, stage: u32, target: &str) {
let mut cargo = build.cargo(&compiler, Mode::Libstd, target, "doc");
cargo.arg("--manifest-path")
.arg(build.src.join("src/rustc/std_shim/Cargo.toml"))
.arg("--features").arg(build.std_features());
.arg("--features").arg(build.std_features())
.arg("-p").arg("std");
build.run(&mut cargo);
cp_r(&out_dir, &out)
}
2 changes: 1 addition & 1 deletion src/bootstrap/step.rs
Original file line number Diff line number Diff line change
@@ -458,7 +458,7 @@ pub fn build_rules(build: &Build) -> Rules {
for (krate, path, default) in krates("test_shim") {
rules.doc(&krate.doc_step, path)
.dep(|s| s.name("libtest"))
.default(default && build.config.docs)
.default(default && build.config.compiler_docs)
.run(move |s| doc::test(build, s.stage, s.target));
}
for (krate, path, default) in krates("rustc-main") {
1 change: 1 addition & 0 deletions src/liballoc_jemalloc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ links = "jemalloc"
name = "alloc_jemalloc"
path = "lib.rs"
test = false
doc = false

[dependencies]
core = { path = "../libcore" }
1 change: 1 addition & 0 deletions src/liballoc_system/Cargo.toml
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ version = "0.0.0"
name = "alloc_system"
path = "lib.rs"
test = false
doc = false

[dependencies]
core = { path = "../libcore" }
1 change: 1 addition & 0 deletions src/libcompiler_builtins/Cargo.toml
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ name = "compiler_builtins"
path = "lib.rs"
test = false
bench = false
doc = false

[dependencies]
core = { path = "../libcore" }
1 change: 1 addition & 0 deletions src/libpanic_abort/Cargo.toml
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ version = "0.0.0"
path = "lib.rs"
test = false
bench = false
doc = false

[dependencies]
core = { path = "../libcore" }
1 change: 1 addition & 0 deletions src/libpanic_unwind/Cargo.toml
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ version = "0.0.0"
path = "lib.rs"
test = false
bench = false
doc = false

[dependencies]
alloc = { path = "../liballoc" }
1 change: 1 addition & 0 deletions src/librand/Cargo.toml
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ version = "0.0.0"
[lib]
name = "rand"
path = "lib.rs"
doc = false

[dependencies]
core = { path = "../libcore" }
7 changes: 7 additions & 0 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
@@ -211,6 +211,12 @@ declare_lint! {
not named `mod.rs`"
}

declare_lint! {
pub LEGACY_IMPORTS,
Warn,
"detects names that resolve to ambiguous glob imports with RFC 1560"
}

declare_lint! {
pub DEPRECATED,
Warn,
@@ -257,6 +263,7 @@ impl LintPass for HardwiredLints {
PATTERNS_IN_FNS_WITHOUT_BODY,
EXTRA_REQUIREMENT_IN_IMPL,
LEGACY_DIRECTORY_OWNERSHIP,
LEGACY_IMPORTS,
DEPRECATED
)
}
4 changes: 4 additions & 0 deletions src/librustc/ty/layout.rs
Original file line number Diff line number Diff line change
@@ -575,6 +575,10 @@ impl<'a, 'gcx, 'tcx> Struct {
});
}

// Disable field reordering until we can decide what to do.
// The odd pattern here avoids a warning about the value never being read.
if can_optimize { can_optimize = false }

let (optimize, sort_ascending) = match kind {
StructKind::AlwaysSizedUnivariant => (can_optimize, false),
StructKind::MaybeUnsizedUnivariant => (can_optimize, false),
77 changes: 39 additions & 38 deletions src/librustc_borrowck/borrowck/mir/elaborate_drops.rs
Original file line number Diff line number Diff line change
@@ -481,54 +481,55 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
is_cleanup: bool)
-> Vec<BasicBlock>
{
let mut succ = succ;
let mut unwind_succ = if is_cleanup {
None
} else {
c.unwind
};
let mut update_drop_flag = true;

let mut succ = self.new_block(
c, c.is_cleanup, TerminatorKind::Goto { target: succ }
);

// Always clear the "master" drop flag at the bottom of the
// ladder. This is needed because the "master" drop flag
// protects the ADT's discriminant, which is invalidated
// after the ADT is dropped.
self.set_drop_flag(
Location { block: succ, statement_index: 0 },
c.path,
DropFlagState::Absent
);

fields.iter().rev().enumerate().map(|(i, &(ref lv, path))| {
let drop_block = match path {
Some(path) => {
debug!("drop_ladder: for std field {} ({:?})", i, lv);

self.elaborated_drop_block(&DropCtxt {
source_info: c.source_info,
is_cleanup: is_cleanup,
init_data: c.init_data,
lvalue: lv,
path: path,
succ: succ,
unwind: unwind_succ,
})
}
None => {
debug!("drop_ladder: for rest field {} ({:?})", i, lv);

let blk = self.complete_drop(&DropCtxt {
source_info: c.source_info,
is_cleanup: is_cleanup,
init_data: c.init_data,
lvalue: lv,
path: c.path,
succ: succ,
unwind: unwind_succ,
}, update_drop_flag);

// the drop flag has been updated - updating
// it again would clobber it.
update_drop_flag = false;

blk
}
succ = if let Some(path) = path {
debug!("drop_ladder: for std field {} ({:?})", i, lv);

self.elaborated_drop_block(&DropCtxt {
source_info: c.source_info,
is_cleanup: is_cleanup,
init_data: c.init_data,
lvalue: lv,
path: path,
succ: succ,
unwind: unwind_succ,
})
} else {
debug!("drop_ladder: for rest field {} ({:?})", i, lv);

self.complete_drop(&DropCtxt {
source_info: c.source_info,
is_cleanup: is_cleanup,
init_data: c.init_data,
lvalue: lv,
path: c.path,
succ: succ,
unwind: unwind_succ,
}, false)
};

succ = drop_block;
unwind_succ = unwind_ladder.as_ref().map(|p| p[i]);

drop_block
succ
}).collect()
}

4 changes: 4 additions & 0 deletions src/librustc_lint/lib.rs
Original file line number Diff line number Diff line change
@@ -234,6 +234,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
id: LintId::of(LEGACY_DIRECTORY_OWNERSHIP),
reference: "issue #37872 <https://github.com/rust-lang/rust/issues/37872>",
},
FutureIncompatibleInfo {
id: LintId::of(LEGACY_IMPORTS),
reference: "issue #38260 <https://github.com/rust-lang/rust/issues/38260>",
},
]);

// Register renamed and removed lints
59 changes: 40 additions & 19 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ use syntax::ast::{Item, ItemKind, ImplItem, ImplItemKind};
use syntax::ast::{Local, Mutability, Pat, PatKind, Path};
use syntax::ast::{PathSegment, PathParameters, QSelf, TraitItemKind, TraitRef, Ty, TyKind};

use syntax_pos::{Span, DUMMY_SP};
use syntax_pos::{Span, DUMMY_SP, MultiSpan};
use errors::DiagnosticBuilder;

use std::cell::{Cell, RefCell};
@@ -896,6 +896,7 @@ enum NameBindingKind<'a> {
Ambiguity {
b1: &'a NameBinding<'a>,
b2: &'a NameBinding<'a>,
legacy: bool,
}
}

@@ -907,13 +908,15 @@ struct AmbiguityError<'a> {
lexical: bool,
b1: &'a NameBinding<'a>,
b2: &'a NameBinding<'a>,
legacy: bool,
}

impl<'a> NameBinding<'a> {
fn module(&self) -> Option<Module<'a>> {
match self.kind {
NameBindingKind::Module(module) => Some(module),
NameBindingKind::Import { binding, .. } => binding.module(),
NameBindingKind::Ambiguity { legacy: true, b1, .. } => b1.module(),
_ => None,
}
}
@@ -923,6 +926,7 @@ impl<'a> NameBinding<'a> {
NameBindingKind::Def(def) => def,
NameBindingKind::Module(module) => module.def().unwrap(),
NameBindingKind::Import { binding, .. } => binding.def(),
NameBindingKind::Ambiguity { legacy: true, b1, .. } => b1.def(),
NameBindingKind::Ambiguity { .. } => Def::Err,
}
}
@@ -1349,11 +1353,14 @@ impl<'a> Resolver<'a> {
self.record_use(name, ns, binding, span)
}
NameBindingKind::Import { .. } => false,
NameBindingKind::Ambiguity { b1, b2 } => {
NameBindingKind::Ambiguity { b1, b2, legacy } => {
self.ambiguity_errors.push(AmbiguityError {
span: span, name: name, lexical: false, b1: b1, b2: b2,
span: span, name: name, lexical: false, b1: b1, b2: b2, legacy: legacy,
});
true
if legacy {
self.record_use(name, ns, b1, span);
}
!legacy
}
_ => false
}
@@ -2946,6 +2953,7 @@ impl<'a> Resolver<'a> {

let mut lookup_results = Vec::new();
let mut worklist = Vec::new();
let mut seen_modules = FxHashSet();
worklist.push((self.graph_root, Vec::new(), false));

while let Some((in_module,
@@ -3001,7 +3009,7 @@ impl<'a> Resolver<'a> {
if !in_module_is_extern || name_binding.vis == ty::Visibility::Public {
// add the module to the lookup
let is_extern = in_module_is_extern || name_binding.is_extern_crate();
if !worklist.iter().any(|&(m, ..)| m.def() == module.def()) {
if seen_modules.insert(module.def_id().unwrap()) {
worklist.push((module, path_segments, is_extern));
}
}
@@ -3065,26 +3073,39 @@ impl<'a> Resolver<'a> {
self.report_shadowing_errors();
let mut reported_spans = FxHashSet();

for &AmbiguityError { span, name, b1, b2, lexical } in &self.ambiguity_errors {
for &AmbiguityError { span, name, b1, b2, lexical, legacy } in &self.ambiguity_errors {
if !reported_spans.insert(span) { continue }
let participle = |binding: &NameBinding| {
if binding.is_import() { "imported" } else { "defined" }
};
let msg1 = format!("`{}` could resolve to the name {} here", name, participle(b1));
let msg2 = format!("`{}` could also resolve to the name {} here", name, participle(b2));
self.session.struct_span_err(span, &format!("`{}` is ambiguous", name))
.span_note(b1.span, &msg1)
.span_note(b2.span, &msg2)
.note(&if !lexical && b1.is_glob_import() {
format!("consider adding an explicit import of `{}` to disambiguate", name)
} else if let Def::Macro(..) = b1.def() {
format!("macro-expanded {} do not shadow",
if b1.is_import() { "macro imports" } else { "macros" })
} else {
format!("macro-expanded {} do not shadow when used in a macro invocation path",
if b1.is_import() { "imports" } else { "items" })
})
.emit();
let note = if !lexical && b1.is_glob_import() {
format!("consider adding an explicit import of `{}` to disambiguate", name)
} else if let Def::Macro(..) = b1.def() {
format!("macro-expanded {} do not shadow",
if b1.is_import() { "macro imports" } else { "macros" })
} else {
format!("macro-expanded {} do not shadow when used in a macro invocation path",
if b1.is_import() { "imports" } else { "items" })
};
if legacy {
let id = match b2.kind {
NameBindingKind::Import { directive, .. } => directive.id,
_ => unreachable!(),
};
let mut span = MultiSpan::from_span(span);
span.push_span_label(b1.span, msg1);
span.push_span_label(b2.span, msg2);
let msg = format!("`{}` is ambiguous", name);
self.session.add_lint(lint::builtin::LEGACY_IMPORTS, id, span, msg);
} else {
self.session.struct_span_err(span, &format!("`{}` is ambiguous", name))
.span_note(b1.span, &msg1)
.span_note(b2.span, &msg2)
.note(&note)
.emit();
}
}

for &PrivacyError(span, name, binding) in &self.privacy_errors {
1 change: 1 addition & 0 deletions src/librustc_resolve/macros.rs
Original file line number Diff line number Diff line change
@@ -288,6 +288,7 @@ impl<'a> Resolver<'a> {
Some(shadower) if shadower.def() != binding.def() => {
self.ambiguity_errors.push(AmbiguityError {
span: span, name: name, b1: shadower, b2: binding, lexical: true,
legacy: false,
});
return Ok(shadower);
}
41 changes: 31 additions & 10 deletions src/librustc_resolve/resolve_imports.rs
Original file line number Diff line number Diff line change
@@ -159,6 +159,7 @@ impl<'a> Resolver<'a> {
binding.def() != shadowed_glob.def() {
self.ambiguity_errors.push(AmbiguityError {
span: span, name: name, lexical: false, b1: binding, b2: shadowed_glob,
legacy: false,
});
}
}
@@ -336,9 +337,9 @@ impl<'a> Resolver<'a> {
}

pub fn ambiguity(&mut self, b1: &'a NameBinding<'a>, b2: &'a NameBinding<'a>)
-> &'a NameBinding<'a> {
-> &'a NameBinding<'a> {
self.arenas.alloc_name_binding(NameBinding {
kind: NameBindingKind::Ambiguity { b1: b1, b2: b2 },
kind: NameBindingKind::Ambiguity { b1: b1, b2: b2, legacy: false },
vis: if b1.vis.is_at_least(b2.vis, self) { b1.vis } else { b2.vis },
span: b1.span,
expansion: Mark::root(),
@@ -726,7 +727,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
}

for (&(name, ns), resolution) in module.resolutions.borrow().iter() {
let resolution = resolution.borrow();
let resolution = &mut *resolution.borrow_mut();
let binding = match resolution.binding {
Some(binding) => binding,
None => continue,
@@ -743,14 +744,34 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
}
}

if let NameBindingKind::Import { binding: orig_binding, directive, .. } = binding.kind {
if ns == TypeNS && orig_binding.is_variant() &&
!orig_binding.vis.is_at_least(binding.vis, self) {
let msg = format!("variant `{}` is private, and cannot be reexported \
(error E0364), consider declaring its enum as `pub`",
name);
self.session.add_lint(PRIVATE_IN_PUBLIC, directive.id, binding.span, msg);
match binding.kind {
NameBindingKind::Import { binding: orig_binding, directive, .. } => {
if ns == TypeNS && orig_binding.is_variant() &&
!orig_binding.vis.is_at_least(binding.vis, self) {
let msg = format!("variant `{}` is private, and cannot be reexported \
(error E0364), consider declaring its enum as `pub`",
name);
self.session.add_lint(PRIVATE_IN_PUBLIC, directive.id, binding.span, msg);
}
}
NameBindingKind::Ambiguity { b1, b2, .. }
if b1.is_glob_import() && b2.is_glob_import() => {
let (orig_b1, orig_b2) = match (&b1.kind, &b2.kind) {
(&NameBindingKind::Import { binding: b1, .. },
&NameBindingKind::Import { binding: b2, .. }) => (b1, b2),
_ => continue,
};
let (b1, b2) = match (orig_b1.vis, orig_b2.vis) {
(ty::Visibility::Public, ty::Visibility::Public) => continue,
(ty::Visibility::Public, _) => (b1, b2),
(_, ty::Visibility::Public) => (b2, b1),
_ => continue,
};
resolution.binding = Some(self.arenas.alloc_name_binding(NameBinding {
kind: NameBindingKind::Ambiguity { b1: b1, b2: b2, legacy: true }, ..*b1
}));
}
_ => {}
}
}

14 changes: 9 additions & 5 deletions src/librustc_trans/mir/mod.rs
Original file line number Diff line number Diff line change
@@ -10,14 +10,13 @@

use libc::c_uint;
use llvm::{self, ValueRef};
use rustc::ty;
use rustc::ty::{self, layout};
use rustc::mir;
use rustc::mir::tcx::LvalueTy;
use session::config::FullDebugInfo;
use base;
use common::{self, Block, BlockAndBuilder, CrateContext, FunctionContext, C_null};
use debuginfo::{self, declare_local, DebugLoc, VariableAccess, VariableKind, FunctionDebugContext};
use machine;
use type_of;

use syntax_pos::{DUMMY_SP, NO_EXPANSION, COMMAND_LINE_EXPN, BytePos};
@@ -494,10 +493,15 @@ fn arg_local_refs<'bcx, 'tcx>(bcx: &BlockAndBuilder<'bcx, 'tcx>,
llval
};

let llclosurety = type_of::type_of(bcx.ccx(), closure_ty);
let layout = bcx.ccx().layout_of(closure_ty);
let offsets = match *layout {
layout::Univariant { ref variant, .. } => &variant.offsets[..],
_ => bug!("Closures are only supposed to be Univariant")
};

for (i, (decl, ty)) in mir.upvar_decls.iter().zip(upvar_tys).enumerate() {
let byte_offset_of_var_in_env =
machine::llelement_offset(bcx.ccx(), llclosurety, i);
let byte_offset_of_var_in_env = offsets[i].bytes();


let ops = unsafe {
[llvm::LLVMRustDIBuilderCreateOpDeref(),
1 change: 1 addition & 0 deletions src/libunwind/Cargo.toml
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ name = "unwind"
path = "lib.rs"
test = false
bench = false
doc = false

[dependencies]
core = { path = "../libcore" }
1 change: 1 addition & 0 deletions src/rustc/libc_shim/Cargo.toml
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ name = "libc"
path = "../../liblibc/src/lib.rs"
test = false
bench = false
doc = false

[dependencies]
core = { path = "../../libcore" }
1 change: 1 addition & 0 deletions src/rustc/std_shim/Cargo.toml
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ authors = ["The Rust Project Developers"]
[lib]
name = "std_shim"
path = "lib.rs"
doc = false

[dependencies]
std = { path = "../../libstd" }
2 changes: 1 addition & 1 deletion src/stage0.txt
Original file line number Diff line number Diff line change
@@ -13,4 +13,4 @@
# released on `$date`

rustc: 1.14.0-2016-12-18
cargo: nightly-2016-11-16
cargo: fbeea902d2c9a5be6d99cc35681565d8f7832592
30 changes: 30 additions & 0 deletions src/test/compile-fail/imports/rfc-1560-warning-cycle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2016 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(rustc_attrs)]
#![allow(unused)]

pub struct Foo;

mod bar {
struct Foo;

mod baz {
use *; //~ NOTE `Foo` could resolve to the name imported here
use bar::*; //~ NOTE `Foo` could also resolve to the name imported here
fn f(_: Foo) {}
//~^ WARN `Foo` is ambiguous
//~| WARN hard error in a future release
//~| NOTE see issue #38260
}
}

#[rustc_error]
fn main() {} //~ ERROR compilation successful
4 changes: 3 additions & 1 deletion src/test/compile-fail/recursive-reexports.rs
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@

// aux-build:recursive_reexports.rs

fn f() -> recursive_reexports::S {} //~ ERROR undeclared
extern crate recursive_reexports;

fn f() -> recursive_reexports::S {} //~ ERROR type name `recursive_reexports::S` is undefined

fn main() {}
54 changes: 54 additions & 0 deletions src/test/run-pass/issue-38437.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2016 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.

// Check that drop elaboration clears the "master" discriminant
// drop flag even if it protects no fields.

struct Good(usize);
impl Drop for Good {
#[inline(never)]
fn drop(&mut self) {
println!("dropping Good({})", self.0);
}
}

struct Void;
impl Drop for Void {
#[inline(never)]
fn drop(&mut self) {
panic!("Suddenly, a Void appears.");
}
}

enum E {
Never(Void),
Fine(Good)
}

fn main() {
let mut go = true;

loop {
let next;
match go {
true => next = E::Fine(Good(123)),
false => return,
}

match next {
E::Never(_) => return,
E::Fine(_good) => go = false,
}

// `next` is dropped and StorageDead'd here. We must reset the
// discriminant's drop flag to avoid random variants being
// dropped.
}
}
7 changes: 0 additions & 7 deletions src/test/run-pass/type-sizes.rs
Original file line number Diff line number Diff line change
@@ -31,10 +31,6 @@ enum e3 {
a([u16; 0], u8), b
}

// Test struct field reordering to make sure it actually reorders.
struct WillOptimize1(u8, u16, u8);
struct WillOptimize2 { a: u8, b: u16, c: u8}

pub fn main() {
assert_eq!(size_of::<u8>(), 1 as usize);
assert_eq!(size_of::<u32>(), 4 as usize);
@@ -58,7 +54,4 @@ pub fn main() {
assert_eq!(size_of::<e1>(), 8 as usize);
assert_eq!(size_of::<e2>(), 8 as usize);
assert_eq!(size_of::<e3>(), 4 as usize);

assert_eq!(size_of::<WillOptimize1>(), 4);
assert_eq!(size_of::<WillOptimize2>(), 4);
}
35 changes: 19 additions & 16 deletions src/test/ui/print_type_sizes/nullable.stdout
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
print-type-size type: `IndirectNonZero<u32>`: 12 bytes, alignment: 4 bytes
print-type-size field `.nested`: 8 bytes
print-type-size field `.post`: 2 bytes
print-type-size type: `IndirectNonZero<u32>`: 20 bytes, alignment: 4 bytes
print-type-size field `.pre`: 1 bytes
print-type-size end padding: 1 bytes
print-type-size type: `MyOption<IndirectNonZero<u32>>`: 12 bytes, alignment: 4 bytes
print-type-size variant `Some`: 12 bytes
print-type-size field `.0`: 12 bytes
print-type-size type: `EmbeddedDiscr`: 8 bytes, alignment: 4 bytes
print-type-size variant `Record`: 7 bytes
print-type-size field `.val`: 4 bytes
print-type-size field `.post`: 2 bytes
print-type-size field `.pre`: 1 bytes
print-type-size end padding: 1 bytes
print-type-size type: `NestedNonZero<u32>`: 8 bytes, alignment: 4 bytes
print-type-size field `.val`: 4 bytes
print-type-size padding: 3 bytes
print-type-size field `.nested`: 12 bytes, alignment: 4 bytes
print-type-size field `.post`: 2 bytes
print-type-size end padding: 2 bytes
print-type-size type: `MyOption<IndirectNonZero<u32>>`: 20 bytes, alignment: 4 bytes
print-type-size variant `Some`: 20 bytes
print-type-size field `.0`: 20 bytes
print-type-size type: `EmbeddedDiscr`: 12 bytes, alignment: 4 bytes
print-type-size variant `Record`: 10 bytes
print-type-size field `.pre`: 1 bytes
print-type-size padding: 3 bytes
print-type-size field `.val`: 4 bytes, alignment: 4 bytes
print-type-size field `.post`: 2 bytes
print-type-size end padding: 2 bytes
print-type-size type: `NestedNonZero<u32>`: 12 bytes, alignment: 4 bytes
print-type-size field `.pre`: 1 bytes
print-type-size end padding: 1 bytes
print-type-size padding: 3 bytes
print-type-size field `.val`: 4 bytes, alignment: 4 bytes
print-type-size field `.post`: 2 bytes
print-type-size end padding: 2 bytes
print-type-size type: `MyOption<core::nonzero::NonZero<u32>>`: 4 bytes, alignment: 4 bytes
print-type-size variant `Some`: 4 bytes
print-type-size field `.0`: 4 bytes
10 changes: 6 additions & 4 deletions src/test/ui/print_type_sizes/packed.stdout
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
print-type-size type: `Padded`: 12 bytes, alignment: 4 bytes
print-type-size field `.g`: 4 bytes
print-type-size field `.h`: 2 bytes
print-type-size type: `Padded`: 16 bytes, alignment: 4 bytes
print-type-size field `.a`: 1 bytes
print-type-size field `.b`: 1 bytes
print-type-size padding: 2 bytes
print-type-size field `.g`: 4 bytes, alignment: 4 bytes
print-type-size field `.c`: 1 bytes
print-type-size padding: 1 bytes
print-type-size field `.h`: 2 bytes, alignment: 2 bytes
print-type-size field `.d`: 1 bytes
print-type-size end padding: 2 bytes
print-type-size end padding: 3 bytes
print-type-size type: `Packed`: 10 bytes, alignment: 1 bytes
print-type-size field `.a`: 1 bytes
print-type-size field `.b`: 1 bytes
16 changes: 7 additions & 9 deletions src/test/ui/print_type_sizes/padding.stdout
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
print-type-size type: `E1`: 12 bytes, alignment: 4 bytes
print-type-size discriminant: 1 bytes
print-type-size variant `A`: 7 bytes
print-type-size discriminant: 4 bytes
print-type-size variant `A`: 5 bytes
print-type-size field `.0`: 4 bytes
print-type-size field `.1`: 1 bytes
print-type-size padding: 2 bytes
print-type-size field `.0`: 4 bytes, alignment: 4 bytes
print-type-size variant `B`: 11 bytes
print-type-size padding: 3 bytes
print-type-size field `.0`: 8 bytes, alignment: 4 bytes
print-type-size variant `B`: 8 bytes
print-type-size field `.0`: 8 bytes
print-type-size type: `E2`: 12 bytes, alignment: 4 bytes
print-type-size discriminant: 1 bytes
print-type-size variant `A`: 7 bytes
@@ -17,7 +15,7 @@ print-type-size variant `B`: 11 bytes
print-type-size padding: 3 bytes
print-type-size field `.0`: 8 bytes, alignment: 4 bytes
print-type-size type: `S`: 8 bytes, alignment: 4 bytes
print-type-size field `.g`: 4 bytes
print-type-size field `.a`: 1 bytes
print-type-size field `.b`: 1 bytes
print-type-size end padding: 2 bytes
print-type-size padding: 2 bytes
print-type-size field `.g`: 4 bytes, alignment: 4 bytes