about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-09-07 23:02:03 +0000
committerbors <bors@rust-lang.org>2024-09-07 23:02:03 +0000
commit878f49f5ff0dd88a85bcd5d99fc0d90e219c354c (patch)
treefcd894695c1fb799a4fb67f7a3f842f49c644b97 /compiler/rustc_mir_transform/src
parent12b26c13fba25c9e1bc2fdf05f3c2dbb851c83de (diff)
parent4ba483d68b1dc6c73b65507194035d7c09122d2f (diff)
downloadrust-878f49f5ff0dd88a85bcd5d99fc0d90e219c354c.tar.gz
rust-878f49f5ff0dd88a85bcd5d99fc0d90e219c354c.zip
Auto merge of #130091 - matthiaskrgr:rollup-kalu1cs, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #126452 (Implement raw lifetimes and labels (`'r#ident`))
 - #129555 (stabilize const_float_bits_conv)
 - #129594 (explain the options bootstrap passes to curl)
 - #129677 (Don't build by-move body when async closure is tainted)
 - #129847 (Do not call query to compute coroutine layout for synthetic body of async closure)
 - #129869 (add a few more crashtests)
 - #130009 (rustdoc-search: allow trailing `Foo ->` arg search)
 - #130046 (str: make as_mut_ptr and as_bytes_mut unstably const)
 - #130047 (Win: Add dbghelp to the list of import libraries)
 - #130059 (Remove the unused  `llvm-skip-rebuild` option from x.py)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_mir_transform/src')
-rw-r--r--compiler/rustc_mir_transform/src/coroutine/by_move_body.rs11
-rw-r--r--compiler/rustc_mir_transform/src/validate.rs13
2 files changed, 21 insertions, 3 deletions
diff --git a/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs b/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs
index cf39c136b01..9e35dfed0ee 100644
--- a/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs
+++ b/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs
@@ -88,6 +88,11 @@ pub fn coroutine_by_move_body_def_id<'tcx>(
 ) -> DefId {
     let body = tcx.mir_built(coroutine_def_id).borrow();
 
+    // If the typeck results are tainted, no need to make a by-ref body.
+    if body.tainted_by_errors.is_some() {
+        return coroutine_def_id.to_def_id();
+    }
+
     let Some(hir::CoroutineKind::Desugared(_, hir::CoroutineSource::Closure)) =
         tcx.coroutine_kind(coroutine_def_id)
     else {
@@ -98,7 +103,9 @@ pub fn coroutine_by_move_body_def_id<'tcx>(
     // the MIR body will be constructed well.
     let coroutine_ty = body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty;
 
-    let ty::Coroutine(_, args) = *coroutine_ty.kind() else { bug!("{body:#?}") };
+    let ty::Coroutine(_, args) = *coroutine_ty.kind() else {
+        bug!("tried to create by-move body of non-coroutine receiver");
+    };
     let args = args.as_coroutine();
 
     let coroutine_kind = args.kind_ty().to_opt_closure_kind().unwrap();
@@ -107,7 +114,7 @@ pub fn coroutine_by_move_body_def_id<'tcx>(
     let ty::CoroutineClosure(_, parent_args) =
         *tcx.type_of(parent_def_id).instantiate_identity().kind()
     else {
-        bug!();
+        bug!("coroutine's parent was not a coroutine-closure");
     };
     if parent_args.references_error() {
         return coroutine_def_id.to_def_id();
diff --git a/compiler/rustc_mir_transform/src/validate.rs b/compiler/rustc_mir_transform/src/validate.rs
index 69e2592e82c..e515dfc5ea5 100644
--- a/compiler/rustc_mir_transform/src/validate.rs
+++ b/compiler/rustc_mir_transform/src/validate.rs
@@ -1,6 +1,7 @@
 //! Validates the MIR to ensure that invariants are upheld.
 
 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
+use rustc_hir as hir;
 use rustc_hir::LangItem;
 use rustc_index::bit_set::BitSet;
 use rustc_index::IndexVec;
@@ -714,7 +715,17 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
                             // since we may be in the process of computing this MIR in the
                             // first place.
                             let layout = if def_id == self.caller_body.source.def_id() {
-                                // FIXME: This is not right for async closures.
+                                self.caller_body.coroutine_layout_raw()
+                            } else if let Some(hir::CoroutineKind::Desugared(
+                                _,
+                                hir::CoroutineSource::Closure,
+                            )) = self.tcx.coroutine_kind(def_id)
+                                && let ty::ClosureKind::FnOnce =
+                                    args.as_coroutine().kind_ty().to_opt_closure_kind().unwrap()
+                                && self.caller_body.source.def_id()
+                                    == self.tcx.coroutine_by_move_body_def_id(def_id)
+                            {
+                                // Same if this is the by-move body of a coroutine-closure.
                                 self.caller_body.coroutine_layout_raw()
                             } else {
                                 self.tcx.coroutine_layout(def_id, args.as_coroutine().kind_ty())