Skip to content

Commit af50e38

Browse files
committed
Auto merge of #54457 - pietroalbini:rollup, r=pietroalbini
Rollup of 16 pull requests Successful merges: - #53652 (define copy_within on slices) - #54261 (Make `dyn` a keyword in the 2018 edition) - #54280 (remove (more) CAS API from Atomic* types where not natively supported) - #54323 (rustbuild: drop color handling) - #54350 (Support specifying edition in doc test) - #54370 (Improve handling of type bounds in `bit_set.rs`.) - #54371 (add -Zui-testing to rustdoc) - #54374 (Make 'proc_macro::MultiSpan' public.) - #54402 (Use no_default_libraries for all NetBSD flavors) - #54409 (Detect `for _ in in bar {}` typo) - #54412 (add applicability to span_suggestion call) - #54413 (Add UI test for deref recursion limit printing twice) - #54415 (parser: Tweak function parameter parsing to avoid rollback on succesfull path) - #54420 (Compress `Liveness` data some more.) - #54422 (Simplify slice's first(_mut) and last(_mut) with get) - #54446 (Unify christianpoveda's emails) Failed merges: - #54058 (Introduce the partition_dedup/by/by_key methods for slices) r? @ghost
2 parents e7b5ba8 + 48ec53c commit af50e38

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+912
-447
lines changed

.mailmap

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Chris C Cerami <chrisccerami@users.noreply.github.com> Chris C Cerami <chrisccer
5252
Chris Pressey <cpressey@gmail.com>
5353
Chris Thorn <chris@thorn.co> Chris Thorn <thorn@thoughtbot.com>
5454
Chris Vittal <christopher.vittal@gmail.com> Christopher Vittal <christopher.vittal@gmail.com>
55+
Christian Poveda <christianpoveda@protonmail.com> <z1mvader@protonmail.com> <cn.poveda.ruiz@gmail.com>
5556
Clark Gaebel <cg.wowus.cg@gmail.com> <cgaebel@mozilla.com>
5657
Clinton Ryan <clint.ryan3@gmail.com>
5758
Corey Richardson <corey@octayn.net> Elaine "See More" Nemo <corey@octayn.net>

src/bootstrap/bin/rustc.rs

-9
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,6 @@ fn main() {
291291
cmd.arg("-Z").arg("verify-llvm-ir");
292292
}
293293

294-
let color = match env::var("RUSTC_COLOR") {
295-
Ok(s) => usize::from_str(&s).expect("RUSTC_COLOR should be an integer"),
296-
Err(_) => 0,
297-
};
298-
299-
if color != 0 {
300-
cmd.arg("--color=always");
301-
}
302-
303294
if env::var_os("RUSTC_DENY_WARNINGS").is_some() && env::var_os("RUSTC_EXTERNAL_TOOL").is_none()
304295
{
305296
cmd.arg("-Dwarnings");

src/bootstrap/compile.rs

+1-33
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use build_helper::{output, mtime, up_to_date};
2929
use filetime::FileTime;
3030
use serde_json;
3131

32-
use util::{exe, libdir, is_dylib, CiEnv};
32+
use util::{exe, libdir, is_dylib};
3333
use {Compiler, Mode, GitRepo};
3434
use native;
3535

@@ -1034,29 +1034,6 @@ pub fn add_to_sysroot(builder: &Builder, sysroot_dst: &Path, stamp: &Path) {
10341034
}
10351035
}
10361036

1037-
// Avoiding a dependency on winapi to keep compile times down
1038-
#[cfg(unix)]
1039-
fn stderr_isatty() -> bool {
1040-
use libc;
1041-
unsafe { libc::isatty(libc::STDERR_FILENO) != 0 }
1042-
}
1043-
#[cfg(windows)]
1044-
fn stderr_isatty() -> bool {
1045-
type DWORD = u32;
1046-
type BOOL = i32;
1047-
type HANDLE = *mut u8;
1048-
const STD_ERROR_HANDLE: DWORD = -12i32 as DWORD;
1049-
extern "system" {
1050-
fn GetStdHandle(which: DWORD) -> HANDLE;
1051-
fn GetConsoleMode(hConsoleHandle: HANDLE, lpMode: *mut DWORD) -> BOOL;
1052-
}
1053-
unsafe {
1054-
let handle = GetStdHandle(STD_ERROR_HANDLE);
1055-
let mut out = 0;
1056-
GetConsoleMode(handle, &mut out) != 0
1057-
}
1058-
}
1059-
10601037
pub fn run_cargo(builder: &Builder,
10611038
cargo: &mut Command,
10621039
tail_args: Vec<String>,
@@ -1218,15 +1195,6 @@ pub fn stream_cargo(
12181195
cargo.arg("--message-format").arg("json")
12191196
.stdout(Stdio::piped());
12201197

1221-
if stderr_isatty() && builder.ci_env == CiEnv::None &&
1222-
// if the terminal is reported as dumb, then we don't want to enable color for rustc
1223-
env::var_os("TERM").map(|t| t != *"dumb").unwrap_or(true) {
1224-
// since we pass message-format=json to cargo, we need to tell the rustc
1225-
// wrapper to give us colored output if necessary. This is because we
1226-
// only want Cargo's JSON output, not rustcs.
1227-
cargo.env("RUSTC_COLOR", "1");
1228-
}
1229-
12301198
for arg in tail_args {
12311199
cargo.arg(arg);
12321200
}

src/doc/rustdoc/src/documentation-tests.md

+16
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,22 @@ compiles, then the test will fail. However please note that code failing
323323
with the current Rust release may work in a future release, as new features
324324
are added.
325325

326+
```text
327+
/// Only runs on the 2018 edition.
328+
///
329+
/// ```edition2018
330+
/// let result: Result<i32, ParseIntError> = try {
331+
/// "1".parse::<i32>()?
332+
/// + "2".parse::<i32>()?
333+
/// + "3".parse::<i32>()?
334+
/// };
335+
/// ```
336+
```
337+
338+
`edition2018` tells `rustdoc` that the code sample should be compiled the 2018
339+
edition of Rust. Similarly, you can specify `edition2015` to compile the code
340+
with the 2015 edition.
341+
326342
## Syntax reference
327343

328344
The *exact* syntax for code blocks, including the edge cases, can be found

src/doc/unstable-book/src/language-features/try-blocks.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ The tracking issue for this feature is: [#31436]
99
The `try_blocks` feature adds support for `try` blocks. A `try`
1010
block creates a new scope one can use the `?` operator in.
1111

12-
```rust,ignore
13-
// This code needs the 2018 edition
14-
12+
```rust,edition2018
1513
#![feature(try_blocks)]
1614
1715
use std::num::ParseIntError;

src/libcore/slice/mod.rs

+63-6
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl<T> [T] {
119119
#[stable(feature = "rust1", since = "1.0.0")]
120120
#[inline]
121121
pub fn first(&self) -> Option<&T> {
122-
if self.is_empty() { None } else { Some(&self[0]) }
122+
self.get(0)
123123
}
124124

125125
/// Returns a mutable pointer to the first element of the slice, or `None` if it is empty.
@@ -137,7 +137,7 @@ impl<T> [T] {
137137
#[stable(feature = "rust1", since = "1.0.0")]
138138
#[inline]
139139
pub fn first_mut(&mut self) -> Option<&mut T> {
140-
if self.is_empty() { None } else { Some(&mut self[0]) }
140+
self.get_mut(0)
141141
}
142142

143143
/// Returns the first and all the rest of the elements of the slice, or `None` if it is empty.
@@ -239,7 +239,8 @@ impl<T> [T] {
239239
#[stable(feature = "rust1", since = "1.0.0")]
240240
#[inline]
241241
pub fn last(&self) -> Option<&T> {
242-
if self.is_empty() { None } else { Some(&self[self.len() - 1]) }
242+
let last_idx = self.len().checked_sub(1)?;
243+
self.get(last_idx)
243244
}
244245

245246
/// Returns a mutable pointer to the last item in the slice.
@@ -257,9 +258,8 @@ impl<T> [T] {
257258
#[stable(feature = "rust1", since = "1.0.0")]
258259
#[inline]
259260
pub fn last_mut(&mut self) -> Option<&mut T> {
260-
let len = self.len();
261-
if len == 0 { return None; }
262-
Some(&mut self[len - 1])
261+
let last_idx = self.len().checked_sub(1)?;
262+
self.get_mut(last_idx)
263263
}
264264

265265
/// Returns a reference to an element or subslice depending on the type of
@@ -1618,6 +1618,63 @@ impl<T> [T] {
16181618
}
16191619
}
16201620

1621+
/// Copies elements from one part of the slice to another part of itself,
1622+
/// using a memmove.
1623+
///
1624+
/// `src` is the range within `self` to copy from. `dest` is the starting
1625+
/// index of the range within `self` to copy to, which will have the same
1626+
/// length as `src`. The two ranges may overlap. The ends of the two ranges
1627+
/// must be less than or equal to `self.len()`.
1628+
///
1629+
/// # Panics
1630+
///
1631+
/// This function will panic if either range exceeds the end of the slice,
1632+
/// or if the end of `src` is before the start.
1633+
///
1634+
/// # Examples
1635+
///
1636+
/// Copying four bytes within a slice:
1637+
///
1638+
/// ```
1639+
/// # #![feature(copy_within)]
1640+
/// let mut bytes = *b"Hello, World!";
1641+
///
1642+
/// bytes.copy_within(1..5, 8);
1643+
///
1644+
/// assert_eq!(&bytes, b"Hello, Wello!");
1645+
/// ```
1646+
#[unstable(feature = "copy_within", issue = "54236")]
1647+
pub fn copy_within<R: ops::RangeBounds<usize>>(&mut self, src: R, dest: usize)
1648+
where
1649+
T: Copy,
1650+
{
1651+
let src_start = match src.start_bound() {
1652+
ops::Bound::Included(&n) => n,
1653+
ops::Bound::Excluded(&n) => n
1654+
.checked_add(1)
1655+
.unwrap_or_else(|| slice_index_overflow_fail()),
1656+
ops::Bound::Unbounded => 0,
1657+
};
1658+
let src_end = match src.end_bound() {
1659+
ops::Bound::Included(&n) => n
1660+
.checked_add(1)
1661+
.unwrap_or_else(|| slice_index_overflow_fail()),
1662+
ops::Bound::Excluded(&n) => n,
1663+
ops::Bound::Unbounded => self.len(),
1664+
};
1665+
assert!(src_start <= src_end, "src end is before src start");
1666+
assert!(src_end <= self.len(), "src is out of bounds");
1667+
let count = src_end - src_start;
1668+
assert!(dest <= self.len() - count, "dest is out of bounds");
1669+
unsafe {
1670+
ptr::copy(
1671+
self.get_unchecked(src_start),
1672+
self.get_unchecked_mut(dest),
1673+
count,
1674+
);
1675+
}
1676+
}
1677+
16211678
/// Swaps all elements in `self` with those in `other`.
16221679
///
16231680
/// The length of `other` must be the same as `self`.

0 commit comments

Comments
 (0)