Skip to content

Commit d40455f

Browse files
authored
Merge pull request #19749 from Veykril/push-tsxvxzzmlxpq
refactor: Remove unnecessary `AsAny` trait
2 parents 3ec5c52 + 091b7b2 commit d40455f

File tree

4 files changed

+4
-56
lines changed

4 files changed

+4
-56
lines changed

crates/hir-def/src/macro_expansion_tests/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,4 @@ impl ProcMacroExpander for IdentityWhenValidProcMacroExpander {
380380
panic!("got invalid macro input: {:?}", parse.errors());
381381
}
382382
}
383-
384-
fn eq_dyn(&self, other: &dyn ProcMacroExpander) -> bool {
385-
other.as_any().type_id() == std::any::TypeId::of::<Self>()
386-
}
387383
}

crates/hir-expand/src/proc_macro.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,8 @@ pub enum ProcMacroKind {
1919
Attr,
2020
}
2121

22-
pub trait AsAny: Any {
23-
fn as_any(&self) -> &dyn Any;
24-
}
25-
26-
impl<T: Any> AsAny for T {
27-
fn as_any(&self) -> &dyn Any {
28-
self
29-
}
30-
}
31-
3222
/// A proc-macro expander implementation.
33-
pub trait ProcMacroExpander: fmt::Debug + Send + Sync + RefUnwindSafe + AsAny {
23+
pub trait ProcMacroExpander: fmt::Debug + Send + Sync + RefUnwindSafe + Any {
3424
/// Run the expander with the given input subtree, optional attribute input subtree (for
3525
/// [`ProcMacroKind::Attr`]), environment variables, and span information.
3626
fn expand(
@@ -44,7 +34,9 @@ pub trait ProcMacroExpander: fmt::Debug + Send + Sync + RefUnwindSafe + AsAny {
4434
current_dir: String,
4535
) -> Result<tt::TopSubtree, ProcMacroExpansionError>;
4636

47-
fn eq_dyn(&self, other: &dyn ProcMacroExpander) -> bool;
37+
fn eq_dyn(&self, other: &dyn ProcMacroExpander) -> bool {
38+
other.type_id() == self.type_id()
39+
}
4840
}
4941

5042
impl PartialEq for dyn ProcMacroExpander {

crates/load-cargo/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,6 @@ impl ProcMacroExpander for Expander {
512512
Err(err) => Err(ProcMacroExpansionError::System(err.to_string())),
513513
}
514514
}
515-
516-
fn eq_dyn(&self, other: &dyn ProcMacroExpander) -> bool {
517-
other.as_any().downcast_ref::<Self>().is_some_and(|other| self == other)
518-
}
519515
}
520516

521517
#[cfg(test)]

crates/test-fixture/src/lib.rs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -662,10 +662,6 @@ impl ProcMacroExpander for IdentityProcMacroExpander {
662662
) -> Result<TopSubtree, ProcMacroExpansionError> {
663663
Ok(subtree.clone())
664664
}
665-
666-
fn eq_dyn(&self, other: &dyn ProcMacroExpander) -> bool {
667-
other.as_any().type_id() == std::any::TypeId::of::<Self>()
668-
}
669665
}
670666

671667
// Expands to a macro_rules! macro, for issue #18089.
@@ -697,10 +693,6 @@ impl ProcMacroExpander for Issue18089ProcMacroExpander {
697693
#subtree
698694
})
699695
}
700-
701-
fn eq_dyn(&self, other: &dyn ProcMacroExpander) -> bool {
702-
other.as_any().type_id() == std::any::TypeId::of::<Self>()
703-
}
704696
}
705697

706698
// Pastes the attribute input as its output
@@ -721,10 +713,6 @@ impl ProcMacroExpander for AttributeInputReplaceProcMacroExpander {
721713
.cloned()
722714
.ok_or_else(|| ProcMacroExpansionError::Panic("Expected attribute input".into()))
723715
}
724-
725-
fn eq_dyn(&self, other: &dyn ProcMacroExpander) -> bool {
726-
other.as_any().type_id() == std::any::TypeId::of::<Self>()
727-
}
728716
}
729717

730718
#[derive(Debug)]
@@ -756,10 +744,6 @@ impl ProcMacroExpander for Issue18840ProcMacroExpander {
756744
top_subtree_delimiter_mut.close = def_site;
757745
Ok(result)
758746
}
759-
760-
fn eq_dyn(&self, other: &dyn ProcMacroExpander) -> bool {
761-
other.as_any().type_id() == std::any::TypeId::of::<Self>()
762-
}
763747
}
764748

765749
#[derive(Debug)]
@@ -791,10 +775,6 @@ impl ProcMacroExpander for MirrorProcMacroExpander {
791775
traverse(&mut builder, input.iter());
792776
Ok(builder.build())
793777
}
794-
795-
fn eq_dyn(&self, other: &dyn ProcMacroExpander) -> bool {
796-
other.as_any().type_id() == std::any::TypeId::of::<Self>()
797-
}
798778
}
799779

800780
// Replaces every literal with an empty string literal and every identifier with its first letter,
@@ -835,10 +815,6 @@ impl ProcMacroExpander for ShortenProcMacroExpander {
835815
}
836816
}
837817
}
838-
839-
fn eq_dyn(&self, other: &dyn ProcMacroExpander) -> bool {
840-
other.as_any().type_id() == std::any::TypeId::of::<Self>()
841-
}
842818
}
843819

844820
// Reads ident type within string quotes, for issue #17479.
@@ -864,10 +840,6 @@ impl ProcMacroExpander for Issue17479ProcMacroExpander {
864840
#symbol()
865841
})
866842
}
867-
868-
fn eq_dyn(&self, other: &dyn ProcMacroExpander) -> bool {
869-
other.as_any().type_id() == std::any::TypeId::of::<Self>()
870-
}
871843
}
872844

873845
// Reads ident type within string quotes, for issue #17479.
@@ -919,10 +891,6 @@ impl ProcMacroExpander for Issue18898ProcMacroExpander {
919891
}
920892
})
921893
}
922-
923-
fn eq_dyn(&self, other: &dyn ProcMacroExpander) -> bool {
924-
other.as_any().type_id() == std::any::TypeId::of::<Self>()
925-
}
926894
}
927895

928896
// Reads ident type within string quotes, for issue #17479.
@@ -950,8 +918,4 @@ impl ProcMacroExpander for DisallowCfgProcMacroExpander {
950918
}
951919
Ok(subtree.clone())
952920
}
953-
954-
fn eq_dyn(&self, other: &dyn ProcMacroExpander) -> bool {
955-
other.as_any().type_id() == std::any::TypeId::of::<Self>()
956-
}
957921
}

0 commit comments

Comments
 (0)