diff --git a/vm/src/macros.rs b/vm/src/macros.rs index 4b2ad0b04..5eeb824a3 100644 --- a/vm/src/macros.rs +++ b/vm/src/macros.rs @@ -244,6 +244,10 @@ macro_rules! match_class { let $binding = $obj; $default }}; + (match ($obj:expr) { ref $binding:ident => $default:expr $(,)? }) => {{ + let $binding = &$obj; + $default + }}; // An arm taken when the object is an instance of the specified built-in // class and binding the downcasted object to the specified identifier and @@ -251,6 +255,9 @@ macro_rules! match_class { (match ($obj:expr) { $binding:ident @ $class:ty => $expr:block $($rest:tt)* }) => { $crate::match_class!(match ($obj) { $binding @ $class => ($expr), $($rest)* }) }; + (match ($obj:expr) { ref $binding:ident @ $class:ty => $expr:block $($rest:tt)* }) => { + $crate::match_class!(match ($obj) { ref $binding @ $class => ($expr), $($rest)* }) + }; // An arm taken when the object is an instance of the specified built-in // class and binding the downcasted object to the specified identifier. @@ -260,6 +267,12 @@ macro_rules! match_class { Err(_obj) => $crate::match_class!(match (_obj) { $($rest)* }), } }; + (match ($obj:expr) { ref $binding:ident @ $class:ty => $expr:expr, $($rest:tt)* }) => { + match $obj.payload::<$class>() { + Some($binding) => $expr, + None => $crate::match_class!(match ($obj) { $($rest)* }), + } + }; // An arm taken when the object is an instance of the specified built-in // class and the target expression is a block.