]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #71306 - Dylan-DPC:rollup-kvzc1da, r=Dylan-DPC
authorbors <bors@rust-lang.org>
Sat, 18 Apr 2020 23:06:08 +0000 (23:06 +0000)
committerbors <bors@rust-lang.org>
Sat, 18 Apr 2020 23:06:08 +0000 (23:06 +0000)
Rollup of 5 pull requests

Successful merges:

 - #71271 (Move `MapInPlace` to rustc_data_structures)
 - #71276 (miri-unleashed: test that we detect heap allocations)
 - #71283 (Minor improvements to -Zprofile)
 - #71287 (Explain why we shouldn't add inline attr to into_vec)
 - #71303 (remove build warnings)

Failed merges:

r? @ghost

23 files changed:
src/liballoc/slice.rs
src/librustc_ast/lib.rs
src/librustc_ast/mut_visit.rs
src/librustc_ast/util/map_in_place.rs [deleted file]
src/librustc_builtin_macros/deriving/generic/mod.rs
src/librustc_data_structures/lib.rs
src/librustc_data_structures/map_in_place.rs [new file with mode: 0644]
src/librustc_expand/config.rs
src/librustc_expand/expand.rs
src/librustc_metadata/creader.rs
src/librustc_mir/borrow_check/diagnostics/region_name.rs
src/librustc_mir/transform/check_consts/mod.rs
src/librustc_mir/transform/check_consts/ops.rs
src/librustc_parse/parser/diagnostics.rs
src/librustc_parse/parser/generics.rs
src/librustc_parse/parser/item.rs
src/librustc_resolve/diagnostics.rs
src/librustc_session/config.rs
src/librustc_session/options.rs
src/librustc_trait_selection/traits/error_reporting/suggestions.rs
src/librustc_typeck/astconv.rs
src/test/ui/consts/miri_unleashed/box.rs [new file with mode: 0644]
src/test/ui/consts/miri_unleashed/box.stderr [new file with mode: 0644]

index c13e90a3d7081946f86f9b34a9be3de193dfe063..53477288b59ee8a89d39bb2bbbd5eceb0730ea8e 100644 (file)
@@ -140,6 +140,9 @@ mod hack {
     use crate::string::ToString;
     use crate::vec::Vec;
 
+    // We shouldn't add inline attribute to this since this is used in
+    // `vec!` macro mostly and causes perf regression. See #71204 for
+    // discussion and perf results.
     pub fn into_vec<T>(b: Box<[T]>) -> Vec<T> {
         unsafe {
             let len = b.len();
index 1687f828f240f904ac780c4347cdba8bfb58a258..4ba062625a40dd2891f7c813da8b10fe8fb73142 100644 (file)
@@ -33,7 +33,6 @@ pub mod util {
     pub mod comments;
     pub mod lev_distance;
     pub mod literal;
-    pub mod map_in_place;
     pub mod parser;
 }
 
index a72a60c30b28a049dec4f28b47cb42368534cecd..e66b358c4ac7fac877970ec4d7e99fb57957b4c2 100644 (file)
@@ -11,8 +11,8 @@
 use crate::ptr::P;
 use crate::token::{self, Token};
 use crate::tokenstream::*;
-use crate::util::map_in_place::MapInPlace;
 
+use rustc_data_structures::map_in_place::MapInPlace;
 use rustc_data_structures::sync::Lrc;
 use rustc_span::source_map::{respan, Spanned};
 use rustc_span::Span;
diff --git a/src/librustc_ast/util/map_in_place.rs b/src/librustc_ast/util/map_in_place.rs
deleted file mode 100644 (file)
index a237a6e..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-// FIXME(Centril): Move to rustc_data_structures.
-
-use smallvec::{Array, SmallVec};
-use std::ptr;
-
-pub trait MapInPlace<T>: Sized {
-    fn map_in_place<F>(&mut self, mut f: F)
-    where
-        F: FnMut(T) -> T,
-    {
-        self.flat_map_in_place(|e| Some(f(e)))
-    }
-
-    fn flat_map_in_place<F, I>(&mut self, f: F)
-    where
-        F: FnMut(T) -> I,
-        I: IntoIterator<Item = T>;
-}
-
-impl<T> MapInPlace<T> for Vec<T> {
-    fn flat_map_in_place<F, I>(&mut self, mut f: F)
-    where
-        F: FnMut(T) -> I,
-        I: IntoIterator<Item = T>,
-    {
-        let mut read_i = 0;
-        let mut write_i = 0;
-        unsafe {
-            let mut old_len = self.len();
-            self.set_len(0); // make sure we just leak elements in case of panic
-
-            while read_i < old_len {
-                // move the read_i'th item out of the vector and map it
-                // to an iterator
-                let e = ptr::read(self.get_unchecked(read_i));
-                let iter = f(e).into_iter();
-                read_i += 1;
-
-                for e in iter {
-                    if write_i < read_i {
-                        ptr::write(self.get_unchecked_mut(write_i), e);
-                        write_i += 1;
-                    } else {
-                        // If this is reached we ran out of space
-                        // in the middle of the vector.
-                        // However, the vector is in a valid state here,
-                        // so we just do a somewhat inefficient insert.
-                        self.set_len(old_len);
-                        self.insert(write_i, e);
-
-                        old_len = self.len();
-                        self.set_len(0);
-
-                        read_i += 1;
-                        write_i += 1;
-                    }
-                }
-            }
-
-            // write_i tracks the number of actually written new items.
-            self.set_len(write_i);
-        }
-    }
-}
-
-impl<T, A: Array<Item = T>> MapInPlace<T> for SmallVec<A> {
-    fn flat_map_in_place<F, I>(&mut self, mut f: F)
-    where
-        F: FnMut(T) -> I,
-        I: IntoIterator<Item = T>,
-    {
-        let mut read_i = 0;
-        let mut write_i = 0;
-        unsafe {
-            let mut old_len = self.len();
-            self.set_len(0); // make sure we just leak elements in case of panic
-
-            while read_i < old_len {
-                // move the read_i'th item out of the vector and map it
-                // to an iterator
-                let e = ptr::read(self.get_unchecked(read_i));
-                let iter = f(e).into_iter();
-                read_i += 1;
-
-                for e in iter {
-                    if write_i < read_i {
-                        ptr::write(self.get_unchecked_mut(write_i), e);
-                        write_i += 1;
-                    } else {
-                        // If this is reached we ran out of space
-                        // in the middle of the vector.
-                        // However, the vector is in a valid state here,
-                        // so we just do a somewhat inefficient insert.
-                        self.set_len(old_len);
-                        self.insert(write_i, e);
-
-                        old_len = self.len();
-                        self.set_len(0);
-
-                        read_i += 1;
-                        write_i += 1;
-                    }
-                }
-            }
-
-            // write_i tracks the number of actually written new items.
-            self.set_len(write_i);
-        }
-    }
-}
index 9338f9afbbb3193d8ec906054c910695bb601581..3a96c5aa8ed4f7775a676010c35f62924cab7e43 100644 (file)
 use rustc_ast::ast::{self, BinOpKind, EnumDef, Expr, Generics, Ident, PatKind};
 use rustc_ast::ast::{GenericArg, GenericParamKind, VariantData};
 use rustc_ast::ptr::P;
-use rustc_ast::util::map_in_place::MapInPlace;
 use rustc_attr as attr;
+use rustc_data_structures::map_in_place::MapInPlace;
 use rustc_expand::base::{Annotatable, ExtCtxt};
 use rustc_session::parse::ParseSess;
 use rustc_span::source_map::respan;
index d0180911567c7e0244ca39954e5eb1d445e350db..d412eaeff742487dd969a95580ea7fd5421d06eb 100644 (file)
@@ -67,6 +67,7 @@ macro_rules! unlikely {
 pub mod graph;
 pub mod jobserver;
 pub mod macros;
+pub mod map_in_place;
 pub mod obligation_forest;
 pub mod owning_ref;
 pub mod ptr_key;
diff --git a/src/librustc_data_structures/map_in_place.rs b/src/librustc_data_structures/map_in_place.rs
new file mode 100644 (file)
index 0000000..5dd9fc6
--- /dev/null
@@ -0,0 +1,108 @@
+use smallvec::{Array, SmallVec};
+use std::ptr;
+
+pub trait MapInPlace<T>: Sized {
+    fn map_in_place<F>(&mut self, mut f: F)
+    where
+        F: FnMut(T) -> T,
+    {
+        self.flat_map_in_place(|e| Some(f(e)))
+    }
+
+    fn flat_map_in_place<F, I>(&mut self, f: F)
+    where
+        F: FnMut(T) -> I,
+        I: IntoIterator<Item = T>;
+}
+
+impl<T> MapInPlace<T> for Vec<T> {
+    fn flat_map_in_place<F, I>(&mut self, mut f: F)
+    where
+        F: FnMut(T) -> I,
+        I: IntoIterator<Item = T>,
+    {
+        let mut read_i = 0;
+        let mut write_i = 0;
+        unsafe {
+            let mut old_len = self.len();
+            self.set_len(0); // make sure we just leak elements in case of panic
+
+            while read_i < old_len {
+                // move the read_i'th item out of the vector and map it
+                // to an iterator
+                let e = ptr::read(self.get_unchecked(read_i));
+                let iter = f(e).into_iter();
+                read_i += 1;
+
+                for e in iter {
+                    if write_i < read_i {
+                        ptr::write(self.get_unchecked_mut(write_i), e);
+                        write_i += 1;
+                    } else {
+                        // If this is reached we ran out of space
+                        // in the middle of the vector.
+                        // However, the vector is in a valid state here,
+                        // so we just do a somewhat inefficient insert.
+                        self.set_len(old_len);
+                        self.insert(write_i, e);
+
+                        old_len = self.len();
+                        self.set_len(0);
+
+                        read_i += 1;
+                        write_i += 1;
+                    }
+                }
+            }
+
+            // write_i tracks the number of actually written new items.
+            self.set_len(write_i);
+        }
+    }
+}
+
+impl<T, A: Array<Item = T>> MapInPlace<T> for SmallVec<A> {
+    fn flat_map_in_place<F, I>(&mut self, mut f: F)
+    where
+        F: FnMut(T) -> I,
+        I: IntoIterator<Item = T>,
+    {
+        let mut read_i = 0;
+        let mut write_i = 0;
+        unsafe {
+            let mut old_len = self.len();
+            self.set_len(0); // make sure we just leak elements in case of panic
+
+            while read_i < old_len {
+                // move the read_i'th item out of the vector and map it
+                // to an iterator
+                let e = ptr::read(self.get_unchecked(read_i));
+                let iter = f(e).into_iter();
+                read_i += 1;
+
+                for e in iter {
+                    if write_i < read_i {
+                        ptr::write(self.get_unchecked_mut(write_i), e);
+                        write_i += 1;
+                    } else {
+                        // If this is reached we ran out of space
+                        // in the middle of the vector.
+                        // However, the vector is in a valid state here,
+                        // so we just do a somewhat inefficient insert.
+                        self.set_len(old_len);
+                        self.insert(write_i, e);
+
+                        old_len = self.len();
+                        self.set_len(0);
+
+                        read_i += 1;
+                        write_i += 1;
+                    }
+                }
+            }
+
+            // write_i tracks the number of actually written new items.
+            self.set_len(write_i);
+        }
+    }
+}
index 72c09f35dfa5573f5ce6f7f1afe4dc05ae4c9cfe..d79dabb509267aafab3442bc39ea47af63744871 100644 (file)
@@ -4,9 +4,9 @@
 use rustc_ast::attr::HasAttrs;
 use rustc_ast::mut_visit::*;
 use rustc_ast::ptr::P;
-use rustc_ast::util::map_in_place::MapInPlace;
 use rustc_attr as attr;
 use rustc_data_structures::fx::FxHashMap;
+use rustc_data_structures::map_in_place::MapInPlace;
 use rustc_errors::{error_code, struct_span_err, Applicability, Handler};
 use rustc_feature::{Feature, Features, State as FeatureState};
 use rustc_feature::{
index 7473c890c5ab98b7dd6c7c2b0359680714c76711..2618c758ca5da2723c9c01bd7ec4e7617f88ffec 100644 (file)
 use rustc_ast::ptr::P;
 use rustc_ast::token;
 use rustc_ast::tokenstream::TokenStream;
-use rustc_ast::util::map_in_place::MapInPlace;
 use rustc_ast::visit::{self, AssocCtxt, Visitor};
 use rustc_ast_pretty::pprust;
 use rustc_attr::{self as attr, is_builtin_attr, HasAttrs};
+use rustc_data_structures::map_in_place::MapInPlace;
 use rustc_errors::{Applicability, PResult};
 use rustc_feature::Features;
 use rustc_parse::parser::Parser;
index 3e5d7b8efd530a5d31341446639ca9a62f3af454..fe8fbd50627d3c38b4eb31cb1788bf6f6cd5015e 100644 (file)
@@ -686,7 +686,9 @@ fn inject_panic_runtime(&mut self, krate: &ast::Crate) {
     }
 
     fn inject_profiler_runtime(&mut self) {
-        if self.sess.opts.debugging_opts.profile || self.sess.opts.cg.profile_generate.enabled() {
+        if (self.sess.opts.debugging_opts.profile || self.sess.opts.cg.profile_generate.enabled())
+            && !self.sess.opts.debugging_opts.no_profiler_runtime
+        {
             info!("loading profiler");
 
             let name = Symbol::intern("profiler_builtins");
index a085c2f7f69c906b2a1b27eae44bbd4c81efbfeb..e4ca54ffd5e49644d6bd780d082fcddd4aa1dd7e 100644 (file)
@@ -148,7 +148,7 @@ fn synthesize_region_name(&self) -> Symbol {
     ///
     /// This function would create a label like this:
     ///
-    /// ```
+    /// ```text
     ///  | fn foo(x: &u32) { .. }
     ///           ------- fully elaborated type of `x` is `&'1 u32`
     /// ```
@@ -300,7 +300,7 @@ fn give_name_from_error_region(&self, fr: RegionVid) -> Option<RegionName> {
     /// elaborated type, returning something like `'1`. Result looks
     /// like:
     ///
-    /// ```
+    /// ```text
     ///  | fn foo(x: &u32) { .. }
     ///           ------- fully elaborated type of `x` is `&'1 u32`
     /// ```
@@ -347,7 +347,7 @@ fn give_name_if_we_can_match_hir_ty_from_argument(
     /// that has no type annotation.
     /// For example, we might produce an annotation like this:
     ///
-    /// ```
+    /// ```text
     ///  |     foo(|a, b| b)
     ///  |          -  -
     ///  |          |  |
@@ -396,7 +396,7 @@ fn give_name_if_we_cannot_match_hir_ty(
     /// that contains the anonymous reference we want to give a name
     /// to. For example, we might produce an annotation like this:
     ///
-    /// ```
+    /// ```text
     ///  | fn a<T>(items: &[T]) -> Box<dyn Iterator<Item = &T>> {
     ///  |                - let's call the lifetime of this reference `'1`
     /// ```
@@ -600,7 +600,7 @@ fn try_match_adt_and_generic_args<'hir>(
     /// fully elaborated type, returning something like `'1`. Result
     /// looks like:
     ///
-    /// ```
+    /// ```text
     ///  | let x = Some(&22);
     ///        - fully elaborated type of `x` is `Option<&'1 u32>`
     /// ```
index bce3a506b1dd9bc257f26b6070cdb6bb62a02a12..1f916d5fc1d999d95ef30dfc578c1a44930084c7 100644 (file)
@@ -13,7 +13,7 @@
 
 pub use self::qualifs::Qualif;
 
-pub mod ops;
+mod ops;
 pub mod qualifs;
 mod resolver;
 pub mod validation;
index b3264a7a0321ad4b955c7d4b5555c9c1831a74b5..b5e62aa20130b1eb0bdebfdaa3ad111cdcf5da70 100644 (file)
@@ -113,8 +113,6 @@ fn emit_error(&self, item: &Item<'_, '_>, span: Span) {
 #[derive(Debug)]
 pub struct HeapAllocation;
 impl NonConstOp for HeapAllocation {
-    const IS_SUPPORTED_IN_MIRI: bool = false;
-
     fn emit_error(&self, item: &Item<'_, '_>, span: Span) {
         let mut err = struct_span_err!(
             item.tcx.sess,
index 552f3d798ae8aa1a010ff54f490cb957bee4922d..da6d863f2399aecf0af023f057c2d41ed6fd948e 100644 (file)
@@ -579,11 +579,13 @@ fn attempt_chained_comparison_suggestion(
     /// Keep in mind that given that `outer_op.is_comparison()` holds and comparison ops are left
     /// associative we can infer that we have:
     ///
+    /// ```text
     ///           outer_op
     ///           /   \
     ///     inner_op   r2
     ///        /  \
     ///      l1    r1
+    /// ```
     pub(super) fn check_no_chained_comparison(
         &mut self,
         inner_op: &Expr,
index 3442c5081c18f879c07ddded71faf7cb3fe6f750..f4729e306f806a21e986451cd22301fa3395b607 100644 (file)
@@ -8,7 +8,7 @@
 impl<'a> Parser<'a> {
     /// Parses bounds of a lifetime parameter `BOUND + BOUND + BOUND`, possibly with trailing `+`.
     ///
-    /// ```
+    /// ```text
     /// BOUND = LT_BOUND (e.g., `'a`)
     /// ```
     fn parse_lt_param_bounds(&mut self) -> GenericBounds {
index 798eb85f36f36579dfd46dc7251ae3760216ac3a..ae8a20f209b9929493ca4b0b44a1500acda66f5d 100644 (file)
@@ -743,7 +743,7 @@ fn parse_type_alias(&mut self, def: Defaultness) -> PResult<'a, ItemInfo> {
 
     /// Parses a `UseTree`.
     ///
-    /// ```
+    /// ```text
     /// USE_TREE = [`::`] `*` |
     ///            [`::`] `{` USE_TREE_LIST `}` |
     ///            PATH `::` `*` |
@@ -792,7 +792,7 @@ fn parse_use_tree_glob_or_nested(&mut self) -> PResult<'a, UseTreeKind> {
 
     /// Parses a `UseTreeKind::Nested(list)`.
     ///
-    /// ```
+    /// ```text
     /// USE_TREE_LIST = Ø | (USE_TREE `,`)* USE_TREE [`,`]
     /// ```
     fn parse_use_tree_list(&mut self) -> PResult<'a, Vec<(UseTree, ast::NodeId)>> {
index b51760cee1ef8ff76b79d99de86006ae2cc1dc3e..88ec4585b0059d1f03bb77d4a594c5979becf94c 100644 (file)
@@ -1031,7 +1031,7 @@ pub(crate) fn make_path_suggestion(
 
     /// Suggest a missing `self::` if that resolves to an correct module.
     ///
-    /// ```
+    /// ```text
     ///    |
     /// LL | use foo::Bar;
     ///    |     ^^^ did you mean `self::foo`?
@@ -1083,7 +1083,7 @@ fn make_missing_crate_suggestion(
 
     /// Suggests a missing `super::` if that resolves to an correct module.
     ///
-    /// ```
+    /// ```text
     ///    |
     /// LL | use foo::Bar;
     ///    |     ^^^ did you mean `super::foo`?
@@ -1103,7 +1103,7 @@ fn make_missing_super_suggestion(
 
     /// Suggests a missing external crate name if that resolves to an correct module.
     ///
-    /// ```
+    /// ```text
     ///    |
     /// LL | use foobar::Baz;
     ///    |     ^^^^^^ did you mean `baz::foobar`?
index aaf30c583e263eda6b0d26f3ae94baa0fd996488..ba2a4d1d56f2395d6d05a87ca815d5c97ff1d483 100644 (file)
@@ -1655,7 +1655,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
     let output_types = parse_output_types(&debugging_opts, matches, error_format);
 
     let mut cg = build_codegen_options(matches, error_format);
-    let (disable_thinlto, codegen_units) = should_override_cgus_and_disable_thinlto(
+    let (disable_thinlto, mut codegen_units) = should_override_cgus_and_disable_thinlto(
         &output_types,
         matches,
         error_format,
@@ -1672,6 +1672,16 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
             "can't instrument with gcov profiling when compiling incrementally",
         );
     }
+    if debugging_opts.profile {
+        match codegen_units {
+            Some(1) => {}
+            None => codegen_units = Some(1),
+            Some(_) => early_error(
+                error_format,
+                "can't instrument with gcov profiling with multiple codegen units",
+            ),
+        }
+    }
 
     if cg.profile_generate.enabled() && cg.profile_use.is_some() {
         early_error(
index 8cd6ca86f46897e88145e709b282e973e6ee6427..94e65093e71b23714928ca416729332725a9067b 100644 (file)
@@ -890,6 +890,8 @@ fn parse_src_file_hash(slot: &mut Option<SourceFileHashAlgorithm>, v: Option<&st
         "extra arguments to prepend to the linker invocation (space separated)"),
     profile: bool = (false, parse_bool, [TRACKED],
                      "insert profiling code"),
+    no_profiler_runtime: bool = (false, parse_bool, [TRACKED],
+        "don't automatically inject the profiler_builtins crate"),
     relro_level: Option<RelroLevel> = (None, parse_relro_level, [TRACKED],
         "choose which RELRO level to use"),
     nll_facts: bool = (false, parse_bool, [UNTRACKED],
index 254db6cb869b1bfa537fd6316258f887c5130fef..ed69061d618512e342d95ba45d58b12a3c574e04 100644 (file)
@@ -1045,7 +1045,7 @@ fn suggest_fully_qualified_path(
     /// Adds an async-await specific note to the diagnostic when the future does not implement
     /// an auto trait because of a captured type.
     ///
-    /// ```ignore (diagnostic)
+    /// ```text
     /// note: future does not implement `Qux` as this value is used across an await
     ///   --> $DIR/issue-64130-3-other.rs:17:5
     ///    |
@@ -1060,7 +1060,7 @@ fn suggest_fully_qualified_path(
     /// When the diagnostic does not implement `Send` or `Sync` specifically, then the diagnostic
     /// is "replaced" with a different message and a more specific error.
     ///
-    /// ```ignore (diagnostic)
+    /// ```text
     /// error: future cannot be sent between threads safely
     ///   --> $DIR/issue-64130-2-send.rs:21:5
     ///    |
index 4a8cd9e91e2786ab3bc193fe5dbf7f3067f1b399..895042f3ab1151dbaa65461e880fe6566a71572e 100644 (file)
@@ -1250,7 +1250,7 @@ pub fn is_unsized(&self, ast_bounds: &[hir::GenericBound<'_>], span: Span) -> bo
     /// This helper takes a *converted* parameter type (`param_ty`)
     /// and an *unconverted* list of bounds:
     ///
-    /// ```
+    /// ```text
     /// fn foo<T: Debug>
     ///        ^  ^^^^^ `ast_bounds` parameter, in HIR form
     ///        |
@@ -2992,7 +2992,7 @@ fn compute_object_lifetime_bound(
 /// representations). These lists of bounds occur in many places in
 /// Rust's syntax:
 ///
-/// ```
+/// ```text
 /// trait Foo: Bar + Baz { }
 ///            ^^^^^^^^^ supertrait list bounding the `Self` type parameter
 ///
diff --git a/src/test/ui/consts/miri_unleashed/box.rs b/src/test/ui/consts/miri_unleashed/box.rs
new file mode 100644 (file)
index 0000000..0497276
--- /dev/null
@@ -0,0 +1,14 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+#![feature(const_mut_refs, box_syntax)]
+#![deny(const_err)]
+
+use std::mem::ManuallyDrop;
+
+fn main() {}
+
+static TEST_BAD: &mut i32 = {
+    &mut *(box 0)
+    //~^ WARN skipping const check
+    //~| ERROR could not evaluate static initializer
+    //~| NOTE heap allocations
+};
diff --git a/src/test/ui/consts/miri_unleashed/box.stderr b/src/test/ui/consts/miri_unleashed/box.stderr
new file mode 100644 (file)
index 0000000..d1b404e
--- /dev/null
@@ -0,0 +1,15 @@
+warning: skipping const checks
+  --> $DIR/box.rs:10:11
+   |
+LL |     &mut *(box 0)
+   |           ^^^^^^^
+
+error[E0080]: could not evaluate static initializer
+  --> $DIR/box.rs:10:11
+   |
+LL |     &mut *(box 0)
+   |           ^^^^^^^ "heap allocations via `box` keyword" needs an rfc before being allowed inside constants
+
+error: aborting due to previous error; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0080`.