refactor: Remove unnecessary AsAny trait

This commit is contained in:
Lukas Wirth 2025-05-05 16:04:57 +02:00
parent fdfa707807
commit 091b7b2465
4 changed files with 4 additions and 56 deletions

View file

@ -380,8 +380,4 @@ impl ProcMacroExpander for IdentityWhenValidProcMacroExpander {
panic!("got invalid macro input: {:?}", parse.errors()); panic!("got invalid macro input: {:?}", parse.errors());
} }
} }
fn eq_dyn(&self, other: &dyn ProcMacroExpander) -> bool {
other.as_any().type_id() == std::any::TypeId::of::<Self>()
}
} }

View file

@ -19,18 +19,8 @@ pub enum ProcMacroKind {
Attr, Attr,
} }
pub trait AsAny: Any {
fn as_any(&self) -> &dyn Any;
}
impl<T: Any> AsAny for T {
fn as_any(&self) -> &dyn Any {
self
}
}
/// A proc-macro expander implementation. /// A proc-macro expander implementation.
pub trait ProcMacroExpander: fmt::Debug + Send + Sync + RefUnwindSafe + AsAny { pub trait ProcMacroExpander: fmt::Debug + Send + Sync + RefUnwindSafe + Any {
/// Run the expander with the given input subtree, optional attribute input subtree (for /// Run the expander with the given input subtree, optional attribute input subtree (for
/// [`ProcMacroKind::Attr`]), environment variables, and span information. /// [`ProcMacroKind::Attr`]), environment variables, and span information.
fn expand( fn expand(
@ -44,7 +34,9 @@ pub trait ProcMacroExpander: fmt::Debug + Send + Sync + RefUnwindSafe + AsAny {
current_dir: String, current_dir: String,
) -> Result<tt::TopSubtree, ProcMacroExpansionError>; ) -> Result<tt::TopSubtree, ProcMacroExpansionError>;
fn eq_dyn(&self, other: &dyn ProcMacroExpander) -> bool; fn eq_dyn(&self, other: &dyn ProcMacroExpander) -> bool {
other.type_id() == self.type_id()
}
} }
impl PartialEq for dyn ProcMacroExpander { impl PartialEq for dyn ProcMacroExpander {

View file

@ -512,10 +512,6 @@ impl ProcMacroExpander for Expander {
Err(err) => Err(ProcMacroExpansionError::System(err.to_string())), Err(err) => Err(ProcMacroExpansionError::System(err.to_string())),
} }
} }
fn eq_dyn(&self, other: &dyn ProcMacroExpander) -> bool {
other.as_any().downcast_ref::<Self>().is_some_and(|other| self == other)
}
} }
#[cfg(test)] #[cfg(test)]

View file

@ -662,10 +662,6 @@ impl ProcMacroExpander for IdentityProcMacroExpander {
) -> Result<TopSubtree, ProcMacroExpansionError> { ) -> Result<TopSubtree, ProcMacroExpansionError> {
Ok(subtree.clone()) Ok(subtree.clone())
} }
fn eq_dyn(&self, other: &dyn ProcMacroExpander) -> bool {
other.as_any().type_id() == std::any::TypeId::of::<Self>()
}
} }
// Expands to a macro_rules! macro, for issue #18089. // Expands to a macro_rules! macro, for issue #18089.
@ -697,10 +693,6 @@ impl ProcMacroExpander for Issue18089ProcMacroExpander {
#subtree #subtree
}) })
} }
fn eq_dyn(&self, other: &dyn ProcMacroExpander) -> bool {
other.as_any().type_id() == std::any::TypeId::of::<Self>()
}
} }
// Pastes the attribute input as its output // Pastes the attribute input as its output
@ -721,10 +713,6 @@ impl ProcMacroExpander for AttributeInputReplaceProcMacroExpander {
.cloned() .cloned()
.ok_or_else(|| ProcMacroExpansionError::Panic("Expected attribute input".into())) .ok_or_else(|| ProcMacroExpansionError::Panic("Expected attribute input".into()))
} }
fn eq_dyn(&self, other: &dyn ProcMacroExpander) -> bool {
other.as_any().type_id() == std::any::TypeId::of::<Self>()
}
} }
#[derive(Debug)] #[derive(Debug)]
@ -756,10 +744,6 @@ impl ProcMacroExpander for Issue18840ProcMacroExpander {
top_subtree_delimiter_mut.close = def_site; top_subtree_delimiter_mut.close = def_site;
Ok(result) Ok(result)
} }
fn eq_dyn(&self, other: &dyn ProcMacroExpander) -> bool {
other.as_any().type_id() == std::any::TypeId::of::<Self>()
}
} }
#[derive(Debug)] #[derive(Debug)]
@ -791,10 +775,6 @@ impl ProcMacroExpander for MirrorProcMacroExpander {
traverse(&mut builder, input.iter()); traverse(&mut builder, input.iter());
Ok(builder.build()) Ok(builder.build())
} }
fn eq_dyn(&self, other: &dyn ProcMacroExpander) -> bool {
other.as_any().type_id() == std::any::TypeId::of::<Self>()
}
} }
// Replaces every literal with an empty string literal and every identifier with its first letter, // Replaces every literal with an empty string literal and every identifier with its first letter,
@ -835,10 +815,6 @@ impl ProcMacroExpander for ShortenProcMacroExpander {
} }
} }
} }
fn eq_dyn(&self, other: &dyn ProcMacroExpander) -> bool {
other.as_any().type_id() == std::any::TypeId::of::<Self>()
}
} }
// Reads ident type within string quotes, for issue #17479. // Reads ident type within string quotes, for issue #17479.
@ -864,10 +840,6 @@ impl ProcMacroExpander for Issue17479ProcMacroExpander {
#symbol() #symbol()
}) })
} }
fn eq_dyn(&self, other: &dyn ProcMacroExpander) -> bool {
other.as_any().type_id() == std::any::TypeId::of::<Self>()
}
} }
// Reads ident type within string quotes, for issue #17479. // Reads ident type within string quotes, for issue #17479.
@ -919,10 +891,6 @@ impl ProcMacroExpander for Issue18898ProcMacroExpander {
} }
}) })
} }
fn eq_dyn(&self, other: &dyn ProcMacroExpander) -> bool {
other.as_any().type_id() == std::any::TypeId::of::<Self>()
}
} }
// Reads ident type within string quotes, for issue #17479. // Reads ident type within string quotes, for issue #17479.
@ -950,8 +918,4 @@ impl ProcMacroExpander for DisallowCfgProcMacroExpander {
} }
Ok(subtree.clone()) Ok(subtree.clone())
} }
fn eq_dyn(&self, other: &dyn ProcMacroExpander) -> bool {
other.as_any().type_id() == std::any::TypeId::of::<Self>()
}
} }