Skip to content

Commit 088b987

Browse files
committed
Auto merge of #62335 - Mark-Simulacrum:rollup-0pcaz5a, r=Mark-Simulacrum
Rollup of 15 pull requests Successful merges: - #62021 (MSVC link output improve) - #62064 (nth_back for chunks_exact) - #62128 (Adjust warning of -C extra-filename with -o.) - #62161 (Add missing links for TryFrom docs) - #62183 (std: Move a process test out of libstd) - #62186 (Add missing type urls in Into trait) - #62196 (Add Vec::leak) - #62199 (import gdb for explicit access to gdb.current_objfile()) - #62229 (Enable intptrcast for explicit casts) - #62250 (Improve box clone doctests to ensure the documentation is valid) - #62255 (Switch tracking issue for `#![feature(slice_patterns)]`) - #62285 (Fix michaelwoerister's mailmap) - #62304 (HashMap is UnwindSafe) - #62319 (Fix mismatching Kleene operators) - #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

Diff for: .mailmap

+2
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ Matthijs Hofstra <[email protected]>
167167
168168
Michael Williams <[email protected]>
169169
Michael Woerister <michaelwoerister@posteo> <michaelwoerister@gmail>
170+
Michael Woerister <michaelwoerister@posteo> <[email protected]>
171+
Michael Woerister <michaelwoerister@posteo> <[email protected]>
170172
Mickaël Raybaud-Roig <[email protected]> m-r-r <[email protected]>
171173
172174
Mukilan Thiagarajan <[email protected]>

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

+2-2
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

Diff for: src/etc/gdb_load_rust_pretty_printers.py

+1
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())

Diff for: src/liballoc/boxed.rs

+13-1
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>) {

Diff for: src/liballoc/vec.rs

+34
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> {

Diff for: src/libcore/convert.rs

+14-11
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.

Diff for: src/libcore/slice/mod.rs

+15
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")]

Diff for: src/libcore/str/mod.rs

+16-16
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
///

Diff for: src/libcore/tests/ascii.rs

+1-1
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
}

Diff for: src/libcore/tests/pattern.rs

+1-1
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
}

Diff for: src/libcore/tests/slice.rs

+19
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,25 @@ fn test_chunks_exact_nth() {
275275
assert_eq!(c2.next(), None);
276276
}
277277

278+
#[test]
279+
fn test_chunks_exact_nth_back() {
280+
let v: &[i32] = &[0, 1, 2, 3, 4, 5];
281+
let mut c = v.chunks_exact(2);
282+
assert_eq!(c.nth_back(1).unwrap(), &[2, 3]);
283+
assert_eq!(c.next().unwrap(), &[0, 1]);
284+
assert_eq!(c.next(), None);
285+
286+
let v2: &[i32] = &[0, 1, 2, 3, 4];
287+
let mut c2 = v2.chunks_exact(3);
288+
assert_eq!(c2.nth_back(0).unwrap(), &[0, 1, 2]);
289+
assert_eq!(c2.next(), None);
290+
assert_eq!(c2.next_back(), None);
291+
292+
let v3: &[i32] = &[0, 1, 2, 3, 4];
293+
let mut c3 = v3.chunks_exact(10);
294+
assert_eq!(c3.nth_back(0), None);
295+
}
296+
278297
#[test]
279298
fn test_chunks_exact_last() {
280299
let v: &[i32] = &[0, 1, 2, 3, 4, 5];

Diff for: src/librustc_codegen_ssa/back/link.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -653,10 +653,14 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(sess: &'a Session,
653653
linker_error.emit();
654654

655655
if sess.target.target.options.is_like_msvc && linker_not_found {
656-
sess.note_without_error("the msvc targets depend on the msvc linker \
657-
but `link.exe` was not found");
658-
sess.note_without_error("please ensure that VS 2013, VS 2015 or VS 2017 \
659-
was installed with the Visual C++ option");
656+
sess.note_without_error(
657+
"the msvc targets depend on the msvc linker \
658+
but `link.exe` was not found",
659+
);
660+
sess.note_without_error(
661+
"please ensure that VS 2013, VS 2015, VS 2017 or VS 2019 \
662+
was installed with the Visual C++ option",
663+
);
660664
}
661665
sess.abort_if_errors();
662666
}

Diff for: src/librustc_interface/util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -642,14 +642,14 @@ pub fn build_output_filenames(
642642
);
643643
None
644644
} else {
645+
if !sess.opts.cg.extra_filename.is_empty() {
646+
sess.warn("ignoring -C extra-filename flag due to -o flag");
647+
}
645648
Some(out_file.clone())
646649
};
647650
if *odir != None {
648651
sess.warn("ignoring --out-dir flag due to -o flag");
649652
}
650-
if !sess.opts.cg.extra_filename.is_empty() {
651-
sess.warn("ignoring -C extra-filename flag due to -o flag");
652-
}
653653

654654
OutputFilenames {
655655
out_directory: out_file.parent().unwrap_or_else(|| Path::new("")).to_path_buf(),

Diff for: src/librustc_mir/interpret/cast.rs

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc::ty::{self, Ty, TypeAndMut};
22
use rustc::ty::layout::{self, TyLayout, Size};
33
use rustc::ty::adjustment::{PointerCast};
4-
use syntax::ast::{FloatTy, IntTy, UintTy};
4+
use syntax::ast::FloatTy;
55
use syntax::symbol::sym;
66

77
use rustc_apfloat::ieee::{Single, Double};
@@ -151,7 +151,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> {
151151
"Unexpected cast from type {:?}", src_layout.ty
152152
);
153153
match val.to_bits_or_ptr(src_layout.size, self) {
154-
Err(ptr) => self.cast_from_ptr(ptr, dest_layout.ty),
154+
Err(ptr) => self.cast_from_ptr(ptr, src_layout, dest_layout),
155155
Ok(data) => self.cast_from_int(data, src_layout, dest_layout),
156156
}
157157
}
@@ -239,17 +239,25 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> {
239239
fn cast_from_ptr(
240240
&self,
241241
ptr: Pointer<M::PointerTag>,
242-
ty: Ty<'tcx>
242+
src_layout: TyLayout<'tcx>,
243+
dest_layout: TyLayout<'tcx>,
243244
) -> InterpResult<'tcx, Scalar<M::PointerTag>> {
244245
use rustc::ty::TyKind::*;
245-
match ty.sty {
246+
247+
match dest_layout.ty.sty {
246248
// Casting to a reference or fn pointer is not permitted by rustc,
247249
// no need to support it here.
248-
RawPtr(_) |
249-
Int(IntTy::Isize) |
250-
Uint(UintTy::Usize) => Ok(ptr.into()),
251-
Int(_) | Uint(_) => err!(ReadPointerAsBytes),
252-
_ => err!(Unimplemented(format!("ptr to {:?} cast", ty))),
250+
RawPtr(_) => Ok(ptr.into()),
251+
Int(_) | Uint(_) => {
252+
let size = self.memory.pointer_size();
253+
254+
match self.force_bits(Scalar::Ptr(ptr), size) {
255+
Ok(bits) => self.cast_from_int(bits, src_layout, dest_layout),
256+
Err(_) if dest_layout.size == size => Ok(ptr.into()),
257+
Err(e) => Err(e),
258+
}
259+
}
260+
_ => bug!("invalid MIR: ptr to {:?} cast", dest_layout.ty)
253261
}
254262
}
255263

Diff for: src/librustc_target/spec/windows_msvc_base.rs

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ pub fn opts() -> TargetOptions {
1919
target_family: Some("windows".to_string()),
2020
is_like_windows: true,
2121
is_like_msvc: true,
22+
// set VSLANG to 1033 can prevent link.exe from using
23+
// language packs, and avoid generating Non-UTF-8 error
24+
// messages if a link error occurred.
25+
link_env: vec![("VSLANG".to_string(), "1033".to_string())],
2226
pre_link_args: args,
2327
crt_static_allows_dylibs: true,
2428
crt_static_respected: true,

0 commit comments

Comments
 (0)