Skip to content

Rollup of 12 pull requests #67648

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
01599fc
note other end-point when typeck range pats
Centril Dec 13, 2019
e77b9d3
refactor parse_field
Centril Dec 4, 2019
8480b31
extract recover_struct_comma_after_dotdot
Centril Dec 4, 2019
701b974
extract find_struct_error_after_field_looking_code
Centril Dec 4, 2019
66b8ae4
extract error_struct_lit_not_allowed_here
Centril Dec 4, 2019
f6e2bdc
extract is_certainly_not_a_block
Centril Dec 4, 2019
de2e443
make parse_async_block conventional
Centril Dec 6, 2019
7262dcc
refactor loop parsing a bit
Centril Dec 6, 2019
44ff4df
more recovery in if-parsing
Centril Dec 6, 2019
7bcc325
refactor parse_if_expr
Centril Dec 6, 2019
ad6f91a
refactor parse_fn_block_param
Centril Dec 6, 2019
f647c11
simplify parse_fn_block_decl
Centril Dec 6, 2019
aa8adba
simplify parse_literal_maybe_minus
Centril Dec 6, 2019
0bb3dad
extract error_float_lits-must_have_int_part
Centril Dec 6, 2019
98701b2
extract parse_index_expr & refactor parse_dot_suffix
Centril Dec 6, 2019
287ba5d
extract parse_fn_call_expr
Centril Dec 6, 2019
a15d0cd
extract parse_tuple_field_access_expr
Centril Dec 6, 2019
ff5762b
extract recover_field_access_by_float_lit
Centril Dec 6, 2019
9c6bbf1
extract error_unexpected_after_dot and de-fatalize
Centril Dec 6, 2019
bc95228
extract parse_dot_suffix_expr
Centril Dec 7, 2019
7ae12c9
extract parse_dot_base_expr
Centril Dec 7, 2019
af5ac23
simplify parse_dot_call_or_expr
Centril Dec 7, 2019
84f9bf1
refactor parse_address_of -> parse_borrow_expr
Centril Dec 7, 2019
00cc8a1
simplify parse_assoc_op_cast
Centril Dec 7, 2019
80eeefb
extract recover_not_expr
Centril Dec 7, 2019
ada388b
extract is_mistaken_not_ident_negation
Centril Dec 7, 2019
f6ab439
extract parse_deref_expr
Centril Dec 7, 2019
4cfcfe9
extract parse_neg_expr
Centril Dec 7, 2019
efdea63
extract parse_prefix_expr
Centril Dec 7, 2019
8456c40
extract parse_not_expr
Centril Dec 7, 2019
e43a7ef
simplify parse_prefix_range_expr
Centril Dec 7, 2019
05c26a4
refactor assoc op parsing
Centril Dec 7, 2019
7a246ac
fix rebase fallout
Centril Dec 23, 2019
3c56a65
reuse `capacity` variable in slice::repeat
king6cong Dec 24, 2019
43cb37e
Use issue = "none" instead of "0" in intrinsics
KamilaBorowska Dec 25, 2019
b98633b
Store callbacks in global statics
Mark-Simulacrum Dec 25, 2019
4dcc627
Fix skipped setting of syntax::GLOBALS
Mark-Simulacrum Dec 25, 2019
b8ccc0f
Remove `compiler_builtins_lib` documentation
kraai Dec 25, 2019
21e636f
Remove redundant link texts
kraai Dec 26, 2019
2f43313
Convert collapsed to shortcut reference links
kraai Dec 26, 2019
be9a3c6
Update .mailmap
pvdrz Dec 26, 2019
9c0f3f7
Document safety of Path casting
Mark-Simulacrum Dec 26, 2019
e3c814e
prune ill-conceived BTreeMap iter_mut assertion and test more
ssomers Dec 20, 2019
1e40681
Don't ICE on the use of integer addresses for ZST constants in patter…
oli-obk Dec 13, 2019
b5b5258
Retire `to_ptr` which should already have no users but still kept get…
oli-obk Dec 13, 2019
bb1ecee
Simplify `force_allocation_maybe_sized`
oli-obk Dec 13, 2019
13694de
Comment on a few odd things that we should look at
oli-obk Dec 13, 2019
a0bd1a6
Prevent an ICE on invalid transmutes
oli-obk Dec 13, 2019
0e969b7
Interning even happens when validation of a constant fails
oli-obk Dec 14, 2019
a7a011d
Immediately evaluate and validate constants when we want them as oper…
oli-obk Dec 20, 2019
6b651b1
Add regression test for ZST statics being allowed to "read" from them…
oli-obk Dec 20, 2019
41d5818
Explain ParamEnv::reveal_all usage
oli-obk Dec 22, 2019
8a88ff1
Comments should start capitalized and end in a period
oli-obk Dec 22, 2019
cb8d1c3
Explain what we are doing with parameter environments for statics
oli-obk Dec 22, 2019
6937ca2
Explain the currently necessary existance of `TransmuteSizeDiff`
oli-obk Dec 22, 2019
72ebce0
Remove unintended noisy log statement
oli-obk Dec 22, 2019
0e3fafa
Typo
oli-obk Dec 22, 2019
9520551
Explain why `const_eval` is ok here
oli-obk Dec 22, 2019
1acbf4b
Early abort instead of building up zero sized values
oli-obk Dec 22, 2019
20c1b3f
Add a `const_eval` helper to `InterpCx`
oli-obk Dec 22, 2019
1531c39
Documentation nit
oli-obk Dec 22, 2019
b476344
Reintroduce the recursion comment
oli-obk Dec 22, 2019
aaffe12
Use the targetted const eval functions
oli-obk Dec 23, 2019
12a4c2c
Fix rebase fallout
oli-obk Dec 23, 2019
f65a91e
Make ui test bitwidth independent
oli-obk Dec 24, 2019
143f62f
Rollup merge of #67112 - Centril:expr-polish, r=estebank
Mark-Simulacrum Dec 26, 2019
0db3e03
Rollup merge of #67192 - oli-obk:const_zst_addr, r=RalfJung,varkor
Mark-Simulacrum Dec 26, 2019
2896a4c
Rollup merge of #67287 - Centril:mismatch-range-improve-diag, r=estebank
Mark-Simulacrum Dec 26, 2019
6ef9970
Rollup merge of #67459 - ssomers:#67438, r=RalfJung
Mark-Simulacrum Dec 26, 2019
ae68d83
Rollup merge of #67576 - king6cong:slice_repeat, r=Dylan-DPC
Mark-Simulacrum Dec 26, 2019
6f7b2c7
Rollup merge of #67602 - xfix:use-issue-none-instead-of-0-in-intrinsi…
Mark-Simulacrum Dec 26, 2019
d6a0826
Rollup merge of #67614 - Mark-Simulacrum:global-callbacks, r=Zoxc
Mark-Simulacrum Dec 26, 2019
67468b7
Rollup merge of #67617 - kraai:remove-compiler_builtins_lib-docs, r=D…
Mark-Simulacrum Dec 26, 2019
bcdc0a7
Rollup merge of #67629 - kraai:remove-redundant-link-texts, r=stevekl…
Mark-Simulacrum Dec 26, 2019
d619606
Rollup merge of #67632 - kraai:remove-collapsed-reference-links, r=st…
Mark-Simulacrum Dec 26, 2019
6a827fb
Rollup merge of #67633 - christianpoveda:patch-1, r=Mark-Simulacrum
Mark-Simulacrum Dec 26, 2019
bcb7553
Rollup merge of #67635 - Mark-Simulacrum:path-doc-unsafe, r=dtolnay
Mark-Simulacrum Dec 26, 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
7 changes: 4 additions & 3 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ Chris C Cerami <chrisccerami@users.noreply.github.com> Chris C Cerami <chrisccer
Chris Pressey <cpressey@gmail.com>
Chris Thorn <chris@thorn.co> Chris Thorn <thorn@thoughtbot.com>
Chris Vittal <christopher.vittal@gmail.com> Christopher Vittal <christopher.vittal@gmail.com>
Christian Poveda <christianpoveda@protonmail.com> <cn.poveda.ruiz@gmail.com>
Christian Poveda <christianpoveda@protonmail.com> <z1mvader@protonmail.com>
Christian Poveda <christianpoveda@protonmail.com> <cpovedar@fnal.gov>
Christian Poveda <git@christianpoveda.xyz> <christianpoveda@protonmail.com>
Christian Poveda <git@christianpoveda.xyz> <cn.poveda.ruiz@gmail.com>
Christian Poveda <git@christianpoveda.xyz> <z1mvader@protonmail.com>
Christian Poveda <git@christianpoveda.xyz> <cpovedar@fnal.gov>
Clark Gaebel <cg.wowus.cg@gmail.com> <cgaebel@mozilla.com>
Clinton Ryan <clint.ryan3@gmail.com>
Corey Richardson <corey@octayn.net> Elaine "See More" Nemo <corey@octayn.net>
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ labels to triage issues:
to fix the issue.

* The dark blue **final-comment-period** label marks bugs that are using the
RFC signoff functionality of [rfcbot][rfcbot] and are currently in the final
RFC signoff functionality of [rfcbot] and are currently in the final
comment period.

* Red, **I**-prefixed labels indicate the **importance** of the issue. The
Expand All @@ -385,7 +385,7 @@ labels to triage issues:
label.

* The gray **proposed-final-comment-period** label marks bugs that are using
the RFC signoff functionality of [rfcbot][rfcbot] and are currently awaiting
the RFC signoff functionality of [rfcbot] and are currently awaiting
signoff of all team members in order to enter the final comment period.

* Pink, **regression**-prefixed labels track regressions from stable to the
Expand Down
28 changes: 14 additions & 14 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4951,10 +4951,10 @@ Stabilized APIs
---------------

* [`std::panic`]
* [`std::panic::catch_unwind`][] (renamed from `recover`)
* [`std::panic::resume_unwind`][] (renamed from `propagate`)
* [`std::panic::AssertUnwindSafe`][] (renamed from `AssertRecoverSafe`)
* [`std::panic::UnwindSafe`][] (renamed from `RecoverSafe`)
* [`std::panic::catch_unwind`] (renamed from `recover`)
* [`std::panic::resume_unwind`] (renamed from `propagate`)
* [`std::panic::AssertUnwindSafe`] (renamed from `AssertRecoverSafe`)
* [`std::panic::UnwindSafe`] (renamed from `RecoverSafe`)
* [`str::is_char_boundary`]
* [`<*const T>::as_ref`]
* [`<*mut T>::as_ref`]
Expand Down Expand Up @@ -5234,18 +5234,18 @@ Libraries
---------

* Stabilized APIs:
* [`str::encode_utf16`][] (renamed from `utf16_units`)
* [`str::EncodeUtf16`][] (renamed from `Utf16Units`)
* [`str::encode_utf16`] (renamed from `utf16_units`)
* [`str::EncodeUtf16`] (renamed from `Utf16Units`)
* [`Ref::map`]
* [`RefMut::map`]
* [`ptr::drop_in_place`]
* [`time::Instant`]
* [`time::SystemTime`]
* [`Instant::now`]
* [`Instant::duration_since`][] (renamed from `duration_from_earlier`)
* [`Instant::duration_since`] (renamed from `duration_from_earlier`)
* [`Instant::elapsed`]
* [`SystemTime::now`]
* [`SystemTime::duration_since`][] (renamed from `duration_from_earlier`)
* [`SystemTime::duration_since`] (renamed from `duration_from_earlier`)
* [`SystemTime::elapsed`]
* Various `Add`/`Sub` impls for `Time` and `SystemTime`
* [`SystemTimeError`]
Expand Down Expand Up @@ -5432,8 +5432,8 @@ Libraries

* Stabilized APIs
* `Path`
* [`Path::strip_prefix`][] (renamed from relative_from)
* [`path::StripPrefixError`][] (new error type returned from strip_prefix)
* [`Path::strip_prefix`] (renamed from relative_from)
* [`path::StripPrefixError`] (new error type returned from strip_prefix)
* `Ipv4Addr`
* [`Ipv4Addr::is_loopback`]
* [`Ipv4Addr::is_private`]
Expand Down Expand Up @@ -5646,7 +5646,7 @@ Libraries

* Stabilized APIs:
[`Read::read_exact`],
[`ErrorKind::UnexpectedEof`][] (renamed from `UnexpectedEOF`),
[`ErrorKind::UnexpectedEof`] (renamed from `UnexpectedEOF`),
[`fs::DirBuilder`], [`fs::DirBuilder::new`],
[`fs::DirBuilder::recursive`], [`fs::DirBuilder::create`],
[`os::unix::fs::DirBuilderExt`],
Expand All @@ -5659,11 +5659,11 @@ Libraries
[`collections::hash_set::HashSet::drain`],
[`collections::binary_heap::Drain`],
[`collections::binary_heap::BinaryHeap::drain`],
[`Vec::extend_from_slice`][] (renamed from `push_all`),
[`Vec::extend_from_slice`] (renamed from `push_all`),
[`Mutex::get_mut`], [`Mutex::into_inner`], [`RwLock::get_mut`],
[`RwLock::into_inner`],
[`Iterator::min_by_key`][] (renamed from `min_by`),
[`Iterator::max_by_key`][] (renamed from `max_by`).
[`Iterator::min_by_key`] (renamed from `min_by`),
[`Iterator::max_by_key`] (renamed from `max_by`).
* The [core library][1.6co] is stable, as are most of its APIs.
* [The `assert_eq!` macro supports arguments that don't implement
`Sized`][1.6ae], such as arrays. In this way it behaves more like
Expand Down
6 changes: 1 addition & 5 deletions src/doc/unstable-book/src/language-features/lang-items.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,7 @@ pub extern fn rust_begin_panic(info: &PanicInfo) -> ! {

In many cases, you may need to manually link to the `compiler_builtins` crate
when building a `no_std` binary. You may observe this via linker error messages
such as "```undefined reference to `__rust_probestack'```". Using this crate
also requires enabling the library feature `compiler_builtins_lib`. You can read
more about this [here][compiler-builtins-lib].

[compiler-builtins-lib]: ../library-features/compiler-builtins-lib.md
such as "```undefined reference to `__rust_probestack'```".

## More about the language items

Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion src/liballoc/collections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ impl<T> FusedIterator for Iter<'_, T> {}

/// An owning iterator over the elements of a `BinaryHeap`.
///
/// This `struct` is created by the [`into_iter`] method on [`BinaryHeap`][`BinaryHeap`]
/// This `struct` is created by the [`into_iter`] method on [`BinaryHeap`]
/// (provided by the `IntoIterator` trait). See its documentation for more.
///
/// [`into_iter`]: struct.BinaryHeap.html#method.into_iter
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ pub struct IterMut<'a, K: 'a, V: 'a> {

/// An owning iterator over the entries of a `BTreeMap`.
///
/// This `struct` is created by the [`into_iter`] method on [`BTreeMap`][`BTreeMap`]
/// This `struct` is created by the [`into_iter`] method on [`BTreeMap`]
/// (provided by the `IntoIterator` trait). See its documentation for more.
///
/// [`into_iter`]: struct.BTreeMap.html#method.into_iter
Expand Down
54 changes: 30 additions & 24 deletions src/liballoc/collections/btree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ impl<'a, K, V, Type> NodeRef<marker::Mut<'a>, K, V, Type> {

/// Returns a raw ptr to avoid asserting exclusive access to the entire node.
fn as_leaf_mut(&mut self) -> *mut LeafNode<K, V> {
// We are mutable, so we cannot be the root, so accessing this as a leaf is okay.
// We are mutable, so we cannot be the shared root, so accessing this as a leaf is okay.
self.node.as_ptr()
}

Expand All @@ -514,33 +514,37 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Immut<'a>, K, V, Type> {
// but we want to avoid that run-time check.
// Instead, we create a slice pointing into the node whenever possible.
// We can sometimes do this even for the shared root, as the slice will be
// empty. We cannot *always* do this because if the type is too highly
// aligned, the offset of `keys` in a "full node" might be outside the bounds
// of the header! So we do an alignment check first, that will be
// evaluated at compile-time, and only do any run-time check in the rare case
// that the alignment is very big.
if mem::align_of::<K>() > mem::align_of::<LeafNode<(), ()>>() && self.is_shared_root() {
// empty and `NodeHeader` contains an empty `keys_start` array.
// We cannot *always* do this because:
// - `keys_start` is not correctly typed because we want `NodeHeader`'s size to
// not depend on the alignment of `K` (needed because `as_header` should be safe).
// For this reason, `NodeHeader` has this `K2` parameter (that's usually `()`
// and hence just adds a size-0-align-1 field, not affecting layout).
// If the correctly typed header is more highly aligned than the allocated header,
// we cannot transmute safely.
// - Even if we can transmute, the offset of a correctly typed `keys_start` might
// be different and outside the bounds of the allocated header!
// So we do an alignment check and a size check first, that will be evaluated
// at compile-time, and only do any run-time check in the rare case that
// the compile-time checks signal danger.
if (mem::align_of::<NodeHeader<K, V, K>>() > mem::align_of::<NodeHeader<K, V>>()
|| mem::size_of::<NodeHeader<K, V, K>>() != mem::size_of::<NodeHeader<K, V>>())
&& self.is_shared_root()
{
&[]
} else {
// Thanks to the alignment check above, we know that `keys` will be
// If we are a `LeafNode<K, V>`, we can always transmute to
// `NodeHeader<K, V, K>` and `keys_start` always has the same offset
// as the actual `keys`.
// Thanks to the checks above, we know that we can transmute to
// `NodeHeader<K, V, K>` and that `keys_start` will be
// in-bounds of some allocation even if this is the shared root!
// (We might be one-past-the-end, but that is allowed by LLVM.)
// Getting the pointer is tricky though. `NodeHeader` does not have a `keys`
// field because we want its size to not depend on the alignment of `K`
// (needed because `as_header` should be safe). We cannot call `as_leaf`
// because we might be the shared root.
// For this reason, `NodeHeader` has this `K2` parameter (that's usually `()`
// and hence just adds a size-0-align-1 field, not affecting layout).
// We know that we can transmute `NodeHeader<K, V, ()>` to `NodeHeader<K, V, K>`
// because we did the alignment check above, and hence `NodeHeader<K, V, K>`
// is not bigger than `NodeHeader<K, V, ()>`! Then we can use `NodeHeader<K, V, K>`
// Thus we can use `NodeHeader<K, V, K>`
// to compute the pointer where the keys start.
// This entire hack will become unnecessary once
// <https://github.com/rust-lang/rfcs/pull/2582> lands, then we can just take a raw
// pointer to the `keys` field of `*const InternalNode<K, V>`.

// This is a non-debug-assert because it can be completely compile-time evaluated.
assert!(mem::size_of::<NodeHeader<K, V>>() == mem::size_of::<NodeHeader<K, V, K>>());
let header = self.as_header() as *const _ as *const NodeHeader<K, V, K>;
let keys = unsafe { &(*header).keys_start as *const _ as *const K };
unsafe { slice::from_raw_parts(keys, self.len()) }
Expand All @@ -549,7 +553,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Immut<'a>, K, V, Type> {

fn into_val_slice(self) -> &'a [V] {
debug_assert!(!self.is_shared_root());
// We cannot be the root, so `as_leaf` is okay
// We cannot be the shared root, so `as_leaf` is okay
unsafe { slice::from_raw_parts(MaybeUninit::first_ptr(&self.as_leaf().vals), self.len()) }
}

Expand All @@ -567,9 +571,11 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
}

fn into_key_slice_mut(mut self) -> &'a mut [K] {
// Same as for `into_key_slice` above, we try to avoid a run-time check
// (the alignment comparison will usually be performed at compile-time).
if mem::align_of::<K>() > mem::align_of::<LeafNode<(), ()>>() && self.is_shared_root() {
// Same as for `into_key_slice` above, we try to avoid a run-time check.
if (mem::align_of::<NodeHeader<K, V, K>>() > mem::align_of::<NodeHeader<K, V>>()
|| mem::size_of::<NodeHeader<K, V, K>>() != mem::size_of::<NodeHeader<K, V>>())
&& self.is_shared_root()
{
&mut []
} else {
unsafe {
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/collections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl<T: fmt::Debug> fmt::Debug for Iter<'_, T> {

/// An owning iterator over the items of a `BTreeSet`.
///
/// This `struct` is created by the [`into_iter`] method on [`BTreeSet`][`BTreeSet`]
/// This `struct` is created by the [`into_iter`] method on [`BTreeSet`]
/// (provided by the `IntoIterator` trait). See its documentation for more.
///
/// [`BTreeSet`]: struct.BTreeSet.html
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/collections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<T: fmt::Debug> fmt::Debug for IterMut<'_, T> {

/// An owning iterator over the elements of a `LinkedList`.
///
/// This `struct` is created by the [`into_iter`] method on [`LinkedList`][`LinkedList`]
/// This `struct` is created by the [`into_iter`] method on [`LinkedList`]
/// (provided by the `IntoIterator` trait). See its documentation for more.
///
/// [`into_iter`]: struct.LinkedList.html#method.into_iter
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/collections/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2474,7 +2474,7 @@ impl<T> FusedIterator for IterMut<'_, T> {}

/// An owning iterator over the elements of a `VecDeque`.
///
/// This `struct` is created by the [`into_iter`] method on [`VecDeque`][`VecDeque`]
/// This `struct` is created by the [`into_iter`] method on [`VecDeque`]
/// (provided by the `IntoIterator` trait). See its documentation for more.
///
/// [`into_iter`]: struct.VecDeque.html#method.into_iter
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@
//!
//! Additionally, the return value of this function is [`fmt::Result`] which is a
//! type alias of [`Result`]`<(), `[`std::fmt::Error`]`>`. Formatting implementations
//! should ensure that they propagate errors from the [`Formatter`][`Formatter`] (e.g., when
//! should ensure that they propagate errors from the [`Formatter`] (e.g., when
//! calling [`write!`]). However, they should never return errors spuriously. That
//! is, a formatting implementation must and may only return an error if the
//! passed-in [`Formatter`] returns an error. This is because, contrary to what
Expand Down
8 changes: 4 additions & 4 deletions src/liballoc/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,8 @@ impl<T> [T] {
// and `rem` is the remaining part of `n`.

// Using `Vec` to access `set_len()`.
let mut buf = Vec::with_capacity(self.len().checked_mul(n).expect("capacity overflow"));
let capacity = self.len().checked_mul(n).expect("capacity overflow");
let mut buf = Vec::with_capacity(capacity);

// `2^expn` repetition is done by doubling `buf` `expn`-times.
buf.extend(self);
Expand All @@ -476,7 +477,7 @@ impl<T> [T] {

// `rem` (`= n - 2^expn`) repetition is done by copying
// first `rem` repetitions from `buf` itself.
let rem_len = self.len() * n - buf.len(); // `self.len() * rem`
let rem_len = capacity - buf.len(); // `self.len() * rem`
if rem_len > 0 {
// `buf.extend(buf[0 .. rem_len])`:
unsafe {
Expand All @@ -487,8 +488,7 @@ impl<T> [T] {
rem_len,
);
// `buf.len() + rem_len` equals to `buf.capacity()` (`= self.len() * n`).
let buf_cap = buf.capacity();
buf.set_len(buf_cap);
buf.set_len(capacity);
}
}
buf
Expand Down
Loading