Skip to content

feat: add Debug,Clone,Eq traits to callback objects #3228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions bindgen-tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ pub fn main() {
.replace(|c| !char::is_alphanumeric(c), "_")
.replace("__", "_")
.to_lowercase();
writeln!(dst, "test_header!(header_{func}, {:?});", entry.path())
.unwrap();
writeln!(
dst,
"test_header!(header_{func}, {});",
entry.path().display()
)
.unwrap();
}
}

Expand Down
10 changes: 5 additions & 5 deletions bindgen/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ pub enum DiscoveredItem {

/// Relevant information about a type to which new derive attributes will be added using
/// [`ParseCallbacks::add_derives`].
#[derive(Debug)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub struct DeriveInfo<'a> {
/// The name of the type.
Expand All @@ -259,7 +259,7 @@ pub struct DeriveInfo<'a> {

/// Relevant information about a type to which new attributes will be added using
/// [`ParseCallbacks::add_attributes`].
#[derive(Debug)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub struct AttributeInfo<'a> {
/// The name of the type.
Expand All @@ -280,7 +280,7 @@ pub enum TypeKind {
}

/// A struct providing information about the item being passed to [`ParseCallbacks::generated_name_override`].
#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub struct ItemInfo<'a> {
/// The name of the item
Expand All @@ -290,7 +290,7 @@ pub struct ItemInfo<'a> {
}

/// An enum indicating the kind of item for an `ItemInfo`.
#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum ItemKind {
/// A module
Expand All @@ -305,7 +305,7 @@ pub enum ItemKind {

/// Relevant information about a field for which visibility can be determined using
/// [`ParseCallbacks::field_visibility`].
#[derive(Debug)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub struct FieldInfo<'a> {
/// The name of the type.
Expand Down
8 changes: 4 additions & 4 deletions bindgen/ir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
self.need_bitfield_allocation.push(id);
}

let old_item = mem::replace(&mut self.items[id.0], Some(item));
let old_item = self.items[id.0].replace(item);
assert!(
old_item.is_none(),
"should not have already associated an item with the given id"
Expand Down Expand Up @@ -827,7 +827,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
self.add_item_to_module(&item);

let id = item.id();
let old_item = mem::replace(&mut self.items[id.0], Some(item));
let old_item = self.items[id.0].replace(item);
assert!(
old_item.is_none(),
"should not have already associated an item with the given id"
Expand Down Expand Up @@ -987,7 +987,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"

let result = f(self, &mut item);

let existing = mem::replace(&mut self.items[id.0], Some(item));
let existing = self.items[id.0].replace(item);
assert!(existing.is_none());

result
Expand Down Expand Up @@ -1434,7 +1434,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
debug_assert!(item.kind().is_type());
self.add_item_to_module(&item);
let id = item.id();
let old_item = mem::replace(&mut self.items[id.0], Some(item));
let old_item = self.items[id.0].replace(item);
assert!(old_item.is_none(), "Inserted type twice?");
}

Expand Down
2 changes: 1 addition & 1 deletion bindgen/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ impl Bindings {
}

/// Gets the rustfmt path to rustfmt the generated bindings.
fn rustfmt_path(&self) -> io::Result<Cow<'_, PathBuf>> {
fn rustfmt_path(&self) -> io::Result<Cow<'_, Path>> {
debug_assert!(matches!(self.options.formatter, Formatter::Rustfmt));
if let Some(ref p) = self.options.rustfmt_path {
return Ok(Cow::Borrowed(p));
Expand Down
Loading