Diffstat (limited to 'src/any.rs')
-rw-r--r--src/any.rs22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/any.rs b/src/any.rs
index 3ebc7b2..98fbf5c 100644
--- a/src/any.rs
+++ b/src/any.rs
@@ -226,10 +226,14 @@ impl<'b, 'ctx: 'b> dyn AnyTrait<'ctx> + Send + Sync + 'b {
macro_rules! any_trait {
{
impl[$lt:lifetime $($generic:tt)*] $name:ty = [$($protocol:ty),* $(,)?]
- else {
- let $id:ident;
+ else ref {
+ let ($this:ident, $id:ident);
$($fallback:tt)*
}
+ else mut {
+ let ($mut_this:ident, $mut_id:ident);
+ $($mut_fallback:tt)*
+ }
$(where $($bound:tt)*)?
} => {
impl<$lt $($generic)*> $crate::any::AnyTrait<$lt> for $name
@@ -250,6 +254,7 @@ macro_rules! any_trait {
$crate::any::TypeName::T<'__, $lt, $protocol>
>(self as _)),)*
$id => {
+ let $this = self;
$($fallback)*
}
}
@@ -269,8 +274,9 @@ macro_rules! any_trait {
=> ::core::option::Option::Some($crate::any::AnyTraitObject::<'__, $lt, _>::new::<
$crate::any::TypeName::T<'__, $lt, $protocol>
>(self as _)),)*
- $id => {
- $($fallback)*
+ $mut_id => {
+ let $mut_this = self;
+ $($mut_fallback)*
}
}
}
@@ -282,9 +288,13 @@ macro_rules! any_trait {
} => {
$crate::any::any_trait! {
impl[$lt $($generic)*] $name = [$($protocol),*]
- else {
+ else ref {
+ // Always answer no in the fallback branch if no fallback was given.
+ let (_this, _id);
+ ::core::option::Option::None
+ } else mut {
// Always answer no in the fallback branch if no fallback was given.
- let _id;
+ let (_this, _id);
::core::option::Option::None
} $(where $($bound)*)?
}