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 9 pull requests #49615

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
adaaeea
Add missing anchor for union type fields
GuillaumeGomez Mar 30, 2018
d0eeb29
Add support for variant and types fields for intra links
GuillaumeGomez Mar 30, 2018
fb7deda
Add #[must_use] to a few standard library methods
scottmcm Mar 31, 2018
8f9ec1c
avoid IdxSets containing garbage above the universe length
arielb1 Apr 1, 2018
cc939ac
Add vec![ptr::null{,_mut}(); n] optimization, like vec![0; n]
glandium Mar 30, 2018
0df837f
Add vec!['\0'; n] optimization, like vec![0; n]
glandium Apr 2, 2018
fb5b5f5
Refactor inner function into closure.
leoyvens Mar 26, 2018
be25e78
Remove single use helper function.
leoyvens Mar 27, 2018
6511ef3
Simplify code around expected argument types.
leoyvens Mar 27, 2018
a2a0f21
Fix typo
rolfvandekrol Apr 2, 2018
58217ed
run-pass/attr-stmt-expr: expand test cases
abonander Apr 3, 2018
9ab5788
Fix "since" version for getpid feature.
tmccombs Apr 3, 2018
a77b131
Rollup merge of #49419 - leodasvacas:small-typeck-refactorings, r=nik…
kennytm Apr 3, 2018
6c9b016
Rollup merge of #49496 - glandium:master, r=sfackler
kennytm Apr 3, 2018
c091d07
Rollup merge of #49512 - GuillaumeGomez:intra-links-fields, r=QuietMi…
kennytm Apr 3, 2018
bf80935
Rollup merge of #49516 - GuillaumeGomez:add-union-field-missing-ancho…
kennytm Apr 3, 2018
911cda8
Rollup merge of #49533 - scottmcm:more-must-use, r=nikomatsakis
kennytm Apr 3, 2018
cb36b2c
Rollup merge of #49570 - arielb1:bounded-universe, r=nikomatsakis
kennytm Apr 3, 2018
78e0254
Rollup merge of #49599 - rolfvandekrol:feature/no_ru, r=frewsxcv
kennytm Apr 3, 2018
0878e0f
Rollup merge of #49609 - abonander:attr-macro-stmt-expr, r=petrochenkov
kennytm Apr 3, 2018
6af59e8
Rollup merge of #49612 - tmccombs:stabilize-getpid, r=kennytm
kennytm Apr 3, 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
1 change: 1 addition & 0 deletions src/liballoc/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub trait ToOwned {
/// let vv: Vec<i32> = v.to_owned();
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use = "cloning is often expensive and is not expected to have side effects"]
fn to_owned(&self) -> Self::Owned;

/// Uses borrowed data to replace owned data, usually by cloning.
Expand Down
81 changes: 55 additions & 26 deletions src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1567,40 +1567,69 @@ impl SpecFromElem for u8 {
}
}

macro_rules! impl_spec_from_elem {
impl<T: Clone + IsZero> SpecFromElem for T {
#[inline]
fn from_elem(elem: T, n: usize) -> Vec<T> {
if elem.is_zero() {
return Vec {
buf: RawVec::with_capacity_zeroed(n),
len: n,
}
}
let mut v = Vec::with_capacity(n);
v.extend_with(n, ExtendElement(elem));
v
}
}

unsafe trait IsZero {
/// Whether this value is zero
fn is_zero(&self) -> bool;
}

macro_rules! impl_is_zero {
($t: ty, $is_zero: expr) => {
impl SpecFromElem for $t {
unsafe impl IsZero for $t {
#[inline]
fn from_elem(elem: $t, n: usize) -> Vec<$t> {
if $is_zero(elem) {
return Vec {
buf: RawVec::with_capacity_zeroed(n),
len: n,
}
}
let mut v = Vec::with_capacity(n);
v.extend_with(n, ExtendElement(elem));
v
fn is_zero(&self) -> bool {
$is_zero(*self)
}
}
};
}
}

impl_spec_from_elem!(i8, |x| x == 0);
impl_spec_from_elem!(i16, |x| x == 0);
impl_spec_from_elem!(i32, |x| x == 0);
impl_spec_from_elem!(i64, |x| x == 0);
impl_spec_from_elem!(i128, |x| x == 0);
impl_spec_from_elem!(isize, |x| x == 0);
impl_is_zero!(i8, |x| x == 0);
impl_is_zero!(i16, |x| x == 0);
impl_is_zero!(i32, |x| x == 0);
impl_is_zero!(i64, |x| x == 0);
impl_is_zero!(i128, |x| x == 0);
impl_is_zero!(isize, |x| x == 0);

impl_is_zero!(u16, |x| x == 0);
impl_is_zero!(u32, |x| x == 0);
impl_is_zero!(u64, |x| x == 0);
impl_is_zero!(u128, |x| x == 0);
impl_is_zero!(usize, |x| x == 0);

impl_is_zero!(char, |x| x == '\0');

impl_is_zero!(f32, |x: f32| x.to_bits() == 0);
impl_is_zero!(f64, |x: f64| x.to_bits() == 0);

impl_spec_from_elem!(u16, |x| x == 0);
impl_spec_from_elem!(u32, |x| x == 0);
impl_spec_from_elem!(u64, |x| x == 0);
impl_spec_from_elem!(u128, |x| x == 0);
impl_spec_from_elem!(usize, |x| x == 0);
unsafe impl<T: ?Sized> IsZero for *const T {
#[inline]
fn is_zero(&self) -> bool {
(*self).is_null()
}
}

unsafe impl<T: ?Sized> IsZero for *mut T {
#[inline]
fn is_zero(&self) -> bool {
(*self).is_null()
}
}

impl_spec_from_elem!(f32, |x: f32| x.to_bits() == 0);
impl_spec_from_elem!(f64, |x: f64| x.to_bits() == 0);

////////////////////////////////////////////////////////////////////////////////
// Common trait implementations for Vec
Expand Down
1 change: 1 addition & 0 deletions src/libcore/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ pub trait Clone : Sized {
/// assert_eq!("Hello", hello.clone());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use = "cloning is often expensive and is not expected to have side effects"]
fn clone(&self) -> Self;

/// Performs copy-assignment from `source`.
Expand Down
1 change: 1 addition & 0 deletions src/libcore/iter/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,7 @@ pub trait Iterator {
/// [`Result`]: ../../std/result/enum.Result.html
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use = "if you really need to exhaust the iterator, consider `.for_each(drop)` instead"]
fn collect<B: FromIterator<Self::Item>>(self) -> B where Self: Sized {
FromIterator::from_iter(self)
}
Expand Down
74 changes: 73 additions & 1 deletion src/librustc_data_structures/indexed_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ impl<T: Idx> IdxSetBuf<T> {

/// Creates set holding every element whose index falls in range 0..universe_size.
pub fn new_filled(universe_size: usize) -> Self {
Self::new(!0, universe_size)
let mut result = Self::new(!0, universe_size);
result.trim_to(universe_size);
result
}

/// Creates set holding no elements.
Expand Down Expand Up @@ -168,6 +170,36 @@ impl<T: Idx> IdxSet<T> {
}
}

/// Sets all elements up to `universe_size`
pub fn set_up_to(&mut self, universe_size: usize) {
for b in &mut self.bits {
*b = !0;
}
self.trim_to(universe_size);
}

/// Clear all elements above `universe_size`.
fn trim_to(&mut self, universe_size: usize) {
let word_bits = mem::size_of::<Word>() * 8;

// `trim_block` is the first block where some bits have
// to be cleared.
let trim_block = universe_size / word_bits;

// all the blocks above it have to be completely cleared.
if trim_block < self.bits.len() {
for b in &mut self.bits[trim_block+1..] {
*b = 0;
}

// at that block, the `universe_size % word_bits` lsbs
// should remain.
let remaining_bits = universe_size % word_bits;
let mask = (1<<remaining_bits)-1;
self.bits[trim_block] &= mask;
}
}

/// Removes `elem` from the set `self`; returns true iff this changed `self`.
pub fn remove(&mut self, elem: &T) -> bool {
self.bits.clear_bit(elem.index())
Expand Down Expand Up @@ -252,3 +284,43 @@ impl<'a, T: Idx> Iterator for Iter<'a, T> {
}
}
}

#[test]
fn test_trim_to() {
use std::cmp;

for i in 0..256 {
let mut idx_buf: IdxSetBuf<usize> = IdxSetBuf::new_filled(128);
idx_buf.trim_to(i);

let elems: Vec<usize> = idx_buf.iter().collect();
let expected: Vec<usize> = (0..cmp::min(i, 128)).collect();
assert_eq!(elems, expected);
}
}

#[test]
fn test_set_up_to() {
for i in 0..128 {
for mut idx_buf in
vec![IdxSetBuf::new_empty(128), IdxSetBuf::new_filled(128)]
.into_iter()
{
idx_buf.set_up_to(i);

let elems: Vec<usize> = idx_buf.iter().collect();
let expected: Vec<usize> = (0..i).collect();
assert_eq!(elems, expected);
}
}
}

#[test]
fn test_new_filled() {
for i in 0..128 {
let mut idx_buf = IdxSetBuf::new_filled(i);
let elems: Vec<usize> = idx_buf.iter().collect();
let expected: Vec<usize> = (0..i).collect();
assert_eq!(elems, expected);
}
}
2 changes: 1 addition & 1 deletion src/librustc_mir/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ newtype_index!(ScopeId);
/// macro (and methods below) makes working with `BlockAnd` much more
/// convenient.

#[must_use] // if you don't use one of these results, you're leaving a dangling edge
#[must_use = "if you don't use one of these results, you're leaving a dangling edge"]
struct BlockAnd<T>(BasicBlock, T);

trait BlockAndExtension {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/dataflow/impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ impl<'a, 'gcx, 'tcx> BitDenotation for MaybeUninitializedPlaces<'a, 'gcx, 'tcx>
// sets on_entry bits for Arg places
fn start_block_effect(&self, entry_set: &mut IdxSet<MovePathIndex>) {
// set all bits to 1 (uninit) before gathering counterevidence
for e in entry_set.words_mut() { *e = !0; }
entry_set.set_up_to(self.bits_per_block());

drop_flag_effects_for_function_entry(
self.tcx, self.mir, self.mdpe,
Expand Down Expand Up @@ -443,7 +443,7 @@ impl<'a, 'gcx, 'tcx> BitDenotation for DefinitelyInitializedPlaces<'a, 'gcx, 'tc

// sets on_entry bits for Arg places
fn start_block_effect(&self, entry_set: &mut IdxSet<MovePathIndex>) {
for e in entry_set.words_mut() { *e = 0; }
entry_set.clear();

drop_flag_effects_for_function_entry(
self.tcx, self.mir, self.mdpe,
Expand Down
Loading