Skip to content

Commit

Permalink
Appease clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Sep 23, 2022
1 parent 07db82e commit 167ad93
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 50 deletions.
1 change: 1 addition & 0 deletions header-translator/src/availability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use clang::PlatformAvailability;

#[derive(Debug, Clone)]
pub struct Availability {
#[allow(dead_code)]
inner: Vec<PlatformAvailability>,
}

Expand Down
11 changes: 5 additions & 6 deletions header-translator/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use std::collections::{BTreeMap, HashSet};
use std::fs;
use std::io::{Result, Write};
use std::io::Write;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};

use clang::source::File;
use clang::{Clang, Entity, EntityKind, EntityVisitResult, Index};
use clang::{Clang, Entity, EntityVisitResult, Index};
use proc_macro2::{Ident, TokenStream};
use quote::{format_ident, quote, TokenStreamExt};
use quote::{format_ident, quote};

use header_translator::{create_rust_file, Config};

Expand Down Expand Up @@ -100,7 +99,7 @@ fn main() {
dbg!(&entity);
dbg!(entity.get_availability());

let mut entities_left = usize::MAX;
let _entities_left = usize::MAX;

let mut result: BTreeMap<PathBuf, Vec<Entity<'_>>> = BTreeMap::new();

Expand Down Expand Up @@ -191,7 +190,7 @@ fn main() {
}
});

let mut mod_tokens = quote! {
let mod_tokens = quote! {
#(pub(crate) mod #mod_names;)*

mod __exported {
Expand Down
24 changes: 7 additions & 17 deletions header-translator/src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,13 @@ impl MemoryManagement {
/// in a way that we can just use `msg_send_id!`.
fn verify_sel(self, sel: &str) {
let bytes = sel.as_bytes();
if in_selector_family(bytes, b"new") {
assert!(
self == Self::ReturnsRetained,
"{:?} did not match {}",
self,
sel
);
} else if in_selector_family(bytes, b"alloc") {
assert!(
self == Self::ReturnsRetained,
"{:?} did not match {}",
self,
sel
);
} else if in_selector_family(bytes, b"init") {
if in_selector_family(bytes, b"init") {
assert!(self == Self::Init, "{:?} did not match {}", self, sel);
} else if in_selector_family(bytes, b"copy") || in_selector_family(bytes, b"mutableCopy") {
} else if in_selector_family(bytes, b"new")
|| in_selector_family(bytes, b"alloc")
|| in_selector_family(bytes, b"copy")
|| in_selector_family(bytes, b"mutableCopy")
{
assert!(
self == Self::ReturnsRetained,
"{:?} did not match {}",
Expand Down Expand Up @@ -240,7 +230,7 @@ impl ToTokens for Method {
let arguments: Vec<_> = self
.arguments
.iter()
.map(|(param, ty)| (format_ident!("{}", handle_reserved(&param)), ty))
.map(|(param, ty)| (format_ident!("{}", handle_reserved(param)), ty))
.collect();

let fn_args = arguments
Expand Down
16 changes: 7 additions & 9 deletions header-translator/src/rust_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,11 @@ impl RustType {
match Self::parse(param, false, false) {
Self::Id {
type_,
is_return,
nullability,
is_return: _,
nullability: _,
} => type_,
// TODO: Handle this better
Self::Class { nullability } => GenericType {
Self::Class { nullability: _ } => GenericType {
name: "TodoClass".to_string(),
generics: Vec::new(),
},
Expand Down Expand Up @@ -384,7 +384,7 @@ impl ToTokens for RustType {
let tokens = match &**pointee {
Self::Id {
type_,
is_return,
is_return: _,
nullability,
} => {
if *nullability == Nullability::NonNull {
Expand All @@ -398,12 +398,10 @@ impl ToTokens for RustType {
};
if *nullability == Nullability::NonNull {
quote!(NonNull<#tokens>)
} else if *is_const {
quote!(*const #tokens)
} else {
if *is_const {
quote!(*const #tokens)
} else {
quote!(*mut #tokens)
}
quote!(*mut #tokens)
}
}
Array {
Expand Down
28 changes: 10 additions & 18 deletions header-translator/src/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,9 @@ impl Stmt {
EntityKind::InclusionDirective => {
// let file = entity.get_file().expect("inclusion file");
let name = entity.get_name().expect("inclusion name");
let mut iter = name.split("/");
let mut iter = name.split('/');
let framework = iter.next().expect("inclusion name has framework");
let file = if let Some(file) = iter.next() {
file
} else {
// Ignore
return None;
};
let file = iter.next()?;
assert!(iter.count() == 0, "no more left");

Some(Self::FileImport {
Expand All @@ -78,10 +73,7 @@ impl Stmt {
// We intentionally don't handle generics here
Some(Self::ItemImport { name })
}
EntityKind::MacroExpansion
| EntityKind::ObjCClassRef
| EntityKind::ObjCProtocolRef
| EntityKind::MacroDefinition => None,
EntityKind::MacroExpansion | EntityKind::MacroDefinition => None,
EntityKind::ObjCInterfaceDecl => {
// entity.get_mangled_objc_names()
let name = entity.get_name().expect("class name");
Expand Down Expand Up @@ -329,10 +321,10 @@ impl ToTokens for Stmt {
}
Self::ClassDecl {
name,
availability,
availability: _,
superclass,
generics,
protocols,
protocols: _,
methods,
} => {
let name = format_ident!("{}", name);
Expand Down Expand Up @@ -381,10 +373,10 @@ impl ToTokens for Stmt {
}
Self::CategoryDecl {
class_name,
availability,
availability: _,
name,
generics,
protocols,
protocols: _,
methods,
} => {
let meta = if let Some(name) = name {
Expand All @@ -408,9 +400,9 @@ impl ToTokens for Stmt {
}
Self::ProtocolDecl {
name,
availability,
protocols,
methods,
availability: _,
protocols: _,
methods: _,
} => {
let name = format_ident!("{}", name);

Expand Down

0 comments on commit 167ad93

Please sign in to comment.