From 6f568e72f336cd64fecb240c6aafbe4bf7ed4379 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 28 Feb 2020 22:54:10 +0100 Subject: [PATCH 01/13] miri engine: turn some debug_assert into assert --- src/librustc_mir/interpret/cast.rs | 2 +- src/librustc_mir/interpret/memory.rs | 2 +- src/librustc_mir/interpret/operator.rs | 2 +- src/librustc_mir/interpret/place.rs | 10 ++++------ src/librustc_mir/interpret/step.rs | 2 +- src/librustc_mir/interpret/terminator.rs | 2 +- src/librustc_mir/interpret/validity.rs | 6 +++--- 7 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/librustc_mir/interpret/cast.rs b/src/librustc_mir/interpret/cast.rs index 9461a06690212..78e7db44b8745 100644 --- a/src/librustc_mir/interpret/cast.rs +++ b/src/librustc_mir/interpret/cast.rs @@ -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))) } diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index 1df389d9c8bee..673afc6c06d25 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -195,7 +195,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { kind: MemoryKind, ) -> Pointer { let id = self.tcx.alloc_map.lock().reserve(); - debug_assert_ne!( + assert_ne!( Some(kind), M::STATIC_KIND.map(MemoryKind::Machine), "dynamically allocating static memory" diff --git a/src/librustc_mir/interpret/operator.rs b/src/librustc_mir/interpret/operator.rs index 2e8c94903ca46..3b074e7b5a270 100644 --- a/src/librustc_mir/interpret/operator.rs +++ b/src/librustc_mir/interpret/operator.rs @@ -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, diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index 4f96cb698915d..8215b4c5aa406 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -1130,12 +1130,10 @@ where let layout = self.layout_of(ty)?; // More sanity checks - if cfg!(debug_assertions) { - let (size, align) = self.read_size_and_align_from_vtable(vtable)?; - assert_eq!(size, layout.size); - // only ABI alignment is preserved - assert_eq!(align, layout.align.abi); - } + let (size, align) = self.read_size_and_align_from_vtable(vtable)?; + assert_eq!(size, layout.size); + // only ABI alignment is preserved + assert_eq!(align, layout.align.abi); let mplace = MPlaceTy { mplace: MemPlace { meta: MemPlaceMeta::None, ..*mplace }, layout }; Ok((instance, mplace)) diff --git a/src/librustc_mir/interpret/step.rs b/src/librustc_mir/interpret/step.rs index 7d59c0181a8f3..f298a6677d6dc 100644 --- a/src/librustc_mir/interpret/step.rs +++ b/src/librustc_mir/interpret/step.rs @@ -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); } diff --git a/src/librustc_mir/interpret/terminator.rs b/src/librustc_mir/interpret/terminator.rs index a02a6898c1d71..28922f2c75329 100644 --- a/src/librustc_mir/interpret/terminator.rs +++ b/src/librustc_mir/interpret/terminator.rs @@ -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) { diff --git a/src/librustc_mir/interpret/validity.rs b/src/librustc_mir/interpret/validity.rs index aa2b3040a716f..77c911a516557 100644 --- a/src/librustc_mir/interpret/validity.rs +++ b/src/librustc_mir/interpret/validity.rs @@ -142,16 +142,16 @@ fn wrapping_range_contains(r: &RangeInclusive, test: u128) -> bool { // "expected something " makes sense. fn wrapping_range_format(r: &RangeInclusive, 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) From 5982e9d3ca679866a0533d69a41224c333a5348a Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 29 Feb 2020 10:25:57 +0100 Subject: [PATCH 02/13] downgrade some assertions to debug_ again --- src/librustc_mir/interpret/memory.rs | 2 +- src/librustc_mir/interpret/place.rs | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index 673afc6c06d25..1df389d9c8bee 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -195,7 +195,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { kind: MemoryKind, ) -> Pointer { let id = self.tcx.alloc_map.lock().reserve(); - assert_ne!( + debug_assert_ne!( Some(kind), M::STATIC_KIND.map(MemoryKind::Machine), "dynamically allocating static memory" diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index 8215b4c5aa406..4f96cb698915d 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -1130,10 +1130,12 @@ where let layout = self.layout_of(ty)?; // More sanity checks - let (size, align) = self.read_size_and_align_from_vtable(vtable)?; - assert_eq!(size, layout.size); - // only ABI alignment is preserved - assert_eq!(align, layout.align.abi); + if cfg!(debug_assertions) { + let (size, align) = self.read_size_and_align_from_vtable(vtable)?; + assert_eq!(size, layout.size); + // only ABI alignment is preserved + assert_eq!(align, layout.align.abi); + } let mplace = MPlaceTy { mplace: MemPlace { meta: MemPlaceMeta::None, ..*mplace }, layout }; Ok((instance, mplace)) From e364c283fd15e5bc43ed1b7c0e8c86b0c8bd44d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Mon, 2 Mar 2020 18:43:05 +0100 Subject: [PATCH 03/13] Use let instead of match to get value of enum with single variant. --- src/librustc_mir/monomorphize/collector.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index f6a93363dc109..862a7ef1e73c0 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -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; From 5abaeb3d6712b54f3309df968ebee39e544d0fcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Mon, 2 Mar 2020 18:53:56 +0100 Subject: [PATCH 04/13] Simplify conditions like x + 1 <= y to x < y --- src/liballoc/collections/btree/node.rs | 2 +- src/librustc/mir/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/liballoc/collections/btree/node.rs b/src/liballoc/collections/btree/node.rs index c1bd68a020a68..362755f8b7f63 100644 --- a/src/liballoc/collections/btree/node.rs +++ b/src/liballoc/collections/btree/node.rs @@ -1191,7 +1191,7 @@ impl<'a, K, V> Handle, 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( diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 668240ab42b4c..36818020569b0 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -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() From c287d86d2c535425cdf830e3be11e00fa32c909f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Mon, 2 Mar 2020 19:36:12 +0100 Subject: [PATCH 05/13] Use .nth(x) instead of .skip(x).next() on iterators. --- src/librustc_codegen_ssa/back/link.rs | 2 +- src/librustc_infer/traits/error_reporting/suggestions.rs | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs index 90601521b19f1..61ca7c859abfd 100644 --- a/src/librustc_codegen_ssa/back/link.rs +++ b/src/librustc_codegen_ssa/back/link.rs @@ -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()), diff --git a/src/librustc_infer/traits/error_reporting/suggestions.rs b/src/librustc_infer/traits/error_reporting/suggestions.rs index ed6cfa51cdf18..d05955fb858c0 100644 --- a/src/librustc_infer/traits/error_reporting/suggestions.rs +++ b/src/librustc_infer/traits/error_reporting/suggestions.rs @@ -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; } From ae34b9d996716994de1ce185fa23fc5427905d57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Mon, 2 Mar 2020 20:01:03 +0100 Subject: [PATCH 06/13] Use .any(x) instead of .find(x).is_some() on iterators. --- src/librustc_typeck/check/demand.rs | 3 +-- .../coherence/inherent_impls_overlap.rs | 13 +++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index 0c5f3d3e99d75..bdf587dc321f7 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -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 diff --git a/src/librustc_typeck/coherence/inherent_impls_overlap.rs b/src/librustc_typeck/coherence/inherent_impls_overlap.rs index fcded27463e92..778eee3586b4b 100644 --- a/src/librustc_typeck/coherence/inherent_impls_overlap.rs +++ b/src/librustc_typeck/coherence/inherent_impls_overlap.rs @@ -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; From 10183851fbfa68241a5eeaf9b3cc575172731a6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Mon, 2 Mar 2020 20:17:10 +0100 Subject: [PATCH 07/13] Improve weird formatting by moving comment inside else-code block. --- src/librustc_expand/mbe/transcribe.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc_expand/mbe/transcribe.rs b/src/librustc_expand/mbe/transcribe.rs index 80bf02b1366e0..d12dedf9e0c7a 100644 --- a/src/librustc_expand/mbe/transcribe.rs +++ b/src/librustc_expand/mbe/transcribe.rs @@ -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() { From df716b0e37ed087b8bce20bc04c23efd0fa5b645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Tue, 3 Mar 2020 02:07:15 +0100 Subject: [PATCH 08/13] use conditions directly --- src/librustc_codegen_llvm/va_arg.rs | 3 +-- src/librustc_span/source_map.rs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/librustc_codegen_llvm/va_arg.rs b/src/librustc_codegen_llvm/va_arg.rs index 9bc3eec60ae04..a552f2cdb78aa 100644 --- a/src/librustc_codegen_llvm/va_arg.rs +++ b/src/librustc_codegen_llvm/va_arg.rs @@ -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 diff --git a/src/librustc_span/source_map.rs b/src/librustc_span/source_map.rs index 39601ad76222c..e0bbaf730a537 100644 --- a/src/librustc_span/source_map.rs +++ b/src/librustc_span/source_map.rs @@ -689,7 +689,7 @@ impl SourceMap { whitespace_found = true; } - if whitespace_found && !c.is_whitespace() { false } else { true } + !whitespace_found || c.is_whitespace() }) } From a61e13423e57380a08ea1475db57fc30cb7deb15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Tue, 3 Mar 2020 00:00:00 +0000 Subject: [PATCH 09/13] Invoke OptimizerLastEPCallbacks in PreLinkThinLTO The default ThinLTO pre-link pipeline does not include optimizer last extension points. Thus, when using the new LLVM pass manager & ThinLTO & sanitizers on any opt-level different from zero, the sanitizer function passes would be omitted from the pipeline. Add optimizer last extensions points manually to the pipeline, but guard registration with stage check in the case this behaviour changes in the future. --- src/rustllvm/PassWrapper.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/rustllvm/PassWrapper.cpp b/src/rustllvm/PassWrapper.cpp index 65071c3ed86e0..90d24d20737db 100644 --- a/src/rustllvm/PassWrapper.cpp +++ b/src/rustllvm/PassWrapper.cpp @@ -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); From 52c5f2a577bdc5181af96eb6a2f82cd502f92f20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Tue, 3 Mar 2020 00:00:00 +0000 Subject: [PATCH 10/13] Add test for -Znew-llvm-pass-manager -Clto=thin -Zsanitizer=... Additionally verify that the current implementation of LLVM version check (which uses lexicographic ordering) is good enough to exclude versions before LLVM 9, where the new LLVM pass manager is unsupported. --- .../new-llvm-pass-manager-thin-lto.rs | 27 +++++++++++++++++++ src/tools/compiletest/src/header/tests.rs | 18 +++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/test/ui/sanitize/new-llvm-pass-manager-thin-lto.rs diff --git a/src/test/ui/sanitize/new-llvm-pass-manager-thin-lto.rs b/src/test/ui/sanitize/new-llvm-pass-manager-thin-lto.rs new file mode 100644 index 0000000000000..61d5d51cfd248 --- /dev/null +++ b/src/test/ui/sanitize/new-llvm-pass-manager-thin-lto.rs @@ -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); + } +} diff --git a/src/tools/compiletest/src/header/tests.rs b/src/tools/compiletest/src/header/tests.rs index 38fa778219de2..6c478f7e29da4 100644 --- a/src/tools/compiletest/src/header/tests.rs +++ b/src/tools/compiletest/src/header/tests.rs @@ -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(); From b0e288d9f1d8b0f4038bb955a68308b892d54ea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Tue, 3 Mar 2020 00:00:00 +0000 Subject: [PATCH 11/13] Fix check for __msan_keep_going in sanitizer-recover test Match `@__msan_keep_going = weak_odr constant i32 1`. --- src/test/codegen/sanitizer-recover.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/codegen/sanitizer-recover.rs b/src/test/codegen/sanitizer-recover.rs index 9a583725b0bf0..05b4ab5653cc8 100644 --- a/src/test/codegen/sanitizer-recover.rs +++ b/src/test/codegen/sanitizer-recover.rs @@ -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) From ecae6e4260311fac40ef76a84273f6bc865e63d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 1 Mar 2020 22:04:42 +0100 Subject: [PATCH 12/13] use question mark operator in a few places. --- src/libcore/iter/adapters/mod.rs | 8 ++------ src/librustc/hir/map/mod.rs | 5 ++--- src/librustc/ty/instance.rs | 4 +--- src/librustc_incremental/persist/work_product.rs | 4 +--- 4 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/libcore/iter/adapters/mod.rs b/src/libcore/iter/adapters/mod.rs index 58606531a1ace..02dc9b8f82ed2 100644 --- a/src/libcore/iter/adapters/mod.rs +++ b/src/libcore/iter/adapters/mod.rs @@ -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 { 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() } diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 4f7c4153ea173..bd26e02efb749 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -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, diff --git a/src/librustc/ty/instance.rs b/src/librustc/ty/instance.rs index f65822aba4c9e..4014d1d8ae250 100644 --- a/src/librustc/ty/instance.rs +++ b/src/librustc/ty/instance.rs @@ -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 diff --git a/src/librustc_incremental/persist/work_product.rs b/src/librustc_incremental/persist/work_product.rs index 65a742a202ddd..b1861acec0426 100644 --- a/src/librustc_incremental/persist/work_product.rs +++ b/src/librustc_incremental/persist/work_product.rs @@ -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() From c92267a86393df927feccd3d03894a6cfe92dea8 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 3 Mar 2020 13:30:17 +0100 Subject: [PATCH 13/13] Add explanation for E0379 --- src/librustc_error_codes/error_codes/E0379.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/librustc_error_codes/error_codes/E0379.md b/src/librustc_error_codes/error_codes/E0379.md index 3503da6ac2f78..930204847ecd8 100644 --- a/src/librustc_error_codes/error_codes/E0379.md +++ b/src/librustc_error_codes/error_codes/E0379.md @@ -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].