Skip to content

Commit

Permalink
Auto merge of #54432 - kennytm:rollup, r=kennytm
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
bors committed Sep 21, 2018
2 parents 1002e40 + e6b2e80 commit efaf8bf
Show file tree
Hide file tree
Showing 35 changed files with 633 additions and 102 deletions.
9 changes: 0 additions & 9 deletions src/bootstrap/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,6 @@ fn main() {
cmd.arg("-Z").arg("verify-llvm-ir");
}

let color = match env::var("RUSTC_COLOR") {
Ok(s) => usize::from_str(&s).expect("RUSTC_COLOR should be an integer"),
Err(_) => 0,
};

if color != 0 {
cmd.arg("--color=always");
}

if env::var_os("RUSTC_DENY_WARNINGS").is_some() && env::var_os("RUSTC_EXTERNAL_TOOL").is_none()
{
cmd.arg("-Dwarnings");
Expand Down
34 changes: 1 addition & 33 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use build_helper::{output, mtime, up_to_date};
use filetime::FileTime;
use serde_json;

use util::{exe, libdir, is_dylib, CiEnv};
use util::{exe, libdir, is_dylib};
use {Compiler, Mode, GitRepo};
use native;

Expand Down Expand Up @@ -1034,29 +1034,6 @@ pub fn add_to_sysroot(builder: &Builder, sysroot_dst: &Path, stamp: &Path) {
}
}

// Avoiding a dependency on winapi to keep compile times down
#[cfg(unix)]
fn stderr_isatty() -> bool {
use libc;
unsafe { libc::isatty(libc::STDERR_FILENO) != 0 }
}
#[cfg(windows)]
fn stderr_isatty() -> bool {
type DWORD = u32;
type BOOL = i32;
type HANDLE = *mut u8;
const STD_ERROR_HANDLE: DWORD = -12i32 as DWORD;
extern "system" {
fn GetStdHandle(which: DWORD) -> HANDLE;
fn GetConsoleMode(hConsoleHandle: HANDLE, lpMode: *mut DWORD) -> BOOL;
}
unsafe {
let handle = GetStdHandle(STD_ERROR_HANDLE);
let mut out = 0;
GetConsoleMode(handle, &mut out) != 0
}
}

pub fn run_cargo(builder: &Builder,
cargo: &mut Command,
tail_args: Vec<String>,
Expand Down Expand Up @@ -1218,15 +1195,6 @@ pub fn stream_cargo(
cargo.arg("--message-format").arg("json")
.stdout(Stdio::piped());

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

for arg in tail_args {
cargo.arg(arg);
}
Expand Down
69 changes: 63 additions & 6 deletions src/libcore/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl<T> [T] {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn first(&self) -> Option<&T> {
if self.is_empty() { None } else { Some(&self[0]) }
self.get(0)
}

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

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

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

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

/// Copies elements from one part of the slice to another part of itself,
/// using a memmove.
///
/// `src` is the range within `self` to copy from. `dest` is the starting
/// index of the range within `self` to copy to, which will have the same
/// length as `src`. The two ranges may overlap. The ends of the two ranges
/// must be less than or equal to `self.len()`.
///
/// # Panics
///
/// This function will panic if either range exceeds the end of the slice,
/// or if the end of `src` is before the start.
///
/// # Examples
///
/// Copying four bytes within a slice:
///
/// ```
/// # #![feature(copy_within)]
/// let mut bytes = *b"Hello, World!";
///
/// bytes.copy_within(1..5, 8);
///
/// assert_eq!(&bytes, b"Hello, Wello!");
/// ```
#[unstable(feature = "copy_within", issue = "54236")]
pub fn copy_within<R: ops::RangeBounds<usize>>(&mut self, src: R, dest: usize)
where
T: Copy,
{
let src_start = match src.start_bound() {
ops::Bound::Included(&n) => n,
ops::Bound::Excluded(&n) => n
.checked_add(1)
.unwrap_or_else(|| slice_index_overflow_fail()),
ops::Bound::Unbounded => 0,
};
let src_end = match src.end_bound() {
ops::Bound::Included(&n) => n
.checked_add(1)
.unwrap_or_else(|| slice_index_overflow_fail()),
ops::Bound::Excluded(&n) => n,
ops::Bound::Unbounded => self.len(),
};
assert!(src_start <= src_end, "src end is before src start");
assert!(src_end <= self.len(), "src is out of bounds");
let count = src_end - src_start;
assert!(dest <= self.len() - count, "dest is out of bounds");
unsafe {
ptr::copy(
self.get_unchecked(src_start),
self.get_unchecked_mut(dest),
count,
);
}
}

/// Swaps all elements in `self` with those in `other`.
///
/// The length of `other` must be the same as `self`.
Expand Down
1 change: 1 addition & 0 deletions src/libcore/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#![feature(inner_deref)]
#![feature(slice_internals)]
#![feature(option_replace)]
#![feature(copy_within)]

extern crate core;
extern crate test;
Expand Down
46 changes: 46 additions & 0 deletions src/libcore/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,3 +1000,49 @@ fn test_align_to_empty_mid() {
assert_eq!(mid.as_ptr() as usize % mem::align_of::<Chunk>(), 0);
}
}

#[test]
fn test_copy_within() {
// Start to end, with a RangeTo.
let mut bytes = *b"Hello, World!";
bytes.copy_within(..3, 10);
assert_eq!(&bytes, b"Hello, WorHel");

// End to start, with a RangeFrom.
let mut bytes = *b"Hello, World!";
bytes.copy_within(10.., 0);
assert_eq!(&bytes, b"ld!lo, World!");

// Overlapping, with a RangeInclusive.
let mut bytes = *b"Hello, World!";
bytes.copy_within(0..=11, 1);
assert_eq!(&bytes, b"HHello, World");

// Whole slice, with a RangeFull.
let mut bytes = *b"Hello, World!";
bytes.copy_within(.., 0);
assert_eq!(&bytes, b"Hello, World!");
}

#[test]
#[should_panic(expected = "src is out of bounds")]
fn test_copy_within_panics_src_too_long() {
let mut bytes = *b"Hello, World!";
// The length is only 13, so 14 is out of bounds.
bytes.copy_within(10..14, 0);
}

#[test]
#[should_panic(expected = "dest is out of bounds")]
fn test_copy_within_panics_dest_too_long() {
let mut bytes = *b"Hello, World!";
// The length is only 13, so a slice of length 4 starting at index 10 is out of bounds.
bytes.copy_within(0..4, 10);
}
#[test]
#[should_panic(expected = "src end is before src start")]
fn test_copy_within_panics_src_inverted() {
let mut bytes = *b"Hello, World!";
// 2 is greater than 1, so this range is invalid.
bytes.copy_within(2..1, 0);
}
2 changes: 1 addition & 1 deletion src/libproc_macro/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub mod rustc;
mod diagnostic;

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

use std::{ascii, fmt, iter};
use std::path::PathBuf;
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1937,8 +1937,7 @@ impl EarlyLintPass for KeywordIdents {
let next_edition = match cx.sess.edition() {
Edition::Edition2015 => {
match &ident.as_str()[..] {
"async" |
"try" => Edition::Edition2018,
"async" | "try" | "dyn" => Edition::Edition2018,
_ => return,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use std::collections::VecDeque;
use std::fmt;
use syntax::symbol::keywords;
use syntax_pos::Span;
use syntax::errors::Applicability;

mod region_name;
mod var_name;
Expand Down Expand Up @@ -540,14 +541,15 @@ impl<'tcx> RegionInferenceContext<'tcx> {
RegionName::Named(name) => format!("{}", name),
RegionName::Synthesized(_) => "'_".to_string(),
};
diag.span_suggestion(
diag.span_suggestion_with_applicability(
span,
&format!(
"to allow this impl Trait to capture borrowed data with lifetime \
`{}`, add `{}` as a constraint",
fr_name, suggestable_fr_name,
),
format!("{} + {}", snippet, suggestable_fr_name),
Applicability::MachineApplicable,
);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_target/spec/netbsd_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub fn opts() -> TargetOptions {
executables: true,
target_family: Some("unix".to_string()),
linker_is_gnu: true,
no_default_libraries: false,
has_rpath: true,
pre_link_args: args,
position_independent_executables: true,
Expand Down
1 change: 0 additions & 1 deletion src/librustc_target/spec/x86_64_rumprun_netbsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub fn target() -> TargetResult {
base.has_rpath = false;
base.position_independent_executables = false;
base.disable_redzone = true;
base.no_default_libraries = false;
base.exe_allocation_crate = None;
base.stack_probes = true;

Expand Down
11 changes: 8 additions & 3 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ impl DocAccessLevels for AccessLevels<DefId> {
pub fn new_handler(error_format: ErrorOutputType,
source_map: Option<Lrc<source_map::SourceMap>>,
treat_err_as_bug: bool,
ui_testing: bool,
) -> errors::Handler {
// rustdoc doesn't override (or allow to override) anything from this that is relevant here, so
// stick to the defaults
Expand All @@ -283,7 +284,7 @@ pub fn new_handler(error_format: ErrorOutputType,
source_map.map(|cm| cm as _),
false,
sessopts.debugging_opts.teach,
).ui_testing(sessopts.debugging_opts.ui_testing)
).ui_testing(ui_testing)
),
ErrorOutputType::Json(pretty) => {
let source_map = source_map.unwrap_or_else(
Expand All @@ -293,7 +294,7 @@ pub fn new_handler(error_format: ErrorOutputType,
None,
source_map,
pretty,
).ui_testing(sessopts.debugging_opts.ui_testing)
).ui_testing(ui_testing)
)
},
ErrorOutputType::Short(color_config) => Box::new(
Expand Down Expand Up @@ -335,6 +336,7 @@ pub fn run_core(search_paths: SearchPaths,
mut manual_passes: Vec<String>,
mut default_passes: passes::DefaultPassOption,
treat_err_as_bug: bool,
ui_testing: bool,
) -> (clean::Crate, RenderInfo, Vec<String>) {
// Parse, resolve, and typecheck the given crate.

Expand Down Expand Up @@ -389,6 +391,8 @@ pub fn run_core(search_paths: SearchPaths,
actually_rustdoc: true,
debugging_opts: config::DebuggingOptions {
force_unstable_if_unmarked,
treat_err_as_bug,
ui_testing,
..config::basic_debugging_options()
},
error_format,
Expand All @@ -400,7 +404,8 @@ pub fn run_core(search_paths: SearchPaths,
let source_map = Lrc::new(source_map::SourceMap::new(sessopts.file_path_mapping()));
let diagnostic_handler = new_handler(error_format,
Some(source_map.clone()),
treat_err_as_bug);
treat_err_as_bug,
ui_testing);

let mut sess = session::build_session_(
sessopts, cpath, diagnostic_handler, source_map,
Expand Down
12 changes: 9 additions & 3 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,11 @@ fn main_args(args: &[String]) -> isize {
let treat_err_as_bug = matches.opt_strs("Z").iter().any(|x| {
*x == "treat-err-as-bug"
});
let ui_testing = matches.opt_strs("Z").iter().any(|x| {
*x == "ui-testing"
});

let diag = core::new_handler(error_format, None, treat_err_as_bug);
let diag = core::new_handler(error_format, None, treat_err_as_bug, ui_testing);

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

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

Expand All @@ -715,7 +721,7 @@ where R: 'static + Send,
display_warnings, crate_name.clone(),
force_unstable_if_unmarked, edition, cg, error_format,
lint_opts, lint_cap, describe_lints, manual_passes, default_passes,
treat_err_as_bug);
treat_err_as_bug, ui_testing);

info!("finished with rustc");

Expand Down
Loading

0 comments on commit efaf8bf

Please sign in to comment.