From 39b293fb5a68081e7c050ed2805c8e3404c9763a Mon Sep 17 00:00:00 2001 From: Kirby Linvill Date: Wed, 25 Oct 2023 22:09:12 +0100 Subject: [PATCH] Add a public API to get all body locals This is particularly helpful for the ui tests, but also could be helpful for Stable MIR users who just want all the locals without needing to concatenate responses --- compiler/stable_mir/src/mir/body.rs | 8 ++++++++ tests/ui-fulldeps/stable-mir/check_instance.rs | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/compiler/stable_mir/src/mir/body.rs b/compiler/stable_mir/src/mir/body.rs index dc472b3786c..97dd649bf64 100644 --- a/compiler/stable_mir/src/mir/body.rs +++ b/compiler/stable_mir/src/mir/body.rs @@ -48,6 +48,14 @@ impl Body { pub fn internal_locals(&self) -> &[LocalDecl] { &self.locals[self.arg_count + 1..] } + + /// Convenience function to get all the locals in this function. + /// + /// Locals are typically accessed via the more specific methods `ret_local`, + /// `arg_locals`, and `internal_locals`. + pub fn locals(&self) -> &[LocalDecl] { + &self.locals + } } type LocalDecls = Vec; diff --git a/tests/ui-fulldeps/stable-mir/check_instance.rs b/tests/ui-fulldeps/stable-mir/check_instance.rs index ee82bc77aed..29d88b31e77 100644 --- a/tests/ui-fulldeps/stable-mir/check_instance.rs +++ b/tests/ui-fulldeps/stable-mir/check_instance.rs @@ -59,7 +59,7 @@ fn test_body(body: mir::Body) { for term in body.blocks.iter().map(|bb| &bb.terminator) { match &term.kind { Call { func, .. } => { - let TyKind::RigidTy(ty) = func.ty(&body.locals).kind() else { unreachable!() }; + let TyKind::RigidTy(ty) = func.ty(&body.locals()).kind() else { unreachable!() }; let RigidTy::FnDef(def, args) = ty else { unreachable!() }; let result = Instance::resolve(def, &args); assert!(result.is_ok());