Skip to content

Commit 592e9c3

Browse files
committed
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
2 parents 4ad6248 + f8c026b commit 592e9c3

File tree

24 files changed

+100
-56
lines changed

24 files changed

+100
-56
lines changed

src/liballoc/collections/btree/node.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::
11911191
let right_len = right_node.len();
11921192

11931193
// necessary for correctness, but in a private module
1194-
assert!(left_len + right_len + 1 <= CAPACITY);
1194+
assert!(left_len + right_len < CAPACITY);
11951195

11961196
unsafe {
11971197
ptr::write(

src/libcore/iter/adapters/mod.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1894,9 +1894,7 @@ where
18941894
let to_skip = self.n;
18951895
self.n = 0;
18961896
// nth(n) skips n+1
1897-
if self.iter.nth(to_skip - 1).is_none() {
1898-
return None;
1899-
}
1897+
self.iter.nth(to_skip - 1)?;
19001898
}
19011899
self.iter.nth(n)
19021900
}
@@ -1916,9 +1914,7 @@ where
19161914
fn last(mut self) -> Option<I::Item> {
19171915
if self.n > 0 {
19181916
// nth(n) skips n+1
1919-
if self.iter.nth(self.n - 1).is_none() {
1920-
return None;
1921-
}
1917+
self.iter.nth(self.n - 1)?;
19221918
}
19231919
self.iter.last()
19241920
}

src/librustc/hir/map/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,8 @@ impl<'hir> Map<'hir> {
338338
Node::Variant(_) => DefKind::Variant,
339339
Node::Ctor(variant_data) => {
340340
// FIXME(eddyb) is this even possible, if we have a `Node::Ctor`?
341-
if variant_data.ctor_hir_id().is_none() {
342-
return None;
343-
}
341+
variant_data.ctor_hir_id()?;
342+
344343
let ctor_of = match self.find(self.get_parent_node(hir_id)) {
345344
Some(Node::Item(..)) => def::CtorOf::Struct,
346345
Some(Node::Variant(..)) => def::CtorOf::Variant,

src/librustc/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl<'tcx> Body<'tcx> {
189189
) -> Self {
190190
// We need `arg_count` locals, and one for the return place.
191191
assert!(
192-
local_decls.len() >= arg_count + 1,
192+
local_decls.len() > arg_count,
193193
"expected at least {} locals, got {}",
194194
arg_count + 1,
195195
local_decls.len()

src/librustc/ty/instance.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ impl<'tcx> Instance<'tcx> {
115115
}
116116

117117
// If this a non-generic instance, it cannot be a shared monomorphization.
118-
if self.substs.non_erasable_generics().next().is_none() {
119-
return None;
120-
}
118+
self.substs.non_erasable_generics().next()?;
121119

122120
match self.def {
123121
InstanceDef::Item(def_id) => tcx

src/librustc_codegen_llvm/va_arg.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ pub(super) fn emit_va_arg(
117117
// Windows x86_64
118118
("x86_64", true) => {
119119
let target_ty_size = bx.cx.size_of(target_ty).bytes();
120-
let indirect =
121-
if target_ty_size > 8 || !target_ty_size.is_power_of_two() { true } else { false };
120+
let indirect: bool = target_ty_size > 8 || !target_ty_size.is_power_of_two();
122121
emit_ptr_va_arg(bx, addr, target_ty, indirect, Align::from_bytes(8).unwrap(), false)
123122
}
124123
// For all other architecture/OS combinations fall back to using

src/librustc_codegen_ssa/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ pub fn get_linker(sess: &Session, linker: &Path, flavor: LinkerFlavor) -> (PathB
186186
if flavor == LinkerFlavor::Msvc && t.target_vendor == "uwp" {
187187
if let Some(ref tool) = msvc_tool {
188188
let original_path = tool.path();
189-
if let Some(ref root_lib_path) = original_path.ancestors().skip(4).next() {
189+
if let Some(ref root_lib_path) = original_path.ancestors().nth(4) {
190190
let arch = match t.arch.as_str() {
191191
"x86_64" => Some("x64".to_string()),
192192
"x86" => Some("x86".to_string()),

src/librustc_error_codes/error_codes/E0379.md

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
A trait method was declared const.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0379
6+
#![feature(const_fn)]
7+
8+
trait Foo {
9+
const fn bar() -> u32; // error!
10+
}
11+
```
12+
113
Trait methods cannot be declared `const` by design. For more information, see
214
[RFC 911].
315

src/librustc_expand/mbe/transcribe.rs

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

src/librustc_incremental/persist/work_product.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ pub fn copy_cgu_workproducts_to_incr_comp_cache_dir(
1313
files: &[(WorkProductFileKind, PathBuf)],
1414
) -> Option<(WorkProductId, WorkProduct)> {
1515
debug!("copy_cgu_workproducts_to_incr_comp_cache_dir({:?},{:?})", cgu_name, files);
16-
if sess.opts.incremental.is_none() {
17-
return None;
18-
}
16+
sess.opts.incremental.as_ref()?;
1917

2018
let saved_files = files
2119
.iter()

src/librustc_infer/traits/error_reporting/suggestions.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
401401
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
402402
let refs_number =
403403
snippet.chars().filter(|c| !c.is_whitespace()).take_while(|c| *c == '&').count();
404-
if let Some('\'') =
405-
snippet.chars().filter(|c| !c.is_whitespace()).skip(refs_number).next()
406-
{
404+
if let Some('\'') = snippet.chars().filter(|c| !c.is_whitespace()).nth(refs_number) {
407405
// Do not suggest removal of borrow from type arguments.
408406
return;
409407
}
@@ -464,9 +462,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
464462
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
465463
let refs_number =
466464
snippet.chars().filter(|c| !c.is_whitespace()).take_while(|c| *c == '&').count();
467-
if let Some('\'') =
468-
snippet.chars().filter(|c| !c.is_whitespace()).skip(refs_number).next()
469-
{
465+
if let Some('\'') = snippet.chars().filter(|c| !c.is_whitespace()).nth(refs_number) {
470466
// Do not suggest removal of borrow from type arguments.
471467
return;
472468
}

src/librustc_mir/interpret/cast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
202202

203203
Char => {
204204
// `u8` to `char` cast
205-
debug_assert_eq!(v as u8 as u128, v);
205+
assert_eq!(v as u8 as u128, v);
206206
Ok(Scalar::from_uint(v, Size::from_bytes(4)))
207207
}
208208

src/librustc_mir/interpret/operator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
234234
BitXor => (Scalar::from_uint(l ^ r, size), left_layout.ty),
235235

236236
Add | Sub | Mul | Rem | Div => {
237-
debug_assert!(!left_layout.abi.is_signed());
237+
assert!(!left_layout.abi.is_signed());
238238
let op: fn(u128, u128) -> (u128, bool) = match bin_op {
239239
Add => u128::overflowing_add,
240240
Sub => u128::overflowing_sub,

src/librustc_mir/interpret/step.rs

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

src/librustc_mir/interpret/terminator.rs

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

src/librustc_mir/interpret/validity.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,16 @@ fn wrapping_range_contains(r: &RangeInclusive<u128>, test: u128) -> bool {
144144
// "expected something <in the given range>" makes sense.
145145
fn wrapping_range_format(r: &RangeInclusive<u128>, max_hi: u128) -> String {
146146
let (lo, hi) = r.clone().into_inner();
147-
debug_assert!(hi <= max_hi);
147+
assert!(hi <= max_hi);
148148
if lo > hi {
149149
format!("less or equal to {}, or greater or equal to {}", hi, lo)
150150
} else if lo == hi {
151151
format!("equal to {}", lo)
152152
} else if lo == 0 {
153-
debug_assert!(hi < max_hi, "should not be printing if the range covers everything");
153+
assert!(hi < max_hi, "should not be printing if the range covers everything");
154154
format!("less or equal to {}", hi)
155155
} else if hi == max_hi {
156-
debug_assert!(lo > 0, "should not be printing if the range covers everything");
156+
assert!(lo > 0, "should not be printing if the range covers everything");
157157
format!("greater or equal to {}", lo)
158158
} else {
159159
format!("in the range {:?}", r)

src/librustc_mir/monomorphize/collector.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -824,11 +824,8 @@ fn find_vtable_types_for_unsizing<'tcx>(
824824
(&ty::Adt(source_adt_def, source_substs), &ty::Adt(target_adt_def, target_substs)) => {
825825
assert_eq!(source_adt_def, target_adt_def);
826826

827-
let kind = monomorphize::custom_coerce_unsize_info(tcx, source_ty, target_ty);
828-
829-
let coerce_index = match kind {
830-
CustomCoerceUnsized::Struct(i) => i,
831-
};
827+
let CustomCoerceUnsized::Struct(coerce_index) =
828+
monomorphize::custom_coerce_unsize_info(tcx, source_ty, target_ty);
832829

833830
let source_fields = &source_adt_def.non_enum_variant().fields;
834831
let target_fields = &target_adt_def.non_enum_variant().fields;

src/librustc_span/source_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ impl SourceMap {
689689
whitespace_found = true;
690690
}
691691

692-
if whitespace_found && !c.is_whitespace() { false } else { true }
692+
!whitespace_found || c.is_whitespace()
693693
})
694694
}
695695

src/librustc_typeck/check/demand.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
236236
//
237237
// FIXME? Other potential candidate methods: `as_ref` and
238238
// `as_mut`?
239-
.find(|a| a.check_name(sym::rustc_conversion_suggestion))
240-
.is_some()
239+
.any(|a| a.check_name(sym::rustc_conversion_suggestion))
241240
});
242241

243242
methods

src/librustc_typeck/coherence/inherent_impls_overlap.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,11 @@ impl InherentOverlapChecker<'tcx> {
2323
let impl_items2 = self.tcx.associated_items(impl2);
2424

2525
for item1 in impl_items1.in_definition_order() {
26-
let collision = impl_items2
27-
.filter_by_name_unhygienic(item1.ident.name)
28-
.find(|item2| {
29-
// Symbols and namespace match, compare hygienically.
30-
item1.kind.namespace() == item2.kind.namespace()
31-
&& item1.ident.modern() == item2.ident.modern()
32-
})
33-
.is_some();
26+
let collision = impl_items2.filter_by_name_unhygienic(item1.ident.name).any(|item2| {
27+
// Symbols and namespace match, compare hygienically.
28+
item1.kind.namespace() == item2.kind.namespace()
29+
&& item1.ident.modern() == item2.ident.modern()
30+
});
3431

3532
if collision {
3633
return true;

src/rustllvm/PassWrapper.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -868,15 +868,23 @@ LLVMRustOptimizeWithNewPassManager(
868868
} else {
869869
for (const auto &C : PipelineStartEPCallbacks)
870870
PB.registerPipelineStartEPCallback(C);
871-
for (const auto &C : OptimizerLastEPCallbacks)
872-
PB.registerOptimizerLastEPCallback(C);
871+
if (OptStage != LLVMRustOptStage::PreLinkThinLTO) {
872+
for (const auto &C : OptimizerLastEPCallbacks)
873+
PB.registerOptimizerLastEPCallback(C);
874+
}
873875

874876
switch (OptStage) {
875877
case LLVMRustOptStage::PreLinkNoLTO:
876878
MPM = PB.buildPerModuleDefaultPipeline(OptLevel, DebugPassManager);
877879
break;
878880
case LLVMRustOptStage::PreLinkThinLTO:
879881
MPM = PB.buildThinLTOPreLinkDefaultPipeline(OptLevel, DebugPassManager);
882+
if (!OptimizerLastEPCallbacks.empty()) {
883+
FunctionPassManager FPM(DebugPassManager);
884+
for (const auto &C : OptimizerLastEPCallbacks)
885+
C(FPM, OptLevel);
886+
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
887+
}
880888
break;
881889
case LLVMRustOptStage::PreLinkFatLTO:
882890
MPM = PB.buildLTOPreLinkDefaultPipeline(OptLevel, DebugPassManager);

src/test/codegen/sanitizer-recover.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
//[MSAN-RECOVER-LTO] compile-flags: -Zsanitizer=memory -Zsanitizer-recover=memory -C lto=fat
1515
//
1616
// MSAN-NOT: @__msan_keep_going
17-
// MSAN-RECOVER: @__msan_keep_going = weak_odr {{.*}} constant i32 1
18-
// MSAN-RECOVER-LTO: @__msan_keep_going = weak_odr {{.*}} constant i32 1
17+
// MSAN-RECOVER: @__msan_keep_going = weak_odr {{.*}}constant i32 1
18+
// MSAN-RECOVER-LTO: @__msan_keep_going = weak_odr {{.*}}constant i32 1
1919

2020
// ASAN-LABEL: define i32 @penguin(
2121
// ASAN: call void @__asan_report_load4(i64 %0)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Regression test for sanitizer function instrumentation passes not
2+
// being run when compiling with new LLVM pass manager and ThinLTO.
3+
// Note: The issue occured only on non-zero opt-level.
4+
//
5+
// min-llvm-version 9.0
6+
// needs-sanitizer-support
7+
// only-x86_64
8+
//
9+
// no-prefer-dynamic
10+
// revisions: opt0 opt1
11+
// compile-flags: -Znew-llvm-pass-manager=yes -Zsanitizer=address -Clto=thin
12+
//[opt0]compile-flags: -Copt-level=0
13+
//[opt1]compile-flags: -Copt-level=1
14+
// run-fail
15+
// error-pattern: ERROR: AddressSanitizer: stack-use-after-scope
16+
17+
static mut P: *mut usize = std::ptr::null_mut();
18+
19+
fn main() {
20+
unsafe {
21+
{
22+
let mut x = 0;
23+
P = &mut x;
24+
}
25+
std::ptr::write_volatile(P, 123);
26+
}
27+
}

src/tools/compiletest/src/header/tests.rs

+18
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,24 @@ fn no_system_llvm() {
109109
assert!(parse_rs(&config, "// no-system-llvm").ignore);
110110
}
111111

112+
#[test]
113+
fn llvm_version() {
114+
let mut config = config();
115+
116+
config.llvm_version = Some("8.1.2-rust".to_owned());
117+
assert!(parse_rs(&config, "// min-llvm-version 9.0").ignore);
118+
119+
config.llvm_version = Some("9.0.1-rust-1.43.0-dev".to_owned());
120+
assert!(parse_rs(&config, "// min-llvm-version 9.2").ignore);
121+
122+
config.llvm_version = Some("9.3.1-rust-1.43.0-dev".to_owned());
123+
assert!(!parse_rs(&config, "// min-llvm-version 9.2").ignore);
124+
125+
// FIXME.
126+
// config.llvm_version = Some("10.0.0-rust".to_owned());
127+
// assert!(!parse_rs(&config, "// min-llvm-version 9.0").ignore);
128+
}
129+
112130
#[test]
113131
fn ignore_target() {
114132
let mut config = config();

0 commit comments

Comments
 (0)