Skip to content

Commit 088b987

Browse files
committed
Auto merge of rust-lang#62335 - Mark-Simulacrum:rollup-0pcaz5a, r=Mark-Simulacrum
Rollup of 15 pull requests Successful merges: - rust-lang#62021 (MSVC link output improve) - rust-lang#62064 (nth_back for chunks_exact) - rust-lang#62128 (Adjust warning of -C extra-filename with -o.) - rust-lang#62161 (Add missing links for TryFrom docs) - rust-lang#62183 (std: Move a process test out of libstd) - rust-lang#62186 (Add missing type urls in Into trait) - rust-lang#62196 (Add Vec::leak) - rust-lang#62199 (import gdb for explicit access to gdb.current_objfile()) - rust-lang#62229 (Enable intptrcast for explicit casts) - rust-lang#62250 (Improve box clone doctests to ensure the documentation is valid) - rust-lang#62255 (Switch tracking issue for `#![feature(slice_patterns)]`) - rust-lang#62285 (Fix michaelwoerister's mailmap) - rust-lang#62304 (HashMap is UnwindSafe) - rust-lang#62319 (Fix mismatching Kleene operators) - rust-lang#62327 (Fixed document bug, those replaced each other) Failed merges: r? @ghost
2 parents 8c6fb02 + 6b43b50 commit 088b987

File tree

22 files changed

+197
-84
lines changed

22 files changed

+197
-84
lines changed

.mailmap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ Matthijs Hofstra <thiezz@gmail.com>
167167
Melody Horn <melody@boringcactus.com> <mathphreak@gmail.com>
168168
Michael Williams <m.t.williams@live.com>
169169
Michael Woerister <michaelwoerister@posteo> <michaelwoerister@gmail>
170+
Michael Woerister <michaelwoerister@posteo> <michaelwoerister@users.noreply.github.com>
171+
Michael Woerister <michaelwoerister@posteo> <michaelwoerister@posteo.net>
170172
Mickaël Raybaud-Roig <raybaudroigm@gmail.com> m-r-r <raybaudroigm@gmail.com>
171173
Ms2ger <ms2ger@gmail.com> <Ms2ger@gmail.com>
172174
Mukilan Thiagarajan <mukilanthiagarajan@gmail.com>

src/doc/unstable-book/src/language-features/slice-patterns.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# `slice_patterns`
22

3-
The tracking issue for this feature is: [#23121]
3+
The tracking issue for this feature is: [#62254]
44

5-
[#23121]: https://github.com/rust-lang/rust/issues/23121
5+
[#62254]: https://github.com/rust-lang/rust/issues/62254
66

77
------------------------
88

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
import gdb
12
import gdb_rust_pretty_printing
23
gdb_rust_pretty_printing.register_printers(gdb.current_objfile())

src/liballoc/boxed.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,23 +367,35 @@ impl<T: Clone> Clone for Box<T> {
367367
/// ```
368368
/// let x = Box::new(5);
369369
/// let y = x.clone();
370+
///
371+
/// // The value is the same
372+
/// assert_eq!(x, y);
373+
///
374+
/// // But they are unique objects
375+
/// assert_ne!(&*x as *const i32, &*y as *const i32);
370376
/// ```
371377
#[rustfmt::skip]
372378
#[inline]
373379
fn clone(&self) -> Box<T> {
374380
box { (**self).clone() }
375381
}
382+
376383
/// Copies `source`'s contents into `self` without creating a new allocation.
377384
///
378385
/// # Examples
379386
///
380387
/// ```
381388
/// let x = Box::new(5);
382389
/// let mut y = Box::new(10);
390+
/// let yp: *const i32 = &*y;
383391
///
384392
/// y.clone_from(&x);
385393
///
386-
/// assert_eq!(*y, 5);
394+
/// // The value is the same
395+
/// assert_eq!(x, y);
396+
///
397+
/// // And no allocation occurred
398+
/// assert_eq!(yp, &*y);
387399
/// ```
388400
#[inline]
389401
fn clone_from(&mut self, source: &Box<T>) {

src/liballoc/vec.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,40 @@ impl<T> Vec<T> {
13671367
self.truncate(new_len);
13681368
}
13691369
}
1370+
1371+
/// Consumes and leaks the `Vec`, returning a mutable reference to the contents,
1372+
/// `&'a mut [T]`. Note that the type `T` must outlive the chosen lifetime
1373+
/// `'a`. If the type has only static references, or none at all, then this
1374+
/// may be chosen to be `'static`.
1375+
///
1376+
/// This function is similar to the `leak` function on `Box`.
1377+
///
1378+
/// This function is mainly useful for data that lives for the remainder of
1379+
/// the program's life. Dropping the returned reference will cause a memory
1380+
/// leak.
1381+
///
1382+
/// # Examples
1383+
///
1384+
/// Simple usage:
1385+
///
1386+
/// ```
1387+
/// #![feature(vec_leak)]
1388+
///
1389+
/// fn main() {
1390+
/// let x = vec![1, 2, 3];
1391+
/// let static_ref: &'static mut [usize] = Vec::leak(x);
1392+
/// static_ref[0] += 1;
1393+
/// assert_eq!(static_ref, &[2, 2, 3]);
1394+
/// }
1395+
/// ```
1396+
#[unstable(feature = "vec_leak", issue = "62195")]
1397+
#[inline]
1398+
pub fn leak<'a>(vec: Vec<T>) -> &'a mut [T]
1399+
where
1400+
T: 'a // Technically not needed, but kept to be explicit.
1401+
{
1402+
Box::leak(vec.into_boxed_slice())
1403+
}
13701404
}
13711405

13721406
impl<T: Clone> Vec<T> {

src/libcore/convert.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,12 @@ pub trait AsMut<T: ?Sized> {
251251
///
252252
/// # Examples
253253
///
254-
/// [`String`] implements `Into<Vec<u8>>`:
254+
/// [`String`] implements [`Into`]`<`[`Vec`]`<`[`u8`]`>>`:
255255
///
256256
/// In order to express that we want a generic function to take all arguments that can be
257257
/// converted to a specified type `T`, we can use a trait bound of [`Into`]`<T>`.
258258
/// For example: The function `is_hello` takes all arguments that can be converted into a
259-
/// `Vec<u8>`.
259+
/// [`Vec`]`<`[`u8`]`>`.
260260
///
261261
/// ```
262262
/// fn is_hello<T: Into<Vec<u8>>>(s: T) {
@@ -274,6 +274,7 @@ pub trait AsMut<T: ?Sized> {
274274
/// [`String`]: ../../std/string/struct.String.html
275275
/// [`From`]: trait.From.html
276276
/// [`Into`]: trait.Into.html
277+
/// [`Vec`]: ../../std/vec/struct.Vec.html
277278
#[stable(feature = "rust1", since = "1.0.0")]
278279
pub trait Into<T>: Sized {
279280
/// Performs the conversion.
@@ -410,12 +411,12 @@ pub trait TryInto<T>: Sized {
410411
///
411412
/// This is useful when you are doing a type conversion that may
412413
/// trivially succeed but may also need special handling.
413-
/// For example, there is no way to convert an `i64` into an `i32`
414-
/// using the [`From`] trait, because an `i64` may contain a value
415-
/// that an `i32` cannot represent and so the conversion would lose data.
416-
/// This might be handled by truncating the `i64` to an `i32` (essentially
417-
/// giving the `i64`'s value modulo `i32::MAX`) or by simply returning
418-
/// `i32::MAX`, or by some other method. The `From` trait is intended
414+
/// For example, there is no way to convert an [`i64`] into an [`i32`]
415+
/// using the [`From`] trait, because an [`i64`] may contain a value
416+
/// that an [`i32`] cannot represent and so the conversion would lose data.
417+
/// This might be handled by truncating the [`i64`] to an [`i32`] (essentially
418+
/// giving the [`i64`]'s value modulo [`i32::MAX`]) or by simply returning
419+
/// [`i32::MAX`], or by some other method. The [`From`] trait is intended
419420
/// for perfect conversions, so the `TryFrom` trait informs the
420421
/// programmer when a type conversion could go bad and lets them
421422
/// decide how to handle it.
@@ -425,8 +426,8 @@ pub trait TryInto<T>: Sized {
425426
/// - `TryFrom<T> for U` implies [`TryInto`]`<U> for T`
426427
/// - [`try_from`] is reflexive, which means that `TryFrom<T> for T`
427428
/// is implemented and cannot fail -- the associated `Error` type for
428-
/// calling `T::try_from()` on a value of type `T` is `Infallible`.
429-
/// When the `!` type is stablized `Infallible` and `!` will be
429+
/// calling `T::try_from()` on a value of type `T` is [`Infallible`].
430+
/// When the [`!`] type is stablized [`Infallible`] and [`!`] will be
430431
/// equivalent.
431432
///
432433
/// `TryFrom<T>` can be implemented as follows:
@@ -451,7 +452,7 @@ pub trait TryInto<T>: Sized {
451452
///
452453
/// # Examples
453454
///
454-
/// As described, [`i32`] implements `TryFrom<i64>`:
455+
/// As described, [`i32`] implements `TryFrom<`[`i64`]`>`:
455456
///
456457
/// ```
457458
/// use std::convert::TryFrom;
@@ -474,6 +475,8 @@ pub trait TryInto<T>: Sized {
474475
///
475476
/// [`try_from`]: trait.TryFrom.html#tymethod.try_from
476477
/// [`TryInto`]: trait.TryInto.html
478+
/// [`i32::MAX`]: ../../std/i32/constant.MAX.html
479+
/// [`!`]: ../../std/primitive.never.html
477480
#[stable(feature = "try_from", since = "1.34.0")]
478481
pub trait TryFrom<T>: Sized {
479482
/// The type returned in the event of a conversion error.

src/libcore/slice/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4453,6 +4453,21 @@ impl<'a, T> DoubleEndedIterator for ChunksExact<'a, T> {
44534453
Some(snd)
44544454
}
44554455
}
4456+
4457+
#[inline]
4458+
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
4459+
let len = self.len();
4460+
if n >= len {
4461+
self.v = &[];
4462+
None
4463+
} else {
4464+
let start = (len - 1 - n) * self.chunk_size;
4465+
let end = start + self.chunk_size;
4466+
let nth_back = &self.v[start..end];
4467+
self.v = &self.v[..start];
4468+
Some(nth_back)
4469+
}
4470+
}
44564471
}
44574472

44584473
#[stable(feature = "chunks_exact", since = "1.31.0")]

src/libcore/str/mod.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3716,10 +3716,10 @@ impl str {
37163716
///
37173717
/// # Text directionality
37183718
///
3719-
/// A string is a sequence of bytes. 'Left' in this context means the first
3720-
/// position of that byte string; for a language like Arabic or Hebrew
3721-
/// which are 'right to left' rather than 'left to right', this will be
3722-
/// the _right_ side, not the left.
3719+
/// A string is a sequence of bytes. `start` in this context means the first
3720+
/// position of that byte string; for a left-to-right language like English or
3721+
/// Russian, this will be left side, and for right-to-left languages like
3722+
/// like Arabic or Hebrew, this will be the right side.
37233723
///
37243724
/// # Examples
37253725
///
@@ -3755,10 +3755,10 @@ impl str {
37553755
///
37563756
/// # Text directionality
37573757
///
3758-
/// A string is a sequence of bytes. 'Right' in this context means the last
3759-
/// position of that byte string; for a language like Arabic or Hebrew
3760-
/// which are 'right to left' rather than 'left to right', this will be
3761-
/// the _left_ side, not the right.
3758+
/// A string is a sequence of bytes. `end` in this context means the last
3759+
/// position of that byte string; for a left-to-right language like English or
3760+
/// Russian, this will be right side, and for right-to-left languages like
3761+
/// like Arabic or Hebrew, this will be the left side.
37623762
///
37633763
/// # Examples
37643764
///
@@ -3804,10 +3804,10 @@ impl str {
38043804
///
38053805
/// # Text directionality
38063806
///
3807-
/// A string is a sequence of bytes. `start` in this context means the first
3808-
/// position of that byte string; for a left-to-right language like English or
3809-
/// Russian, this will be left side, and for right-to-left languages like
3810-
/// like Arabic or Hebrew, this will be the right side.
3807+
/// A string is a sequence of bytes. 'Left' in this context means the first
3808+
/// position of that byte string; for a language like Arabic or Hebrew
3809+
/// which are 'right to left' rather than 'left to right', this will be
3810+
/// the _right_ side, not the left.
38113811
///
38123812
/// # Examples
38133813
///
@@ -3840,10 +3840,10 @@ impl str {
38403840
///
38413841
/// # Text directionality
38423842
///
3843-
/// A string is a sequence of bytes. `end` in this context means the last
3844-
/// position of that byte string; for a left-to-right language like English or
3845-
/// Russian, this will be right side, and for right-to-left languages like
3846-
/// like Arabic or Hebrew, this will be the left side.
3843+
/// A string is a sequence of bytes. 'Right' in this context means the last
3844+
/// position of that byte string; for a language like Arabic or Hebrew
3845+
/// which are 'right to left' rather than 'left to right', this will be
3846+
/// the _left_ side, not the right.
38473847
///
38483848
/// # Examples
38493849
///

src/libcore/tests/ascii.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ macro_rules! assert_none {
151151
stringify!($what), b);
152152
}
153153
}
154-
)*
154+
)+
155155
}};
156156
($what:ident, $($str:tt),+,) => (assert_none!($what,$($str),+))
157157
}

src/libcore/tests/pattern.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::str::pattern::*;
55
macro_rules! search_asserts {
66
($haystack:expr, $needle:expr, $testname:expr, [$($func:ident),*], $result:expr) => {
77
let mut searcher = $needle.into_searcher($haystack);
8-
let arr = [$( Step::from(searcher.$func()) ),+];
8+
let arr = [$( Step::from(searcher.$func()) ),*];
99
assert_eq!(&arr[..], &$result, $testname);
1010
}
1111
}

0 commit comments

Comments
 (0)