Use ResolvableName as resolutions map key
diff --git a/syntax/mod.rs b/syntax/mod.rs
index 12b269e..da1dbf8 100644
--- a/syntax/mod.rs
+++ b/syntax/mod.rs
@@ -228,7 +228,8 @@
// Wrapper for a type which needs to be resolved before it can be printed in
// C++.
-#[derive(Clone, PartialEq, Hash)]
+#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
+#[repr(transparent)]
pub struct ResolvableName {
pub rust: Ident,
}
diff --git a/syntax/names.rs b/syntax/names.rs
index 25ae9f4..b4d8ef1 100644
--- a/syntax/names.rs
+++ b/syntax/names.rs
@@ -53,6 +53,10 @@
Self { rust: ident }
}
+ pub fn from_ref(ident: &Ident) -> &Self {
+ unsafe { &*(ident as *const Ident as *const Self) }
+ }
+
pub fn make_self(span: Span) -> Self {
Self {
rust: Token.into(),
diff --git a/syntax/types.rs b/syntax/types.rs
index 1b61cdb..9fe3562 100644
--- a/syntax/types.rs
+++ b/syntax/types.rs
@@ -20,7 +20,7 @@
pub untrusted: Map<&'a Ident, &'a ExternType>,
pub required_trivial: Map<&'a Ident, TrivialReason<'a>>,
pub explicit_impls: Set<&'a Impl>,
- pub resolutions: Map<&'a Ident, &'a Pair>,
+ pub resolutions: Map<&'a ResolvableName, &'a Pair>,
pub struct_improper_ctypes: UnorderedSet<&'a Ident>,
pub toposorted_structs: Vec<&'a Struct>,
}
@@ -63,7 +63,7 @@
}
let mut add_resolution = |pair: &'a Pair| {
- resolutions.insert(&pair.rust, pair);
+ resolutions.insert(ResolvableName::from_ref(&pair.rust), pair);
};
let mut type_names = UnorderedSet::new();
@@ -291,9 +291,7 @@
}
pub fn resolve(&self, ident: &ResolvableName) -> &Pair {
- self.resolutions
- .get(&ident.rust)
- .expect("Unable to resolve type")
+ self.resolutions.get(ident).expect("Unable to resolve type")
}
}