Skip to content

Commit efaf8bf

Browse files
committed
Auto merge of #54432 - kennytm:rollup, r=kennytm
Rollup of 10 pull requests Successful merges: - #53652 (define copy_within on slices) - #54261 (Make `dyn` a keyword in the 2018 edition) - #54317 (Implement the dbg!(..) macro) - #54323 (rustbuild: drop color handling) - #54371 (add -Zui-testing to rustdoc) - #54374 (Make 'proc_macro::MultiSpan' public.) - #54402 (Use no_default_libraries for all NetBSD flavors) - #54412 (add applicability to span_suggestion call) - #54413 (Add UI test for deref recursion limit printing twice) - #54422 (Simplify slice's first(_mut) and last(_mut) with get)
2 parents 1002e40 + e6b2e80 commit efaf8bf

35 files changed

+633
-102
lines changed

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/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`.

src/libcore/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#![feature(inner_deref)]
4040
#![feature(slice_internals)]
4141
#![feature(option_replace)]
42+
#![feature(copy_within)]
4243

4344
extern crate core;
4445
extern crate test;

src/libcore/tests/slice.rs

+46
Original file line numberDiff line numberDiff line change
@@ -1000,3 +1000,49 @@ fn test_align_to_empty_mid() {
10001000
assert_eq!(mid.as_ptr() as usize % mem::align_of::<Chunk>(), 0);
10011001
}
10021002
}
1003+
1004+
#[test]
1005+
fn test_copy_within() {
1006+
// Start to end, with a RangeTo.
1007+
let mut bytes = *b"Hello, World!";
1008+
bytes.copy_within(..3, 10);
1009+
assert_eq!(&bytes, b"Hello, WorHel");
1010+
1011+
// End to start, with a RangeFrom.
1012+
let mut bytes = *b"Hello, World!";
1013+
bytes.copy_within(10.., 0);
1014+
assert_eq!(&bytes, b"ld!lo, World!");
1015+
1016+
// Overlapping, with a RangeInclusive.
1017+
let mut bytes = *b"Hello, World!";
1018+
bytes.copy_within(0..=11, 1);
1019+
assert_eq!(&bytes, b"HHello, World");
1020+
1021+
// Whole slice, with a RangeFull.
1022+
let mut bytes = *b"Hello, World!";
1023+
bytes.copy_within(.., 0);
1024+
assert_eq!(&bytes, b"Hello, World!");
1025+
}
1026+
1027+
#[test]
1028+
#[should_panic(expected = "src is out of bounds")]
1029+
fn test_copy_within_panics_src_too_long() {
1030+
let mut bytes = *b"Hello, World!";
1031+
// The length is only 13, so 14 is out of bounds.
1032+
bytes.copy_within(10..14, 0);
1033+
}
1034+
1035+
#[test]
1036+
#[should_panic(expected = "dest is out of bounds")]
1037+
fn test_copy_within_panics_dest_too_long() {
1038+
let mut bytes = *b"Hello, World!";
1039+
// The length is only 13, so a slice of length 4 starting at index 10 is out of bounds.
1040+
bytes.copy_within(0..4, 10);
1041+
}
1042+
#[test]
1043+
#[should_panic(expected = "src end is before src start")]
1044+
fn test_copy_within_panics_src_inverted() {
1045+
let mut bytes = *b"Hello, World!";
1046+
// 2 is greater than 1, so this range is invalid.
1047+
bytes.copy_within(2..1, 0);
1048+
}

src/libproc_macro/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub mod rustc;
4848
mod diagnostic;
4949

5050
#[unstable(feature = "proc_macro_diagnostic", issue = "54140")]
51-
pub use diagnostic::{Diagnostic, Level};
51+
pub use diagnostic::{Diagnostic, Level, MultiSpan};
5252

5353
use std::{ascii, fmt, iter};
5454
use std::path::PathBuf;

src/librustc_lint/builtin.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1937,8 +1937,7 @@ impl EarlyLintPass for KeywordIdents {
19371937
let next_edition = match cx.sess.edition() {
19381938
Edition::Edition2015 => {
19391939
match &ident.as_str()[..] {
1940-
"async" |
1941-
"try" => Edition::Edition2018,
1940+
"async" | "try" | "dyn" => Edition::Edition2018,
19421941
_ => return,
19431942
}
19441943
}

src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use std::collections::VecDeque;
2222
use std::fmt;
2323
use syntax::symbol::keywords;
2424
use syntax_pos::Span;
25+
use syntax::errors::Applicability;
2526

2627
mod region_name;
2728
mod var_name;
@@ -540,14 +541,15 @@ impl<'tcx> RegionInferenceContext<'tcx> {
540541
RegionName::Named(name) => format!("{}", name),
541542
RegionName::Synthesized(_) => "'_".to_string(),
542543
};
543-
diag.span_suggestion(
544+
diag.span_suggestion_with_applicability(
544545
span,
545546
&format!(
546547
"to allow this impl Trait to capture borrowed data with lifetime \
547548
`{}`, add `{}` as a constraint",
548549
fr_name, suggestable_fr_name,
549550
),
550551
format!("{} + {}", snippet, suggestable_fr_name),
552+
Applicability::MachineApplicable,
551553
);
552554
}
553555
}

src/librustc_target/spec/netbsd_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub fn opts() -> TargetOptions {
2929
executables: true,
3030
target_family: Some("unix".to_string()),
3131
linker_is_gnu: true,
32+
no_default_libraries: false,
3233
has_rpath: true,
3334
pre_link_args: args,
3435
position_independent_executables: true,

src/librustc_target/spec/x86_64_rumprun_netbsd.rs

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ pub fn target() -> TargetResult {
2121
base.has_rpath = false;
2222
base.position_independent_executables = false;
2323
base.disable_redzone = true;
24-
base.no_default_libraries = false;
2524
base.exe_allocation_crate = None;
2625
base.stack_probes = true;
2726

src/librustdoc/core.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ impl DocAccessLevels for AccessLevels<DefId> {
272272
pub fn new_handler(error_format: ErrorOutputType,
273273
source_map: Option<Lrc<source_map::SourceMap>>,
274274
treat_err_as_bug: bool,
275+
ui_testing: bool,
275276
) -> errors::Handler {
276277
// rustdoc doesn't override (or allow to override) anything from this that is relevant here, so
277278
// stick to the defaults
@@ -283,7 +284,7 @@ pub fn new_handler(error_format: ErrorOutputType,
283284
source_map.map(|cm| cm as _),
284285
false,
285286
sessopts.debugging_opts.teach,
286-
).ui_testing(sessopts.debugging_opts.ui_testing)
287+
).ui_testing(ui_testing)
287288
),
288289
ErrorOutputType::Json(pretty) => {
289290
let source_map = source_map.unwrap_or_else(
@@ -293,7 +294,7 @@ pub fn new_handler(error_format: ErrorOutputType,
293294
None,
294295
source_map,
295296
pretty,
296-
).ui_testing(sessopts.debugging_opts.ui_testing)
297+
).ui_testing(ui_testing)
297298
)
298299
},
299300
ErrorOutputType::Short(color_config) => Box::new(
@@ -335,6 +336,7 @@ pub fn run_core(search_paths: SearchPaths,
335336
mut manual_passes: Vec<String>,
336337
mut default_passes: passes::DefaultPassOption,
337338
treat_err_as_bug: bool,
339+
ui_testing: bool,
338340
) -> (clean::Crate, RenderInfo, Vec<String>) {
339341
// Parse, resolve, and typecheck the given crate.
340342

@@ -389,6 +391,8 @@ pub fn run_core(search_paths: SearchPaths,
389391
actually_rustdoc: true,
390392
debugging_opts: config::DebuggingOptions {
391393
force_unstable_if_unmarked,
394+
treat_err_as_bug,
395+
ui_testing,
392396
..config::basic_debugging_options()
393397
},
394398
error_format,
@@ -400,7 +404,8 @@ pub fn run_core(search_paths: SearchPaths,
400404
let source_map = Lrc::new(source_map::SourceMap::new(sessopts.file_path_mapping()));
401405
let diagnostic_handler = new_handler(error_format,
402406
Some(source_map.clone()),
403-
treat_err_as_bug);
407+
treat_err_as_bug,
408+
ui_testing);
404409

405410
let mut sess = session::build_session_(
406411
sessopts, cpath, diagnostic_handler, source_map,

src/librustdoc/lib.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,11 @@ fn main_args(args: &[String]) -> isize {
409409
let treat_err_as_bug = matches.opt_strs("Z").iter().any(|x| {
410410
*x == "treat-err-as-bug"
411411
});
412+
let ui_testing = matches.opt_strs("Z").iter().any(|x| {
413+
*x == "ui-testing"
414+
});
412415

413-
let diag = core::new_handler(error_format, None, treat_err_as_bug);
416+
let diag = core::new_handler(error_format, None, treat_err_as_bug, ui_testing);
414417

415418
// check for deprecated options
416419
check_deprecated_options(&matches, &diag);
@@ -565,7 +568,7 @@ fn main_args(args: &[String]) -> isize {
565568
let res = acquire_input(PathBuf::from(input), externs, edition, cg, &matches, error_format,
566569
move |out| {
567570
let Output { krate, passes, renderinfo } = out;
568-
let diag = core::new_handler(error_format, None, treat_err_as_bug);
571+
let diag = core::new_handler(error_format, None, treat_err_as_bug, ui_testing);
569572
info!("going to format");
570573
match output_format.as_ref().map(|s| &**s) {
571574
Some("html") | None => {
@@ -702,6 +705,9 @@ where R: 'static + Send,
702705
let treat_err_as_bug = matches.opt_strs("Z").iter().any(|x| {
703706
*x == "treat-err-as-bug"
704707
});
708+
let ui_testing = matches.opt_strs("Z").iter().any(|x| {
709+
*x == "ui-testing"
710+
});
705711

706712
let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);
707713

@@ -715,7 +721,7 @@ where R: 'static + Send,
715721
display_warnings, crate_name.clone(),
716722
force_unstable_if_unmarked, edition, cg, error_format,
717723
lint_opts, lint_cap, describe_lints, manual_passes, default_passes,
718-
treat_err_as_bug);
724+
treat_err_as_bug, ui_testing);
719725

720726
info!("finished with rustc");
721727

0 commit comments

Comments
 (0)