Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #69678

Merged
merged 19 commits into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6f568e7
miri engine: turn some debug_assert into assert
RalfJung Feb 28, 2020
5982e9d
downgrade some assertions to debug_ again
RalfJung Feb 29, 2020
e364c28
Use let instead of match to get value of enum with single variant.
matthiaskrgr Mar 2, 2020
5abaeb3
Simplify conditions like x + 1 <= y to x < y
matthiaskrgr Mar 2, 2020
c287d86
Use .nth(x) instead of .skip(x).next() on iterators.
matthiaskrgr Mar 2, 2020
ae34b9d
Use .any(x) instead of .find(x).is_some() on iterators.
matthiaskrgr Mar 2, 2020
1018385
Improve weird formatting by moving comment inside else-code block.
matthiaskrgr Mar 2, 2020
df716b0
use conditions directly
matthiaskrgr Mar 3, 2020
a61e134
Invoke OptimizerLastEPCallbacks in PreLinkThinLTO
tmiasko Mar 3, 2020
52c5f2a
Add test for -Znew-llvm-pass-manager -Clto=thin -Zsanitizer=...
tmiasko Mar 3, 2020
b0e288d
Fix check for __msan_keep_going in sanitizer-recover test
tmiasko Mar 3, 2020
ecae6e4
use question mark operator in a few places.
matthiaskrgr Mar 1, 2020
c92267a
Add explanation for E0379
GuillaumeGomez Mar 3, 2020
fab54fc
Rollup merge of #69565 - RalfJung:assert, r=eddyb
Dylan-DPC Mar 3, 2020
2cfab73
Rollup merge of #69621 - matthiaskrgr:q, r=petrochenkov
Dylan-DPC Mar 3, 2020
8ca3e59
Rollup merge of #69650 - matthiaskrgr:clnp, r=varkor
Dylan-DPC Mar 3, 2020
099cd7f
Rollup merge of #69653 - matthiaskrgr:needless_bool, r=Dylan-DPC
Dylan-DPC Mar 3, 2020
587ca17
Rollup merge of #69665 - tmiasko:new-pass-manager-thin-lto-opt, r=nikic
Dylan-DPC Mar 3, 2020
f8c026b
Rollup merge of #69670 - GuillaumeGomez:explain-e0379, r=Dylan-DPC
Dylan-DPC Mar 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/liballoc/collections/btree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 2 additions & 6 deletions src/libcore/iter/adapters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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()
}
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 1 addition & 3 deletions src/librustc/ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_codegen_llvm/va_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
12 changes: 12 additions & 0 deletions src/librustc_error_codes/error_codes/E0379.md
Original file line number Diff line number Diff line change
@@ -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].

Expand Down
6 changes: 3 additions & 3 deletions src/librustc_expand/mbe/transcribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_incremental/persist/work_product.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 2 additions & 6 deletions src/librustc_infer/traits/error_reporting/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/terminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 2 additions & 5 deletions src/librustc_mir/monomorphize/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_span/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ impl SourceMap {
whitespace_found = true;
}

if whitespace_found && !c.is_whitespace() { false } else { true }
!whitespace_found || c.is_whitespace()
})
}

Expand Down
3 changes: 1 addition & 2 deletions src/librustc_typeck/check/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 5 additions & 8 deletions src/librustc_typeck/coherence/inherent_impls_overlap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 10 additions & 2 deletions src/rustllvm/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,15 +868,23 @@ 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:
MPM = PB.buildPerModuleDefaultPipeline(OptLevel, DebugPassManager);
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);
Expand Down
4 changes: 2 additions & 2 deletions src/test/codegen/sanitizer-recover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions src/test/ui/sanitize/new-llvm-pass-manager-thin-lto.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}
18 changes: 18 additions & 0 deletions src/tools/compiletest/src/header/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down