Auto merge of #69678 - Dylan-DPC:rollup-yoaueud, r=Dylan-DPC

Rollup of 6 pull requests

Successful merges:

 - #69565 (miri engine: turn some debug_assert into assert)
 - #69621 (use question mark operator in a few places.)
 - #69650 (cleanup more iterator usages (and other things))
 - #69653 (use conditions directly)
 - #69665 (Invoke OptimizerLastEPCallbacks in PreLinkThinLTO)
 - #69670 (Add explanation for E0379)

Failed merges:

r? @ghost
This commit is contained in:
bors 2020-03-03 23:26:38 +00:00
commit 592e9c3700
24 changed files with 100 additions and 56 deletions

View File

@ -1191,7 +1191,7 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::
let right_len = right_node.len();
// necessary for correctness, but in a private module
assert!(left_len + right_len + 1 <= CAPACITY);
assert!(left_len + right_len < CAPACITY);
unsafe {
ptr::write(

View File

@ -1894,9 +1894,7 @@ where
let to_skip = self.n;
self.n = 0;
// nth(n) skips n+1
if self.iter.nth(to_skip - 1).is_none() {
return None;
}
self.iter.nth(to_skip - 1)?;
}
self.iter.nth(n)
}
@ -1916,9 +1914,7 @@ where
fn last(mut self) -> Option<I::Item> {
if self.n > 0 {
// nth(n) skips n+1
if self.iter.nth(self.n - 1).is_none() {
return None;
}
self.iter.nth(self.n - 1)?;
}
self.iter.last()
}

View File

@ -338,9 +338,8 @@ impl<'hir> Map<'hir> {
Node::Variant(_) => DefKind::Variant,
Node::Ctor(variant_data) => {
// FIXME(eddyb) is this even possible, if we have a `Node::Ctor`?
if variant_data.ctor_hir_id().is_none() {
return None;
}
variant_data.ctor_hir_id()?;
let ctor_of = match self.find(self.get_parent_node(hir_id)) {
Some(Node::Item(..)) => def::CtorOf::Struct,
Some(Node::Variant(..)) => def::CtorOf::Variant,

View File

@ -189,7 +189,7 @@ impl<'tcx> Body<'tcx> {
) -> Self {
// We need `arg_count` locals, and one for the return place.
assert!(
local_decls.len() >= arg_count + 1,
local_decls.len() > arg_count,
"expected at least {} locals, got {}",
arg_count + 1,
local_decls.len()

View File

@ -115,9 +115,7 @@ impl<'tcx> Instance<'tcx> {
}
// If this a non-generic instance, it cannot be a shared monomorphization.
if self.substs.non_erasable_generics().next().is_none() {
return None;
}
self.substs.non_erasable_generics().next()?;
match self.def {
InstanceDef::Item(def_id) => tcx

View File

@ -117,8 +117,7 @@ pub(super) fn emit_va_arg(
// Windows x86_64
("x86_64", true) => {
let target_ty_size = bx.cx.size_of(target_ty).bytes();
let indirect =
if target_ty_size > 8 || !target_ty_size.is_power_of_two() { true } else { false };
let indirect: bool = target_ty_size > 8 || !target_ty_size.is_power_of_two();
emit_ptr_va_arg(bx, addr, target_ty, indirect, Align::from_bytes(8).unwrap(), false)
}
// For all other architecture/OS combinations fall back to using

View File

@ -186,7 +186,7 @@ pub fn get_linker(sess: &Session, linker: &Path, flavor: LinkerFlavor) -> (PathB
if flavor == LinkerFlavor::Msvc && t.target_vendor == "uwp" {
if let Some(ref tool) = msvc_tool {
let original_path = tool.path();
if let Some(ref root_lib_path) = original_path.ancestors().skip(4).next() {
if let Some(ref root_lib_path) = original_path.ancestors().nth(4) {
let arch = match t.arch.as_str() {
"x86_64" => Some("x64".to_string()),
"x86" => Some("x86".to_string()),

View File

@ -1,3 +1,15 @@
A trait method was declared const.
Erroneous code example:
```compile_fail,E0379
#![feature(const_fn)]
trait Foo {
const fn bar() -> u32; // error!
}
```
Trait methods cannot be declared `const` by design. For more information, see
[RFC 911].

View File

@ -119,9 +119,9 @@ pub(super) fn transcribe(
let tree = if let Some(tree) = stack.last_mut().unwrap().next() {
// If it still has a TokenTree we have not looked at yet, use that tree.
tree
}
// The else-case never produces a value for `tree` (it `continue`s or `return`s).
else {
} else {
// This else-case never produces a value for `tree` (it `continue`s or `return`s).
// Otherwise, if we have just reached the end of a sequence and we can keep repeating,
// go back to the beginning of the sequence.
if let Frame::Sequence { idx, sep, .. } = stack.last_mut().unwrap() {

View File

@ -13,9 +13,7 @@ pub fn copy_cgu_workproducts_to_incr_comp_cache_dir(
files: &[(WorkProductFileKind, PathBuf)],
) -> Option<(WorkProductId, WorkProduct)> {
debug!("copy_cgu_workproducts_to_incr_comp_cache_dir({:?},{:?})", cgu_name, files);
if sess.opts.incremental.is_none() {
return None;
}
sess.opts.incremental.as_ref()?;
let saved_files = files
.iter()

View File

@ -401,9 +401,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
let refs_number =
snippet.chars().filter(|c| !c.is_whitespace()).take_while(|c| *c == '&').count();
if let Some('\'') =
snippet.chars().filter(|c| !c.is_whitespace()).skip(refs_number).next()
{
if let Some('\'') = snippet.chars().filter(|c| !c.is_whitespace()).nth(refs_number) {
// Do not suggest removal of borrow from type arguments.
return;
}
@ -464,9 +462,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
let refs_number =
snippet.chars().filter(|c| !c.is_whitespace()).take_while(|c| *c == '&').count();
if let Some('\'') =
snippet.chars().filter(|c| !c.is_whitespace()).skip(refs_number).next()
{
if let Some('\'') = snippet.chars().filter(|c| !c.is_whitespace()).nth(refs_number) {
// Do not suggest removal of borrow from type arguments.
return;
}

View File

@ -202,7 +202,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
Char => {
// `u8` to `char` cast
debug_assert_eq!(v as u8 as u128, v);
assert_eq!(v as u8 as u128, v);
Ok(Scalar::from_uint(v, Size::from_bytes(4)))
}

View File

@ -234,7 +234,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
BitXor => (Scalar::from_uint(l ^ r, size), left_layout.ty),
Add | Sub | Mul | Rem | Div => {
debug_assert!(!left_layout.abi.is_signed());
assert!(!left_layout.abi.is_signed());
let op: fn(u128, u128) -> (u128, bool) = match bin_op {
Add => u128::overflowing_add,
Sub => u128::overflowing_sub,

View File

@ -287,7 +287,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
self.eval_terminator(terminator)?;
if !self.stack.is_empty() {
// This should change *something*
debug_assert!(self.cur_frame() != old_stack || self.frame().block != old_bb);
assert!(self.cur_frame() != old_stack || self.frame().block != old_bb);
if let Some(block) = self.frame().block {
info!("// executing {:?}", block);
}

View File

@ -172,7 +172,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
}
let caller_arg = caller_arg.next().ok_or_else(|| err_unsup!(FunctionArgCountMismatch))?;
if rust_abi {
debug_assert!(!caller_arg.layout.is_zst(), "ZSTs must have been already filtered out");
assert!(!caller_arg.layout.is_zst(), "ZSTs must have been already filtered out");
}
// Now, check
if !Self::check_argument_compat(rust_abi, caller_arg.layout, callee_arg.layout) {

View File

@ -144,16 +144,16 @@ fn wrapping_range_contains(r: &RangeInclusive<u128>, test: u128) -> bool {
// "expected something <in the given range>" makes sense.
fn wrapping_range_format(r: &RangeInclusive<u128>, max_hi: u128) -> String {
let (lo, hi) = r.clone().into_inner();
debug_assert!(hi <= max_hi);
assert!(hi <= max_hi);
if lo > hi {
format!("less or equal to {}, or greater or equal to {}", hi, lo)
} else if lo == hi {
format!("equal to {}", lo)
} else if lo == 0 {
debug_assert!(hi < max_hi, "should not be printing if the range covers everything");
assert!(hi < max_hi, "should not be printing if the range covers everything");
format!("less or equal to {}", hi)
} else if hi == max_hi {
debug_assert!(lo > 0, "should not be printing if the range covers everything");
assert!(lo > 0, "should not be printing if the range covers everything");
format!("greater or equal to {}", lo)
} else {
format!("in the range {:?}", r)

View File

@ -824,11 +824,8 @@ fn find_vtable_types_for_unsizing<'tcx>(
(&ty::Adt(source_adt_def, source_substs), &ty::Adt(target_adt_def, target_substs)) => {
assert_eq!(source_adt_def, target_adt_def);
let kind = monomorphize::custom_coerce_unsize_info(tcx, source_ty, target_ty);
let coerce_index = match kind {
CustomCoerceUnsized::Struct(i) => i,
};
let CustomCoerceUnsized::Struct(coerce_index) =
monomorphize::custom_coerce_unsize_info(tcx, source_ty, target_ty);
let source_fields = &source_adt_def.non_enum_variant().fields;
let target_fields = &target_adt_def.non_enum_variant().fields;

View File

@ -689,7 +689,7 @@ impl SourceMap {
whitespace_found = true;
}
if whitespace_found && !c.is_whitespace() { false } else { true }
!whitespace_found || c.is_whitespace()
})
}

View File

@ -236,8 +236,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
//
// FIXME? Other potential candidate methods: `as_ref` and
// `as_mut`?
.find(|a| a.check_name(sym::rustc_conversion_suggestion))
.is_some()
.any(|a| a.check_name(sym::rustc_conversion_suggestion))
});
methods

View File

@ -23,14 +23,11 @@ impl InherentOverlapChecker<'tcx> {
let impl_items2 = self.tcx.associated_items(impl2);
for item1 in impl_items1.in_definition_order() {
let collision = impl_items2
.filter_by_name_unhygienic(item1.ident.name)
.find(|item2| {
// Symbols and namespace match, compare hygienically.
item1.kind.namespace() == item2.kind.namespace()
&& item1.ident.modern() == item2.ident.modern()
})
.is_some();
let collision = impl_items2.filter_by_name_unhygienic(item1.ident.name).any(|item2| {
// Symbols and namespace match, compare hygienically.
item1.kind.namespace() == item2.kind.namespace()
&& item1.ident.modern() == item2.ident.modern()
});
if collision {
return true;

View File

@ -868,8 +868,10 @@ LLVMRustOptimizeWithNewPassManager(
} else {
for (const auto &C : PipelineStartEPCallbacks)
PB.registerPipelineStartEPCallback(C);
for (const auto &C : OptimizerLastEPCallbacks)
PB.registerOptimizerLastEPCallback(C);
if (OptStage != LLVMRustOptStage::PreLinkThinLTO) {
for (const auto &C : OptimizerLastEPCallbacks)
PB.registerOptimizerLastEPCallback(C);
}
switch (OptStage) {
case LLVMRustOptStage::PreLinkNoLTO:
@ -877,6 +879,12 @@ LLVMRustOptimizeWithNewPassManager(
break;
case LLVMRustOptStage::PreLinkThinLTO:
MPM = PB.buildThinLTOPreLinkDefaultPipeline(OptLevel, DebugPassManager);
if (!OptimizerLastEPCallbacks.empty()) {
FunctionPassManager FPM(DebugPassManager);
for (const auto &C : OptimizerLastEPCallbacks)
C(FPM, OptLevel);
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
}
break;
case LLVMRustOptStage::PreLinkFatLTO:
MPM = PB.buildLTOPreLinkDefaultPipeline(OptLevel, DebugPassManager);

View File

@ -14,8 +14,8 @@
//[MSAN-RECOVER-LTO] compile-flags: -Zsanitizer=memory -Zsanitizer-recover=memory -C lto=fat
//
// MSAN-NOT: @__msan_keep_going
// MSAN-RECOVER: @__msan_keep_going = weak_odr {{.*}} constant i32 1
// MSAN-RECOVER-LTO: @__msan_keep_going = weak_odr {{.*}} constant i32 1
// MSAN-RECOVER: @__msan_keep_going = weak_odr {{.*}}constant i32 1
// MSAN-RECOVER-LTO: @__msan_keep_going = weak_odr {{.*}}constant i32 1
// ASAN-LABEL: define i32 @penguin(
// ASAN: call void @__asan_report_load4(i64 %0)

View File

@ -0,0 +1,27 @@
// Regression test for sanitizer function instrumentation passes not
// being run when compiling with new LLVM pass manager and ThinLTO.
// Note: The issue occured only on non-zero opt-level.
//
// min-llvm-version 9.0
// needs-sanitizer-support
// only-x86_64
//
// no-prefer-dynamic
// revisions: opt0 opt1
// compile-flags: -Znew-llvm-pass-manager=yes -Zsanitizer=address -Clto=thin
//[opt0]compile-flags: -Copt-level=0
//[opt1]compile-flags: -Copt-level=1
// run-fail
// error-pattern: ERROR: AddressSanitizer: stack-use-after-scope
static mut P: *mut usize = std::ptr::null_mut();
fn main() {
unsafe {
{
let mut x = 0;
P = &mut x;
}
std::ptr::write_volatile(P, 123);
}
}

View File

@ -109,6 +109,24 @@ fn no_system_llvm() {
assert!(parse_rs(&config, "// no-system-llvm").ignore);
}
#[test]
fn llvm_version() {
let mut config = config();
config.llvm_version = Some("8.1.2-rust".to_owned());
assert!(parse_rs(&config, "// min-llvm-version 9.0").ignore);
config.llvm_version = Some("9.0.1-rust-1.43.0-dev".to_owned());
assert!(parse_rs(&config, "// min-llvm-version 9.2").ignore);
config.llvm_version = Some("9.3.1-rust-1.43.0-dev".to_owned());
assert!(!parse_rs(&config, "// min-llvm-version 9.2").ignore);
// FIXME.
// config.llvm_version = Some("10.0.0-rust".to_owned());
// assert!(!parse_rs(&config, "// min-llvm-version 9.0").ignore);
}
#[test]
fn ignore_target() {
let mut config = config();