From 8cb727424dde83b841610700e40f399848e57700 Mon Sep 17 00:00:00 2001 From: lcnr Date: Fri, 11 Apr 2025 10:42:45 +0200 Subject: [PATCH] use input `def_id` to compute `movable_coroutine` This previously incorrectly returned `true` for parent functions whose first statement was `let local = ;`. While that didn't cause any bugs as we only ever access `movable_coroutine` for `yield` terminators. It was still wrong. --- compiler/rustc_borrowck/src/lib.rs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index b4e807646c0a..94c1b54672ac 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -374,17 +374,8 @@ fn do_mir_borrowck<'tcx>( let diags_buffer = &mut BorrowckDiagnosticsBuffer::default(); nll::dump_annotation(&infcx, body, ®ioncx, &opt_closure_req, diags_buffer); - let movable_coroutine = - // The first argument is the coroutine type passed by value - if let Some(local) = body.local_decls.raw.get(1) - // Get the interior types and args which typeck computed - && let ty::Coroutine(def_id, _) = *local.ty.kind() - && tcx.coroutine_movability(def_id) == hir::Movability::Movable -{ - true -} else { - false -}; + let movable_coroutine = body.coroutine.is_some() + && tcx.coroutine_movability(def.to_def_id()) == hir::Movability::Movable; // While promoteds should mostly be correct by construction, we need to check them for // invalid moves to detect moving out of arrays:`struct S; fn main() { &([S][0]); }`.