summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Fitzgerald <fitzgen@gmail.com>2017-09-29 16:29:00 -0700
committerNick Fitzgerald <fitzgen@gmail.com>2017-10-02 11:33:26 -0700
commit2a0cee7e01ca7fb993ba4b2feaab51e343583be6 (patch)
treef574c6023232cb889eb0b8a9172b6da707369b24
parent25ce0f658775bc866179c291e2f0c85f797a5b6b (diff)
Make functions which take an ItemId generic to take any kind of id
-rw-r--r--src/codegen/mod.rs8
-rw-r--r--src/ir/analysis/derive_copy.rs12
-rw-r--r--src/ir/analysis/derive_debug.rs12
-rw-r--r--src/ir/analysis/derive_default.rs12
-rw-r--r--src/ir/analysis/derive_hash.rs3
-rw-r--r--src/ir/analysis/derive_partial_eq_or_partial_ord.rs3
-rw-r--r--src/ir/analysis/has_destructor.rs3
-rw-r--r--src/ir/analysis/has_float.rs3
-rw-r--r--src/ir/analysis/has_type_param_in_array.rs3
-rw-r--r--src/ir/analysis/has_vtable.rs3
-rw-r--r--src/ir/analysis/template_params.rs3
-rw-r--r--src/ir/context.rs31
-rw-r--r--src/ir/item.rs6
13 files changed, 63 insertions, 39 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index b0c1b18e..fef5d027 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -151,12 +151,12 @@ impl<'a> CodegenResult<'a> {
self.saw_objc = true;
}
- fn seen(&self, item: ItemId) -> bool {
- self.items_seen.contains(&item)
+ fn seen<Id: Into<ItemId>>(&self, item: Id) -> bool {
+ self.items_seen.contains(&item.into())
}
- fn set_seen(&mut self, item: ItemId) {
- self.items_seen.insert(item);
+ fn set_seen<Id: Into<ItemId>>(&mut self, item: Id) {
+ self.items_seen.insert(item.into());
}
fn seen_function(&self, name: &str) -> bool {
diff --git a/src/ir/analysis/derive_copy.rs b/src/ir/analysis/derive_copy.rs
index 319f67cd..e4241b5b 100644
--- a/src/ir/analysis/derive_copy.rs
+++ b/src/ir/analysis/derive_copy.rs
@@ -73,7 +73,8 @@ impl<'ctx> CannotDeriveCopy<'ctx> {
}
}
- fn insert(&mut self, id: ItemId) -> ConstrainResult {
+ fn insert<Id: Into<ItemId>>(&mut self, id: Id) -> ConstrainResult {
+ let id = id.into();
trace!("inserting {:?} into the cannot_derive_copy set", id);
let was_not_already_in_set = self.cannot_derive_copy.insert(id);
@@ -89,7 +90,8 @@ impl<'ctx> CannotDeriveCopy<'ctx> {
/// A type is not `Copy` if we've determined it is not copy, or if it is
/// blacklisted.
- fn is_not_copy(&self, id: ItemId) -> bool {
+ fn is_not_copy<Id: Into<ItemId>>(&self, id: Id) -> bool {
+ let id = id.into();
self.cannot_derive_copy.contains(&id) ||
!self.ctx.whitelisted_items().contains(&id)
}
@@ -177,7 +179,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveCopy<'ctx> {
}
TypeKind::Array(t, len) => {
- let cant_derive_copy = self.is_not_copy(t.into());
+ let cant_derive_copy = self.is_not_copy(t);
if cant_derive_copy {
trace!(
" arrays of T for which we cannot derive Copy \
@@ -198,7 +200,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveCopy<'ctx> {
TypeKind::ResolvedTypeRef(t) |
TypeKind::TemplateAlias(t, _) |
TypeKind::Alias(t) => {
- let cant_derive_copy = self.is_not_copy(t.into());
+ let cant_derive_copy = self.is_not_copy(t);
if cant_derive_copy {
trace!(
" arrays of T for which we cannot derive Copy \
@@ -307,7 +309,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveCopy<'ctx> {
"The early ty.is_opaque check should have handled this case"
);
let def_cannot_derive = self.is_not_copy(
- template.template_definition().into(),
+ template.template_definition()
);
if def_cannot_derive {
trace!(
diff --git a/src/ir/analysis/derive_debug.rs b/src/ir/analysis/derive_debug.rs
index 0ca94cd1..a1743ae9 100644
--- a/src/ir/analysis/derive_debug.rs
+++ b/src/ir/analysis/derive_debug.rs
@@ -74,7 +74,8 @@ impl<'ctx> CannotDeriveDebug<'ctx> {
}
}
- fn insert(&mut self, id: ItemId) -> ConstrainResult {
+ fn insert<Id: Into<ItemId>>(&mut self, id: Id) -> ConstrainResult {
+ let id = id.into();
trace!("inserting {:?} into the cannot_derive_debug set", id);
let was_not_already_in_set = self.cannot_derive_debug.insert(id);
@@ -90,7 +91,8 @@ impl<'ctx> CannotDeriveDebug<'ctx> {
/// A type is not `Debug` if we've determined it is not debug, or if it is
/// blacklisted.
- fn is_not_debug(&self, id: ItemId) -> bool {
+ fn is_not_debug<Id: Into<ItemId>>(&self, id: Id) -> bool {
+ let id = id.into();
self.cannot_derive_debug.contains(&id) ||
!self.ctx.whitelisted_items().contains(&id)
}
@@ -191,7 +193,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveDebug<'ctx> {
}
TypeKind::Array(t, len) => {
- if self.is_not_debug(t.into()) {
+ if self.is_not_debug(t) {
trace!(
" arrays of T for which we cannot derive Debug \
also cannot derive Debug"
@@ -211,7 +213,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveDebug<'ctx> {
TypeKind::ResolvedTypeRef(t) |
TypeKind::TemplateAlias(t, _) |
TypeKind::Alias(t) => {
- if self.is_not_debug(t.into()) {
+ if self.is_not_debug(t) {
trace!(
" aliases and type refs to T which cannot derive \
Debug also cannot derive Debug"
@@ -325,7 +327,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveDebug<'ctx> {
"The early ty.is_opaque check should have handled this case"
);
let def_cannot_derive = self.is_not_debug(
- template.template_definition().into(),
+ template.template_definition()
);
if def_cannot_derive {
trace!(
diff --git a/src/ir/analysis/derive_default.rs b/src/ir/analysis/derive_default.rs
index aff99681..4c208b37 100644
--- a/src/ir/analysis/derive_default.rs
+++ b/src/ir/analysis/derive_default.rs
@@ -71,7 +71,8 @@ impl<'ctx> CannotDeriveDefault<'ctx> {
}
}
- fn insert(&mut self, id: ItemId) -> ConstrainResult {
+ fn insert<Id: Into<ItemId>>(&mut self, id: Id) -> ConstrainResult {
+ let id = id.into();
trace!("inserting {:?} into the cannot_derive_default set", id);
let was_not_already_in_set = self.cannot_derive_default.insert(id);
@@ -85,7 +86,8 @@ impl<'ctx> CannotDeriveDefault<'ctx> {
ConstrainResult::Changed
}
- fn is_not_default(&self, id: ItemId) -> bool {
+ fn is_not_default<Id: Into<ItemId>>(&self, id: Id) -> bool {
+ let id = id.into();
self.cannot_derive_default.contains(&id) ||
!self.ctx.whitelisted_items().contains(&id)
}
@@ -222,7 +224,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveDefault<'ctx> {
}
TypeKind::Array(t, len) => {
- if self.is_not_default(t.into()) {
+ if self.is_not_default(t) {
trace!(
" arrays of T for which we cannot derive Default \
also cannot derive Default"
@@ -242,7 +244,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveDefault<'ctx> {
TypeKind::ResolvedTypeRef(t) |
TypeKind::TemplateAlias(t, _) |
TypeKind::Alias(t) => {
- if self.is_not_default(t.into()) {
+ if self.is_not_default(t) {
trace!(
" aliases and type refs to T which cannot derive \
Default also cannot derive Default"
@@ -353,7 +355,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveDefault<'ctx> {
"The early ty.is_opaque check should have handled this case"
);
let def_cannot_derive =
- self.is_not_default(template.template_definition().into());
+ self.is_not_default(template.template_definition());
if def_cannot_derive {
trace!(
" template definition cannot derive Default, so \
diff --git a/src/ir/analysis/derive_hash.rs b/src/ir/analysis/derive_hash.rs
index 6644ad49..1cbd85fb 100644
--- a/src/ir/analysis/derive_hash.rs
+++ b/src/ir/analysis/derive_hash.rs
@@ -74,7 +74,8 @@ impl<'ctx> CannotDeriveHash<'ctx> {
}
}
- fn insert(&mut self, id: ItemId) -> ConstrainResult {
+ fn insert<Id: Into<ItemId>>(&mut self, id: Id) -> ConstrainResult {
+ let id = id.into();
trace!("inserting {:?} into the cannot_derive_hash set", id);
let was_not_already_in_set = self.cannot_derive_hash.insert(id);
diff --git a/src/ir/analysis/derive_partial_eq_or_partial_ord.rs b/src/ir/analysis/derive_partial_eq_or_partial_ord.rs
index 14e6cd9b..6750dc3b 100644
--- a/src/ir/analysis/derive_partial_eq_or_partial_ord.rs
+++ b/src/ir/analysis/derive_partial_eq_or_partial_ord.rs
@@ -83,7 +83,8 @@ impl<'ctx> CannotDerivePartialEqOrPartialOrd<'ctx> {
}
}
- fn insert(&mut self, id: ItemId) -> ConstrainResult {
+ fn insert<Id: Into<ItemId>>(&mut self, id: Id) -> ConstrainResult {
+ let id = id.into();
trace!("inserting {:?} into the cannot_derive_partialeq_or_partialord set", id);
let was_not_already_in_set = self.cannot_derive_partialeq_or_partialord.insert(id);
diff --git a/src/ir/analysis/has_destructor.rs b/src/ir/analysis/has_destructor.rs
index 2d3bb89f..28537b71 100644
--- a/src/ir/analysis/has_destructor.rs
+++ b/src/ir/analysis/has_destructor.rs
@@ -54,7 +54,8 @@ impl<'ctx> HasDestructorAnalysis<'ctx> {
}
}
- fn insert(&mut self, id: ItemId) -> ConstrainResult {
+ fn insert<Id: Into<ItemId>>(&mut self, id: Id) -> ConstrainResult {
+ let id = id.into();
let was_not_already_in_set = self.have_destructor.insert(id);
assert!(
was_not_already_in_set,
diff --git a/src/ir/analysis/has_float.rs b/src/ir/analysis/has_float.rs
index 0f0fb385..60c53b7d 100644
--- a/src/ir/analysis/has_float.rs
+++ b/src/ir/analysis/has_float.rs
@@ -62,7 +62,8 @@ impl<'ctx> HasFloat<'ctx> {
}
}
- fn insert(&mut self, id: ItemId) -> ConstrainResult {
+ fn insert<Id: Into<ItemId>>(&mut self, id: Id) -> ConstrainResult {
+ let id = id.into();
trace!("inserting {:?} into the has_float set", id);
let was_not_already_in_set = self.has_float.insert(id);
diff --git a/src/ir/analysis/has_type_param_in_array.rs b/src/ir/analysis/has_type_param_in_array.rs
index 09783037..ce1ed77f 100644
--- a/src/ir/analysis/has_type_param_in_array.rs
+++ b/src/ir/analysis/has_type_param_in_array.rs
@@ -64,7 +64,8 @@ impl<'ctx> HasTypeParameterInArray<'ctx> {
}
}
- fn insert(&mut self, id: ItemId) -> ConstrainResult {
+ fn insert<Id: Into<ItemId>>(&mut self, id: Id) -> ConstrainResult {
+ let id = id.into();
trace!(
"inserting {:?} into the has_type_parameter_in_array set",
id
diff --git a/src/ir/analysis/has_vtable.rs b/src/ir/analysis/has_vtable.rs
index 3d44dd92..a0615daf 100644
--- a/src/ir/analysis/has_vtable.rs
+++ b/src/ir/analysis/has_vtable.rs
@@ -47,7 +47,8 @@ impl<'ctx> HasVtableAnalysis<'ctx> {
}
}
- fn insert(&mut self, id: ItemId) -> ConstrainResult {
+ fn insert<Id: Into<ItemId>>(&mut self, id: Id) -> ConstrainResult {
+ let id = id.into();
let was_not_already_in_set = self.have_vtable.insert(id);
assert!(
was_not_already_in_set,
diff --git a/src/ir/analysis/template_params.rs b/src/ir/analysis/template_params.rs
index d7f5ab57..52986243 100644
--- a/src/ir/analysis/template_params.rs
+++ b/src/ir/analysis/template_params.rs
@@ -203,7 +203,8 @@ impl<'ctx> UsedTemplateParameters<'ctx> {
}
}
- fn take_this_id_usage_set(&mut self, this_id: ItemId) -> ItemSet {
+ fn take_this_id_usage_set<Id: Into<ItemId>>(&mut self, this_id: Id) -> ItemSet {
+ let this_id = this_id.into();
self.used
.get_mut(&this_id)
.expect(
diff --git a/src/ir/context.rs b/src/ir/context.rs
index 2fef35ee..45d8ed13 100644
--- a/src/ir/context.rs
+++ b/src/ir/context.rs
@@ -1840,7 +1840,8 @@ impl BindgenContext {
/// Is the item with the given `name` blacklisted? Or is the item with the given
/// `name` and `id` replaced by another type, and effectively blacklisted?
- pub fn blacklisted_by_name(&self, path: &[String], id: ItemId) -> bool {
+ pub fn blacklisted_by_name<Id: Into<ItemId>>(&self, path: &[String], id: Id) -> bool {
+ let id = id.into();
debug_assert!(
self.in_codegen_phase(),
"You're not supposed to call this yet"
@@ -1851,7 +1852,8 @@ impl BindgenContext {
/// Has the item with the given `name` and `id` been replaced by another
/// type?
- pub fn is_replaced_type(&self, path: &[String], id: ItemId) -> bool {
+ pub fn is_replaced_type<Id: Into<ItemId>>(&self, path: &[String], id: Id) -> bool {
+ let id = id.into();
match self.replacements.get(path) {
Some(replaced_by) if *replaced_by != id => true,
_ => false,
@@ -2133,7 +2135,8 @@ impl BindgenContext {
/// Look up whether the item with `id` can
/// derive debug or not.
- pub fn lookup_item_id_can_derive_debug(&self, id: ItemId) -> bool {
+ pub fn lookup_item_id_can_derive_debug<Id: Into<ItemId>>(&self, id: Id) -> bool {
+ let id = id.into();
assert!(
self.in_codegen_phase(),
"We only compute can_derive_debug when we enter codegen"
@@ -2156,7 +2159,8 @@ impl BindgenContext {
/// Look up whether the item with `id` can
/// derive default or not.
- pub fn lookup_item_id_can_derive_default(&self, id: ItemId) -> bool {
+ pub fn lookup_item_id_can_derive_default<Id: Into<ItemId>>(&self, id: Id) -> bool {
+ let id = id.into();
assert!(
self.in_codegen_phase(),
"We only compute can_derive_default when we enter codegen"
@@ -2185,7 +2189,8 @@ impl BindgenContext {
/// Look up whether the item with `id` can
/// derive hash or not.
- pub fn lookup_item_id_can_derive_hash(&self, id: ItemId) -> bool {
+ pub fn lookup_item_id_can_derive_hash<Id: Into<ItemId>>(&self, id: Id) -> bool {
+ let id = id.into();
assert!(
self.in_codegen_phase(),
"We only compute can_derive_debug when we enter codegen"
@@ -2206,7 +2211,8 @@ impl BindgenContext {
}
/// Look up whether the item with `id` can derive `Partial{Eq,Ord}`.
- pub fn lookup_item_id_can_derive_partialeq_or_partialord(&self, id: ItemId) -> bool {
+ pub fn lookup_item_id_can_derive_partialeq_or_partialord<Id: Into<ItemId>>(&self, id: Id) -> bool {
+ let id = id.into();
assert!(
self.in_codegen_phase(),
"We only compute can_derive_partialeq_or_partialord when we enter codegen"
@@ -2298,15 +2304,19 @@ impl TypeId {
}
}
-impl From<ItemId> for ItemResolver {
- fn from(id: ItemId) -> ItemResolver {
+impl<T> From<T> for ItemResolver
+where
+ T: Into<ItemId>
+{
+ fn from(id: T) -> ItemResolver {
ItemResolver::new(id)
}
}
impl ItemResolver {
/// Construct a new `ItemResolver` from the given id.
- pub fn new(id: ItemId) -> ItemResolver {
+ pub fn new<Id: Into<ItemId>>(id: Id) -> ItemResolver {
+ let id = id.into();
ItemResolver {
id: id,
through_type_refs: false,
@@ -2361,7 +2371,8 @@ pub struct PartialType {
impl PartialType {
/// Construct a new `PartialType`.
- pub fn new(decl: Cursor, id: ItemId) -> PartialType {
+ pub fn new<Id: Into<ItemId>>(decl: Cursor, id: Id) -> PartialType {
+ let id = id.into();
// assert!(decl == decl.canonical());
PartialType {
decl: decl,
diff --git a/src/ir/item.rs b/src/ir/item.rs
index 38d562fb..6baf5a06 100644
--- a/src/ir/item.rs
+++ b/src/ir/item.rs
@@ -111,7 +111,7 @@ cfg_if! {
DebugOnlyItemSet
}
- fn contains(&self,_id: &ItemId) -> bool {
+ fn contains(&self, _id: &ItemId) -> bool {
false
}
@@ -474,8 +474,8 @@ impl Item {
/// Set this item's parent id.
///
/// This is only used so replacements get generated in the proper module.
- pub fn set_parent_for_replacement(&mut self, id: ItemId) {
- self.parent_id = id;
+ pub fn set_parent_for_replacement<Id: Into<ItemId>>(&mut self, id: Id) {
+ self.parent_id = id.into();
}
/// Returns the depth this item is indented to.