]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #84313 - lcnr:sized-err-msg, r=petrochenkov
authorDylan DPC <dylan.dpc@gmail.com>
Mon, 19 Apr 2021 20:00:10 +0000 (22:00 +0200)
committerGitHub <noreply@github.com>
Mon, 19 Apr 2021 20:00:10 +0000 (22:00 +0200)
fix suggestion for unsized function parameters

taken from `@fasterthanlime's` article https://fasterthanli.me/articles/whats-in-the-box

compiler/rustc_ast_lowering/src/item.rs
compiler/rustc_middle/src/dep_graph/dep_node.rs
compiler/rustc_middle/src/dep_graph/mod.rs
compiler/rustc_middle/src/mir/mono.rs
compiler/rustc_query_impl/src/plumbing.rs
compiler/rustc_target/src/spec/x86_64_unknown_linux_musl.rs
library/std/src/primitive_docs.rs
library/std/src/thread/local.rs
src/bootstrap/native.rs
src/test/ui/async-await/async-trait-fn.rs
src/test/ui/async-await/async-trait-fn.stderr

index ea01632d75d6a975d19eea985306df7af3d101e8..5fd8f7eb33a1fa882fdc068c3397cdaf0024dec6 100644 (file)
@@ -836,9 +836,17 @@ fn lower_trait_item(&mut self, i: &AssocItem) -> hir::TraitItem<'hir> {
                 (generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Required(names)))
             }
             AssocItemKind::Fn(box FnKind(_, ref sig, ref generics, Some(ref body))) => {
-                let body_id = self.lower_fn_body_block(i.span, &sig.decl, Some(body));
-                let (generics, sig) =
-                    self.lower_method_sig(generics, sig, trait_item_def_id, false, None, i.id);
+                let asyncness = sig.header.asyncness;
+                let body_id =
+                    self.lower_maybe_async_body(i.span, &sig.decl, asyncness, Some(&body));
+                let (generics, sig) = self.lower_method_sig(
+                    generics,
+                    sig,
+                    trait_item_def_id,
+                    false,
+                    asyncness.opt_return_id(),
+                    i.id,
+                );
                 (generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Provided(body_id)))
             }
             AssocItemKind::TyAlias(box TyAliasKind(_, ref generics, ref bounds, ref default)) => {
index ba9d0a40732e6bec841cc6a239bdd9fa61565618..aa54d1ae7b9d118426d9702dac6384725e0b50c4 100644 (file)
@@ -32,8 +32,8 @@
 //! `DepNode` definition happens in the `define_dep_nodes!()` macro. This macro
 //! defines the `DepKind` enum. Each `DepKind` has its own parameters that are
 //! needed at runtime in order to construct a valid `DepNode` fingerprint.
-//! However, only `CompileCodegenUnit` is constructed explicitly (with
-//! `make_compile_codegen_unit`).
+//! However, only `CompileCodegenUnit` and `CompileMonoItem` are constructed
+//! explicitly (with `make_compile_codegen_unit` cq `make_compile_mono_item`).
 //!
 //! Because the macro sees what parameters a given `DepKind` requires, it can
 //! "infer" some properties for each kind of `DepNode`:
 //!   `DefId` it was computed from. In other cases, too much information gets
 //!   lost during fingerprint computation.
 //!
-//! `make_compile_codegen_unit`, together with `DepNode::new()`, ensures that only
-//! valid `DepNode` instances can be constructed. For example, the API does not
-//! allow for constructing parameterless `DepNode`s with anything other
-//! than a zeroed out fingerprint. More generally speaking, it relieves the
-//! user of the `DepNode` API of having to know how to compute the expected
-//! fingerprint for a given set of node parameters.
+//! `make_compile_codegen_unit` and `make_compile_mono_items`, together with
+//! `DepNode::new()`, ensures that only valid `DepNode` instances can be
+//! constructed. For example, the API does not allow for constructing
+//! parameterless `DepNode`s with anything other than a zeroed out fingerprint.
+//! More generally speaking, it relieves the user of the `DepNode` API of
+//! having to know how to compute the expected fingerprint for a given set of
+//! node parameters.
 //!
 //! [dependency graph]: https://rustc-dev-guide.rust-lang.org/query.html
 
+use crate::mir::mono::MonoItem;
 use crate::ty::TyCtxt;
 
 use rustc_data_structures::fingerprint::Fingerprint;
@@ -175,6 +177,14 @@ pub mod dep_kind {
         can_reconstruct_query_key: || false,
     };
 
+    pub const CompileMonoItem: DepKindStruct = DepKindStruct {
+        has_params: true,
+        is_anon: false,
+        is_eval_always: false,
+
+        can_reconstruct_query_key: || false,
+    };
+
     macro_rules! define_query_dep_kinds {
         ($(
             [$($attrs:tt)*]
@@ -251,6 +261,10 @@ pub mod label_strs {
 
     // WARNING: if `Symbol` is changed, make sure you update `make_compile_codegen_unit` below.
     [] CompileCodegenUnit(Symbol),
+
+    // WARNING: if `MonoItem` is changed, make sure you update `make_compile_mono_item` below.
+    // Only used by rustc_codegen_cranelift
+    [] CompileMonoItem(MonoItem),
 ]);
 
 // WARNING: `construct` is generic and does not know that `CompileCodegenUnit` takes `Symbol`s as keys.
@@ -259,6 +273,12 @@ pub mod label_strs {
     DepNode::construct(tcx, DepKind::CompileCodegenUnit, &name)
 }
 
+// WARNING: `construct` is generic and does not know that `CompileMonoItem` takes `MonoItem`s as keys.
+// Be very careful changing this type signature!
+crate fn make_compile_mono_item(tcx: TyCtxt<'tcx>, mono_item: &MonoItem<'tcx>) -> DepNode {
+    DepNode::construct(tcx, DepKind::CompileMonoItem, mono_item)
+}
+
 pub type DepNode = rustc_query_system::dep_graph::DepNode<DepKind>;
 
 // We keep a lot of `DepNode`s in memory during compilation. It's not
index d2fe9af34fb625a8a88ae9e94cd4f89f661ddaec..31bea8329587d7469350bd4bc8c550f2a9fbf029 100644 (file)
@@ -12,8 +12,8 @@
     SerializedDepNodeIndex, WorkProduct, WorkProductId,
 };
 
-crate use dep_node::make_compile_codegen_unit;
 pub use dep_node::{label_strs, DepKind, DepNode, DepNodeExt};
+crate use dep_node::{make_compile_codegen_unit, make_compile_mono_item};
 
 pub type DepGraph = rustc_query_system::dep_graph::DepGraph<DepKind>;
 pub type TaskDeps = rustc_query_system::dep_graph::TaskDeps<DepKind>;
index 6c2468b9ffe0b1c937d2a1fc53d5fb331d35668d..92a1094bbcdc1bbdfb3bb7b6953bac7d8574c8a1 100644 (file)
@@ -181,6 +181,11 @@ pub fn local_span(&self, tcx: TyCtxt<'tcx>) -> Option<Span> {
         }
         .map(|hir_id| tcx.hir().span(hir_id))
     }
+
+    // Only used by rustc_codegen_cranelift
+    pub fn codegen_dep_node(&self, tcx: TyCtxt<'tcx>) -> DepNode {
+        crate::dep_graph::make_compile_mono_item(tcx, self)
+    }
 }
 
 impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for MonoItem<'tcx> {
index 4194b28dc7d681fc485c0e765a55430a7745f6dc..ee914fa1ba95cfb2cedf993b0a1da6168042dd79 100644 (file)
@@ -438,6 +438,11 @@ pub mod query_callbacks {
                 try_load_from_on_disk_cache: |_, _| {},
             };
 
+            pub const CompileMonoItem: QueryStruct = QueryStruct {
+                force_from_dep_node: |_, _| false,
+                try_load_from_on_disk_cache: |_, _| {},
+            };
+
             $(pub const $name: QueryStruct = {
                 const is_anon: bool = is_anon!([$($modifiers)*]);
 
index da79bc2f338031237f6a29f2407035820e2493eb..1e2e5766a311bcf8cc6fb67894538ec424a98945 100644 (file)
@@ -1,4 +1,4 @@
-use crate::spec::{LinkerFlavor, StackProbeType, Target};
+use crate::spec::{LinkerFlavor, SanitizerSet, StackProbeType, Target};
 
 pub fn target() -> Target {
     let mut base = super::linux_musl_base::opts();
@@ -7,6 +7,8 @@ pub fn target() -> Target {
     base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".to_string());
     base.stack_probes = StackProbeType::InlineOrCall { min_llvm_version_for_inline: (11, 0, 1) };
     base.static_position_independent_executables = true;
+    base.supported_sanitizers =
+        SanitizerSet::ADDRESS | SanitizerSet::LEAK | SanitizerSet::MEMORY | SanitizerSet::THREAD;
 
     Target {
         llvm_target: "x86_64-unknown-linux-musl".to_string(),
index 64b22b64f4bf12cc840705a32200735d665df35a..84d072b9860e82f59bd32a5c873abd3aec30ebc7 100644 (file)
@@ -807,10 +807,10 @@ mod prim_tuple {}
 ///
 /// Additionally, `f32` can represent some special values:
 ///
-/// - -0.0: IEEE 754 floating point numbers have a bit that indicates their sign, so -0.0 is a
-///   possible value. For comparison `-0.0 == +0.0` is true but floating point operations can
-///   carry the sign bit through arithmetic operations. This means `-1.0 * 0.0` produces -0.0 and
-///   a negative number rounded to a value smaller than a float can represent also produces -0.0.
+/// - −0.0: IEEE 754 floating point numbers have a bit that indicates their sign, so −0.0 is a
+///   possible value. For comparison −0.0 = +0.0, but floating point operations can carry
+///   the sign bit through arithmetic operations. This means −0.0 × +0.0 produces −0.0 and
+///   a negative number rounded to a value smaller than a float can represent also produces 0.0.
 /// - [∞](#associatedconstant.INFINITY) and
 ///   [−∞](#associatedconstant.NEG_INFINITY): these result from calculations
 ///   like `1.0 / 0.0`.
index 37525e50604ddee3321d71713d54ec0fd3e0dafd..3dcf7e334531fdb3b1c78408aec956b7bb321699 100644 (file)
@@ -217,7 +217,7 @@ unsafe fn __getit() -> $crate::option::Option<&'static $t> {
                         //   so now.
                         0 => {
                             $crate::thread::__FastLocalKeyInner::<$t>::register_dtor(
-                                &VAL as *const _ as *mut u8,
+                                $crate::ptr::addr_of_mut!(VAL) as *mut u8,
                                 destroy,
                             );
                             STATE = 1;
index c06ceb80c6ae028e425f4f07c3ae3a9083462516..bde0a96f03013d22aeb30a80e8a600a15f252ebc 100644 (file)
@@ -814,6 +814,9 @@ fn supported_sanitizers(
         "x86_64-unknown-linux-gnu" => {
             common_libs("linux", "x86_64", &["asan", "lsan", "msan", "tsan"])
         }
+        "x86_64-unknown-linux-musl" => {
+            common_libs("linux", "x86_64", &["asan", "lsan", "msan", "tsan"])
+        }
         _ => Vec::new(),
     }
 }
index f0403b76620c1ba076a7c07303783c7b420d141b..e2062e82725c0507fad934ec9f6720dfab28ea71 100644 (file)
@@ -2,6 +2,10 @@
 trait T {
     async fn foo() {} //~ ERROR functions in traits cannot be declared `async`
     async fn bar(&self) {} //~ ERROR functions in traits cannot be declared `async`
+    async fn baz() { //~ ERROR functions in traits cannot be declared `async`
+        // Nested item must not ICE.
+        fn a() {}
+    }
 }
 
 fn main() {}
index 6080b2815eeb8cd3577aaa74515ff4c3632f066a..1eb8969a80d20047db21c886240c0dc11aebc73d 100644 (file)
@@ -20,6 +20,22 @@ LL |     async fn bar(&self) {}
    = note: `async` trait functions are not currently supported
    = note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
 
-error: aborting due to 2 previous errors
+error[E0706]: functions in traits cannot be declared `async`
+  --> $DIR/async-trait-fn.rs:5:5
+   |
+LL |       async fn baz() {
+   |       ^----
+   |       |
+   |  _____`async` because of this
+   | |
+LL | |         // Nested item must not ICE.
+LL | |         fn a() {}
+LL | |     }
+   | |_____^
+   |
+   = note: `async` trait functions are not currently supported
+   = note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
+
+error: aborting due to 3 previous errors
 
 For more information about this error, try `rustc --explain E0706`.