Skip to content

Commit 39b293f

Browse files
committed
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
1 parent 372c533 commit 39b293f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

compiler/stable_mir/src/mir/body.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ impl Body {
4848
pub fn internal_locals(&self) -> &[LocalDecl] {
4949
&self.locals[self.arg_count + 1..]
5050
}
51+
52+
/// Convenience function to get all the locals in this function.
53+
///
54+
/// Locals are typically accessed via the more specific methods `ret_local`,
55+
/// `arg_locals`, and `internal_locals`.
56+
pub fn locals(&self) -> &[LocalDecl] {
57+
&self.locals
58+
}
5159
}
5260

5361
type LocalDecls = Vec<LocalDecl>;

tests/ui-fulldeps/stable-mir/check_instance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn test_body(body: mir::Body) {
5959
for term in body.blocks.iter().map(|bb| &bb.terminator) {
6060
match &term.kind {
6161
Call { func, .. } => {
62-
let TyKind::RigidTy(ty) = func.ty(&body.locals).kind() else { unreachable!() };
62+
let TyKind::RigidTy(ty) = func.ty(&body.locals()).kind() else { unreachable!() };
6363
let RigidTy::FnDef(def, args) = ty else { unreachable!() };
6464
let result = Instance::resolve(def, &args);
6565
assert!(result.is_ok());

0 commit comments

Comments
 (0)