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 14 pull requests #63309

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
56ebfb1
Implement DoubleEndedIterator for iter::{StepBy, Peekable, Take}
timvermeulen Jun 2, 2019
3b15b16
Explaining the reason why validation is performed in to_str of path.rs
JasonShin Aug 1, 2019
1aa4a57
Update src/libstd/path.rs to shorten the explanation for .to_str vali…
JasonShin Aug 1, 2019
83b5eb9
Always error on `SizeOverflow` during mir evaluation
estebank Jul 31, 2019
58bd878
Do not lint on SizeOverflow, always error
estebank Jul 31, 2019
d3da411
Nicer labels for type layout errors
estebank Jul 31, 2019
dad56c3
Add {IoSlice, IoSliceMut}::advance
Thomasdezeeuw Jul 25, 2019
2c56842
avoid mutable state and override main message
estebank Aug 3, 2019
50b258b
diagnostics: Describe crate root modules in `DefKind::Mod` as "crate"
petrochenkov Aug 3, 2019
db099fb
Point to local place span on "type too big" error
estebank Aug 3, 2019
2340067
Simplify change to layout_of
estebank Aug 4, 2019
416caa1
Add test for issue-29265
JohnTitor Aug 4, 2019
620567d
Add test for issue-49544
JohnTitor Aug 4, 2019
92e4e8e
Add test for issue-37433
JohnTitor Aug 4, 2019
0d15845
fix UB in a test
RalfJung Aug 4, 2019
95f29aa
Revert "Rollup merge of #62696 - chocol4te:fix_#62194, r=estebank"
arielb1 Aug 4, 2019
387dcff
review comments: clean up
estebank Aug 4, 2019
bdd79b8
tweak output and tests
estebank Aug 4, 2019
f621f89
revert change to single test
estebank Aug 4, 2019
a0685a9
fix tests
estebank Aug 5, 2019
4e51ef7
Test content, not value
RalfJung Aug 5, 2019
b5e35b1
remove special code path for unknown tokens
matklad Jul 30, 2019
58ac81a
add unknown token
matklad Jul 30, 2019
b3e8c8b
adapt rustdoc to infailable lexer
matklad Jul 30, 2019
ab3fb1e
Drop span argument from mk_list_item
Mark-Simulacrum Aug 4, 2019
24a491f
Drop explicit span argument from mk_name_value_item
Mark-Simulacrum Aug 4, 2019
8849149
Make mk_attr_id private to libsyntax
Mark-Simulacrum Aug 4, 2019
fbf93d4
Remove leftover AwaitOrigin
Mark-Simulacrum Aug 5, 2019
90b95cf
fix slice comparison
RalfJung Aug 5, 2019
288b4e9
Don't store &Span
Mark-Simulacrum Aug 5, 2019
1f01863
improve align_offset docs
RalfJung Aug 5, 2019
30910ee
Make qualify consts in_projection use PlaceRef
spastorino Aug 5, 2019
2260c90
Rollup merge of #61457 - timvermeulen:double_ended_iters, r=scottmcm
Centril Aug 5, 2019
2e290d3
Rollup merge of #62987 - Thomasdezeeuw:ioslice-advance, r=Thomasdezeeuw
Centril Aug 5, 2019
0aa4a47
Rollup merge of #63017 - matklad:no-fatal, r=petrochenkov
Centril Aug 5, 2019
8f6d31a
Rollup merge of #63152 - estebank:big-array, r=oli-obk
Centril Aug 5, 2019
0599f20
Rollup merge of #63184 - JasonShin:master, r=sfackler
Centril Aug 5, 2019
e690f35
Rollup merge of #63250 - petrochenkov:descrate, r=davidtwco
Centril Aug 5, 2019
b428453
Rollup merge of #63259 - JohnTitor:add-tests-for-some-issues, r=Centril
Centril Aug 5, 2019
2ddc0c9
Rollup merge of #63260 - RalfJung:ptr-test, r=matklad
Centril Aug 5, 2019
814ccee
Rollup merge of #63264 - arielb1:revert-private-coherence-errors, r=e…
Centril Aug 5, 2019
8a2f612
Rollup merge of #63272 - Mark-Simulacrum:clean-attr, r=petrochenkov
Centril Aug 5, 2019
cfc95ed
Rollup merge of #63285 - Mark-Simulacrum:rm-await-origin, r=Centril
Centril Aug 5, 2019
2eaa3fd
Rollup merge of #63287 - Mark-Simulacrum:span-no-ref, r=Centril
Centril Aug 5, 2019
e57a493
Rollup merge of #63295 - RalfJung:align_offset, r=dtolnay
Centril Aug 5, 2019
619ed36
Rollup merge of #63299 - spastorino:in-projection-use-ref, r=oli-obk
Centril Aug 5, 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
117 changes: 117 additions & 0 deletions src/libcore/iter/adapters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,39 @@ impl<I> Iterator for StepBy<I> where I: Iterator {
}
}

impl<I> StepBy<I> where I: ExactSizeIterator {
// The zero-based index starting from the end of the iterator of the
// last element. Used in the `DoubleEndedIterator` implementation.
fn next_back_index(&self) -> usize {
let rem = self.iter.len() % (self.step + 1);
if self.first_take {
if rem == 0 { self.step } else { rem - 1 }
} else {
rem
}
}
}

#[stable(feature = "double_ended_step_by_iterator", since = "1.38.0")]
impl<I> DoubleEndedIterator for StepBy<I> where I: DoubleEndedIterator + ExactSizeIterator {
#[inline]
fn next_back(&mut self) -> Option<Self::Item> {
self.iter.nth_back(self.next_back_index())
}

#[inline]
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
// `self.iter.nth_back(usize::MAX)` does the right thing here when `n`
// is out of bounds because the length of `self.iter` does not exceed
// `usize::MAX` (because `I: ExactSizeIterator`) and `nth_back` is
// zero-indexed
let n = n
.saturating_mul(self.step + 1)
.saturating_add(self.next_back_index());
self.iter.nth_back(n)
}
}

// StepBy can only make the iterator shorter, so the len will still fit.
#[stable(feature = "iterator_step_by", since = "1.28.0")]
impl<I> ExactSizeIterator for StepBy<I> where I: ExactSizeIterator {}
Expand Down Expand Up @@ -1158,6 +1191,45 @@ impl<I: Iterator> Iterator for Peekable<I> {
}
}

#[stable(feature = "double_ended_peek_iterator", since = "1.38.0")]
impl<I> DoubleEndedIterator for Peekable<I> where I: DoubleEndedIterator {
#[inline]
fn next_back(&mut self) -> Option<Self::Item> {
self.iter.next_back().or_else(|| self.peeked.take().and_then(|x| x))
}

#[inline]
fn try_rfold<B, F, R>(&mut self, init: B, mut f: F) -> R where
Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try<Ok=B>
{
match self.peeked.take() {
Some(None) => return Try::from_ok(init),
Some(Some(v)) => match self.iter.try_rfold(init, &mut f).into_result() {
Ok(acc) => f(acc, v),
Err(e) => {
self.peeked = Some(Some(v));
Try::from_error(e)
}
},
None => self.iter.try_rfold(init, f),
}
}

#[inline]
fn rfold<Acc, Fold>(self, init: Acc, mut fold: Fold) -> Acc
where Fold: FnMut(Acc, Self::Item) -> Acc,
{
match self.peeked {
Some(None) => return init,
Some(Some(v)) => {
let acc = self.iter.rfold(init, &mut fold);
fold(acc, v)
}
None => self.iter.rfold(init, fold),
}
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<I: ExactSizeIterator> ExactSizeIterator for Peekable<I> {}

Expand Down Expand Up @@ -1627,6 +1699,51 @@ impl<I> Iterator for Take<I> where I: Iterator{
}
}

#[stable(feature = "double_ended_take_iterator", since = "1.38.0")]
impl<I> DoubleEndedIterator for Take<I> where I: DoubleEndedIterator + ExactSizeIterator {
#[inline]
fn next_back(&mut self) -> Option<Self::Item> {
if self.n == 0 {
None
} else {
let n = self.n;
self.n -= 1;
self.iter.nth_back(self.iter.len().saturating_sub(n))
}
}

#[inline]
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
let len = self.iter.len();
if self.n > n {
let m = len.saturating_sub(self.n) + n;
self.n -= n + 1;
self.iter.nth_back(m)
} else {
if len > 0 {
self.iter.nth_back(len - 1);
}
None
}
}

#[inline]
fn try_rfold<Acc, Fold, R>(&mut self, init: Acc, fold: Fold) -> R where
Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, R: Try<Ok = Acc>
{
if self.n == 0 {
Try::from_ok(init)
} else {
let len = self.iter.len();
if len > self.n && self.iter.nth_back(len - self.n - 1).is_none() {
Try::from_ok(init)
} else {
self.iter.try_rfold(init, fold)
}
}
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<I> ExactSizeIterator for Take<I> where I: ExactSizeIterator {}

Expand Down
12 changes: 8 additions & 4 deletions src/libcore/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1606,10 +1606,12 @@ impl<T: ?Sized> *const T {
/// `align`.
///
/// If it is not possible to align the pointer, the implementation returns
/// `usize::max_value()`.
/// `usize::max_value()`. It is permissible for the implementation to *always*
/// return `usize::max_value()`. Only your algorithm's performance can depend
/// on getting a usable offset here, not its correctness.
///
/// The offset is expressed in number of `T` elements, and not bytes. The value returned can be
/// used with the `add` method.
/// used with the `wrapping_add` method.
///
/// There are no guarantees whatsoever that offsetting the pointer will not overflow or go
/// beyond the allocation that the pointer points into. It is up to the caller to ensure that
Expand Down Expand Up @@ -2407,10 +2409,12 @@ impl<T: ?Sized> *mut T {
/// `align`.
///
/// If it is not possible to align the pointer, the implementation returns
/// `usize::max_value()`.
/// `usize::max_value()`. It is permissible for the implementation to *always*
/// return `usize::max_value()`. Only your algorithm's performance can depend
/// on getting a usable offset here, not its correctness.
///
/// The offset is expressed in number of `T` elements, and not bytes. The value returned can be
/// used with the `add` method.
/// used with the `wrapping_add` method.
///
/// There are no guarantees whatsoever that offsetting the pointer will not overflow or go
/// beyond the allocation that the pointer points into. It is up to the caller to ensure that
Expand Down
Loading