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 13 pull requests #65368

Merged
merged 33 commits into from
Oct 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
334bafe
Document current deny by default lints
HeroicKatora Oct 3, 2019
4bb1592
Suggest `if let` on `let` refutable binding
estebank Oct 9, 2019
5bb0a03
Move diagnostics code out of the critical path
estebank Oct 11, 2019
91cf02c
Implement Clone::clone_from for VecDeque
crgl Oct 3, 2019
10671f1
Add tests for VecDeque clone_from
crgl Oct 3, 2019
d21eeb1
Override nth for VecDeque Iter and IterMut
crgl Oct 4, 2019
7140c02
resolve: fix error title regarding private constructors
da-x Oct 11, 2019
9d11bda
resolve: shorten wording on private constructor error
da-x Oct 11, 2019
05db5a2
Report lint in external macros
memoryruins Oct 11, 2019
95a65cd
Add regression test for CONST_ERR lints in extern macros
memoryruins Oct 11, 2019
e039534
replace the hand-written binary search with the library one
Oct 12, 2019
d8c2956
Improve docs on some char boolean methods
Oct 6, 2019
a2b2362
do not reference LLVM for our concurrency memory model
RalfJung Oct 12, 2019
63cb2fa
compress the function, remove the assert check.
Oct 12, 2019
f363550
it's C++20
RalfJung Oct 12, 2019
d6ab45d
fix link targets
RalfJung Oct 12, 2019
9f09387
syntax: simplify maybe_annotate_with_ascription
Centril Oct 8, 2019
477a68b
simplify maybe_stage_features
Centril Oct 8, 2019
7effe63
simplify integer_lit
Centril Oct 8, 2019
94db37a
mbe: reduce panictry! uses.
Centril Oct 8, 2019
d0f8bd6
Rollup merge of #65039 - HeroicKatora:deny-by-default-book, r=Guillau…
Centril Oct 13, 2019
4dc0b8a
Rollup merge of #65069 - crgl:clone-from-vec-deque, r=bluss
Centril Oct 13, 2019
82fb193
Rollup merge of #65165 - BO41:char_docs, r=varkor
Centril Oct 13, 2019
963e4bc
Rollup merge of #65248 - estebank:mention-if-let, r=cramertj
Centril Oct 13, 2019
540278c
Rollup merge of #65250 - da-x:ctor-in-error-msgs, r=petrochenkov
Centril Oct 13, 2019
433ea1a
Rollup merge of #65295 - estebank:gotta-go-fast, r=nnethercote
Centril Oct 13, 2019
643261a
Rollup merge of #65320 - memoryruins:const_err, r=oli-obk
Centril Oct 13, 2019
af8a6e5
Rollup merge of #65327 - guanqun:remove-hand-binary-search, r=petroch…
Centril Oct 13, 2019
293d02d
Rollup merge of #65339 - RalfJung:atomic-ordering, r=Centril
Centril Oct 13, 2019
b143aa2
Rollup merge of #65357 - Centril:simplify-maybe-annotate-with-ascript…
Centril Oct 13, 2019
5af528a
Rollup merge of #65358 - Centril:smsf, r=davidtwco
Centril Oct 13, 2019
af54a3e
Rollup merge of #65359 - Centril:sil, r=davidtwco
Centril Oct 13, 2019
b828591
Rollup merge of #65360 - Centril:mbrpt, r=petrochenkov
Centril Oct 13, 2019
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
25 changes: 25 additions & 0 deletions src/doc/rustc/src/lints/listing/deny-by-default.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,28 @@ error: invalid `crate_type` value
| ^^^^^^^^^^^^^^^^^^^^
|
```

## const-err

This lint detects expressions that will always panic at runtime and would be an
error in a `const` context.

```rust,ignore
let _ = [0; 4][4];
```

This will produce:

```text
error: index out of bounds: the len is 4 but the index is 4
--> src/lib.rs:1:9
|
1 | let _ = [0; 4][4];
| ^^^^^^^^^
|
```

## order-dependent-trait-objects

This lint detects a trait coherency violation that would allow creating two
trait impls for the same dynamic trait object involving marker traits.
101 changes: 99 additions & 2 deletions src/liballoc/collections/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
use core::array::LengthAtMost32;
use core::cmp::{self, Ordering};
use core::fmt;
use core::iter::{repeat_with, FromIterator, FusedIterator};
use core::mem;
use core::iter::{once, repeat_with, FromIterator, FusedIterator};
use core::mem::{self, replace};
use core::ops::Bound::{Excluded, Included, Unbounded};
use core::ops::{Index, IndexMut, RangeBounds, Try};
use core::ptr::{self, NonNull};
Expand Down Expand Up @@ -57,11 +57,88 @@ pub struct VecDeque<T> {
buf: RawVec<T>,
}

/// PairSlices pairs up equal length slice parts of two deques
///
/// For example, given deques "A" and "B" with the following division into slices:
///
/// A: [0 1 2] [3 4 5]
/// B: [a b] [c d e]
///
/// It produces the following sequence of matching slices:
///
/// ([0 1], [a b])
/// ([2], [c])
/// ([3 4], [d e])
///
/// and the uneven remainder of either A or B is skipped.
struct PairSlices<'a, 'b, T> {
a0: &'a mut [T],
a1: &'a mut [T],
b0: &'b [T],
b1: &'b [T],
}

impl<'a, 'b, T> PairSlices<'a, 'b, T> {
fn from(to: &'a mut VecDeque<T>, from: &'b VecDeque<T>) -> Self {
let (a0, a1) = to.as_mut_slices();
let (b0, b1) = from.as_slices();
PairSlices { a0, a1, b0, b1 }
}

fn has_remainder(&self) -> bool {
!self.b0.is_empty()
}

fn remainder(self) -> impl Iterator<Item=&'b [T]> {
once(self.b0).chain(once(self.b1))
}
}

impl<'a, 'b, T> Iterator for PairSlices<'a, 'b, T>
{
type Item = (&'a mut [T], &'b [T]);
fn next(&mut self) -> Option<Self::Item> {
// Get next part length
let part = cmp::min(self.a0.len(), self.b0.len());
if part == 0 {
return None;
}
let (p0, p1) = replace(&mut self.a0, &mut []).split_at_mut(part);
let (q0, q1) = self.b0.split_at(part);

// Move a1 into a0, if it's empty (and b1, b0 the same way).
self.a0 = p1;
self.b0 = q1;
if self.a0.is_empty() {
self.a0 = replace(&mut self.a1, &mut []);
}
if self.b0.is_empty() {
self.b0 = replace(&mut self.b1, &[]);
}
Some((p0, q0))
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Clone> Clone for VecDeque<T> {
fn clone(&self) -> VecDeque<T> {
self.iter().cloned().collect()
}

fn clone_from(&mut self, other: &Self) {
self.truncate(other.len());

let mut iter = PairSlices::from(self, other);
while let Some((dst, src)) = iter.next() {
dst.clone_from_slice(&src);
}

if iter.has_remainder() {
for remainder in iter.remainder() {
self.extend(remainder.iter().cloned());
}
}
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -2209,6 +2286,16 @@ impl<'a, T> Iterator for Iter<'a, T> {
final_res
}

fn nth(&mut self, n: usize) -> Option<Self::Item> {
if n >= count(self.tail, self.head, self.ring.len()) {
self.tail = self.head;
None
} else {
self.tail = wrap_index(self.tail.wrapping_add(n), self.ring.len());
self.next()
}
}

#[inline]
fn last(mut self) -> Option<&'a T> {
self.next_back()
Expand Down Expand Up @@ -2327,6 +2414,16 @@ impl<'a, T> Iterator for IterMut<'a, T> {
back.iter_mut().fold(accum, &mut f)
}

fn nth(&mut self, n: usize) -> Option<Self::Item> {
if n >= count(self.tail, self.head, self.ring.len()) {
self.tail = self.head;
None
} else {
self.tail = wrap_index(self.tail.wrapping_add(n), self.ring.len());
self.next()
}
}

#[inline]
fn last(mut self) -> Option<&'a mut T> {
self.next_back()
Expand Down
23 changes: 23 additions & 0 deletions src/liballoc/collections/vec_deque/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,29 @@ fn test_vec_from_vecdeque() {
}
}

#[test]
fn test_clone_from() {
let m = vec![1; 8];
let n = vec![2; 12];
for pfv in 0..8 {
for pfu in 0..8 {
for longer in 0..2 {
let (vr, ur) = if longer == 0 { (&m, &n) } else { (&n, &m) };
let mut v = VecDeque::from(vr.clone());
for _ in 0..pfv {
v.push_front(1);
}
let mut u = VecDeque::from(ur.clone());
for _ in 0..pfu {
u.push_front(2);
}
v.clone_from(&u);
assert_eq!(&v, &u);
}
}
}
}

#[test]
fn issue_53529() {
use crate::boxed::Box;
Expand Down
Loading