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 16 pull requests #37262

Closed
wants to merge 64 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
b0eee76
Include attributes on generic parameter bindings in pretty printer.
pnkfelix Oct 10, 2016
4bb68be
Add feature gate for `dropck_eyepatch` feature (RFC 1327).
pnkfelix Oct 11, 2016
e8ccc68
Thread `pure_wrt_drop` field through lifetime and type parameters.
pnkfelix Oct 11, 2016
7d2d5bc
Code for enforcing `#[may_dangle]` attribute.
pnkfelix Oct 11, 2016
9a649c3
Require destructors using `#[may_dangle]` to use `unsafe impl`.
pnkfelix Oct 12, 2016
e185cd5
Fix bug in test for E0199 and add test for E0198.
pnkfelix Oct 12, 2016
fa7f69c
tests for `#[may_dangle]` attribute.
pnkfelix Oct 11, 2016
b486a87
add test case for changing private methods
nikomatsakis Oct 12, 2016
8dd9493
placate diagnostic checking tests by fixing sample code in E0569.
pnkfelix Oct 12, 2016
c239fee
fix typo in diagnostic sample code
pnkfelix Oct 13, 2016
029dcee
Avoid many CrateConfig clones.
nnethercote Oct 13, 2016
094c3a2
test: Don't write files into the source tree
alexcrichton Oct 14, 2016
06d173a
Add AppVeyor configuration to the repo
alexcrichton Oct 7, 2016
ac42f3f
correct erroneous pluralization of '1 type argument' error messages
zackmdavis Oct 15, 2016
d902963
Refactor `syntax::ext::base::Resolver::resolve_invoc`.
jseyfried Oct 14, 2016
33e3da8
Use the macro namespace for custom derives.
jseyfried Oct 15, 2016
aac6dca
Treat custom derive extern crates like empty modules.
jseyfried Oct 15, 2016
5afd6d8
Run rustfmt on libcore/sync folder
srinivasreddy Oct 16, 2016
e4ed345
impl Debug for ReadDir
diwic Oct 16, 2016
49e6b46
Mark enums with non-zero discriminant as non-zero
petrochenkov Oct 12, 2016
88fde7f
Don't process cycles when stalled
jonas-schievink Oct 17, 2016
ed50159
Expand .zip() specialization to .map() and .cloned()
bluss Oct 17, 2016
0271a9a
Fix Subst construction: use subst from adt_def rather than Drop impl'…
pnkfelix Oct 17, 2016
818ac08
remove fixme that i no longer think appropriate.
pnkfelix Oct 17, 2016
85d2e4d
Review feedback: add linebreak and reindent to make braces match better.
pnkfelix Oct 17, 2016
0d8f716
Review feedback: expand comment and simplify some code.
pnkfelix Oct 17, 2016
4124d8e
Moved new dropck-eyepatch compile-fail tests to the `ui/` subtree.
pnkfelix Oct 17, 2016
d07523c
ICH: Use 128-bit Blake2b hash instead of 64-bit SipHash for incr. com…
michaelwoerister Oct 7, 2016
0a0efcb
std::collections: Reexport libcollections's range module
bluss Oct 17, 2016
0c844d2
Set stalled=false when encountering an error
jonas-schievink Oct 17, 2016
c560ca4
Fix typo
michaelwoerister Oct 17, 2016
9578e1a
Fix partially consumed tokens in macro matchers.
jseyfried Oct 16, 2016
95a9e2a
Add regression test.
jseyfried Oct 16, 2016
a29b503
Add stable example to TypeId
Oct 18, 2016
10a58ac
Incorporate review feedback: code formatting fixes, expand a comment.
pnkfelix Oct 18, 2016
d11cd46
Add TypedArena::alloc_slice.
Mark-Simulacrum Oct 17, 2016
7a38599
Use TypedArena::alloc_slice in rustc.
Mark-Simulacrum Oct 17, 2016
1cc1dcc
run rustfmt on libpanic_unwind
srinivasreddy Oct 18, 2016
b260617
run rustfmt on librustc_errors folder
srinivasreddy Oct 18, 2016
4a91a80
Fix some pretty printing tests
petrochenkov Oct 12, 2016
93417fa
Add invalid doc comment help message
GuillaumeGomez Oct 4, 2016
d3c5905
Allow bootstrapping without a key. Fixes #36548
brson Oct 18, 2016
c98211d
Rollup merge of #36964 - GuillaumeGomez:comment_error, r=jonathandturner
eddyb Oct 19, 2016
f7766e8
Rollup merge of #37117 - pnkfelix:may-dangle-attr, r=nikomatsakis
eddyb Oct 19, 2016
ea75c75
Rollup merge of #37124 - nikomatsakis:incr-comp-benchmark, r=michaelw…
eddyb Oct 19, 2016
5e6168f
Rollup merge of #37161 - nnethercote:no-cfg-cloning, r=nrc
eddyb Oct 19, 2016
b9241bc
Rollup merge of #37176 - alexcrichton:no-write-to-root, r=brson
eddyb Oct 19, 2016
9ffc011
Rollup merge of #37182 - alexcrichton:appveyor, r=brson
eddyb Oct 19, 2016
46de940
Rollup merge of #37193 - zackmdavis:pluralization_of_expected_type_ar…
eddyb Oct 19, 2016
a979c01
Rollup merge of #37198 - jseyfried:future_proof_macros_11, r=nrc
eddyb Oct 19, 2016
59e5fbe
Rollup merge of #37202 - petrochenkov:pretty, r=nrc
eddyb Oct 19, 2016
e7b1d4a
Rollup merge of #37208 - jseyfried:fix_partially_consumed_tokens_in_m…
eddyb Oct 19, 2016
ba69fd7
Rollup merge of #37218 - srinivasreddy:sync, r=nrc
eddyb Oct 19, 2016
ce9e95a
Rollup merge of #37220 - Mark-Simulacrum:arena-alloc-slice, r=eddyb
eddyb Oct 19, 2016
82371f8
Rollup merge of #37221 - diwic:6a-readdir-debug, r=alexcrichton
eddyb Oct 19, 2016
f399259
Rollup merge of #37224 - petrochenkov:nz, r=eddyb
eddyb Oct 19, 2016
58b64e7
Rollup merge of #37230 - bluss:zip-specialization-for-map, r=alexcric…
eddyb Oct 19, 2016
4d9d15c
Rollup merge of #37231 - jonas-schievink:obligation-forest-the-quest-…
eddyb Oct 19, 2016
e41219c
Rollup merge of #37233 - michaelwoerister:blake2-for-ich, r=nikomatsakis
eddyb Oct 19, 2016
356cec1
Rollup merge of #37236 - bluss:range-argument, r=alexcrichton
eddyb Oct 19, 2016
d386547
Rollup merge of #37240 - jethrogb:typeid_doc, r=sfackler
eddyb Oct 19, 2016
91487db
Rollup merge of #37254 - srinivasreddy:master, r=alexcrichton
eddyb Oct 19, 2016
e1d2999
Rollup merge of #37257 - srinivasreddy:librustc_errors, r=eddyb
eddyb Oct 19, 2016
38708e5
Rollup merge of #37265 - brson:bootstrap, r=alexcrichton
eddyb Oct 19, 2016
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
Prev Previous commit
Next Next commit
Mark enums with non-zero discriminant as non-zero
  • Loading branch information
petrochenkov committed Oct 16, 2016

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 49e6b466e953e5cb56e29cf546204a004f26a985
32 changes: 17 additions & 15 deletions src/librustc/ty/layout.rs
Original file line number Diff line number Diff line change
@@ -597,7 +597,8 @@ impl<'a, 'gcx, 'tcx> Struct {
-> Result<Option<FieldPath>, LayoutError<'gcx>> {
let tcx = infcx.tcx.global_tcx();
match (ty.layout(infcx)?, &ty.sty) {
(&Scalar { non_zero: true, .. }, _) => Ok(Some(vec![])),
(&Scalar { non_zero: true, .. }, _) |
(&CEnum { non_zero: true, .. }, _) => Ok(Some(vec![])),
(&FatPointer { non_zero: true, .. }, _) => {
Ok(Some(vec![FAT_PTR_ADDR as u32]))
}
@@ -769,6 +770,7 @@ pub enum Layout {
CEnum {
discr: Integer,
signed: bool,
non_zero: bool,
// Inclusive discriminant range.
// If min > max, it represents min...u64::MAX followed by 0...max.
// FIXME(eddyb) always use the shortest range, e.g. by finding
@@ -1002,9 +1004,10 @@ impl<'a, 'gcx, 'tcx> Layout {

if def.is_enum() && def.variants.iter().all(|v| v.fields.is_empty()) {
// All bodies empty -> intlike
let (mut min, mut max) = (i64::MAX, i64::MIN);
let (mut min, mut max, mut non_zero) = (i64::MAX, i64::MIN, true);
for v in &def.variants {
let x = v.disr_val.to_u64_unchecked() as i64;
if x == 0 { non_zero = false; }
if x < min { min = x; }
if x > max { max = x; }
}
@@ -1013,6 +1016,7 @@ impl<'a, 'gcx, 'tcx> Layout {
return success(CEnum {
discr: discr,
signed: signed,
non_zero: non_zero,
min: min as u64,
max: max as u64
});
@@ -1069,19 +1073,17 @@ impl<'a, 'gcx, 'tcx> Layout {

// FIXME(eddyb) should take advantage of a newtype.
if path == &[0] && variants[discr].len() == 1 {
match *variants[discr][0].layout(infcx)? {
Scalar { value, .. } => {
return success(RawNullablePointer {
nndiscr: discr as u64,
value: value
});
}
_ => {
bug!("Layout::compute: `{}`'s non-zero \
`{}` field not scalar?!",
ty, variants[discr][0])
}
}
let value = match *variants[discr][0].layout(infcx)? {
Scalar { value, .. } => value,
CEnum { discr, .. } => Int(discr),
_ => bug!("Layout::compute: `{}`'s non-zero \
`{}` field not scalar?!",
ty, variants[discr][0])
};
return success(RawNullablePointer {
nndiscr: discr as u64,
value: value,
});
}

path.push(0); // For GEP through a pointer.
39 changes: 39 additions & 0 deletions src/test/run-pass/nonzero-enum.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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.

use std::mem::size_of;

enum E {
A = 1,
B = 2,
C = 3,
}

struct S {
a: u16,
b: u8,
e: E,
}

fn main() {
assert_eq!(size_of::<E>(), 1);
assert_eq!(size_of::<Option<E>>(), 1);
assert_eq!(size_of::<Result<E, ()>>(), 1);
assert_eq!(size_of::<S>(), 4);
assert_eq!(size_of::<Option<S>>(), 4);
let enone = None::<E>;
let esome = Some(E::A);
if let Some(..) = enone {
panic!();
}
if let None = esome {
panic!();
}
}
2 changes: 2 additions & 0 deletions src/tools/compiletest/src/main.rs
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@
#![feature(test)]
#![feature(libc)]

#![cfg_attr(stage0, feature(question_mark))]

#![deny(warnings)]

extern crate libc;