diff --git a/header-translator/src/availability.rs b/header-translator/src/availability.rs index f00b07f53..d86af499b 100644 --- a/header-translator/src/availability.rs +++ b/header-translator/src/availability.rs @@ -2,6 +2,7 @@ use clang::PlatformAvailability; #[derive(Debug, Clone)] pub struct Availability { + #[allow(dead_code)] inner: Vec, } diff --git a/header-translator/src/main.rs b/header-translator/src/main.rs index 0e07548fc..9a5bf5f84 100644 --- a/header-translator/src/main.rs +++ b/header-translator/src/main.rs @@ -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}; @@ -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>> = BTreeMap::new(); @@ -191,7 +190,7 @@ fn main() { } }); - let mut mod_tokens = quote! { + let mod_tokens = quote! { #(pub(crate) mod #mod_names;)* mod __exported { diff --git a/header-translator/src/method.rs b/header-translator/src/method.rs index 32ad07f4e..7e3201e37 100644 --- a/header-translator/src/method.rs +++ b/header-translator/src/method.rs @@ -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 {}", @@ -240,7 +230,7 @@ impl ToTokens for Method { let arguments: Vec<_> = self .arguments .iter() - .map(|(param, ty)| (format_ident!("{}", handle_reserved(¶m)), ty)) + .map(|(param, ty)| (format_ident!("{}", handle_reserved(param)), ty)) .collect(); let fn_args = arguments diff --git a/header-translator/src/rust_type.rs b/header-translator/src/rust_type.rs index d60439994..e83ec6cca 100644 --- a/header-translator/src/rust_type.rs +++ b/header-translator/src/rust_type.rs @@ -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(), }, @@ -384,7 +384,7 @@ impl ToTokens for RustType { let tokens = match &**pointee { Self::Id { type_, - is_return, + is_return: _, nullability, } => { if *nullability == Nullability::NonNull { @@ -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 { diff --git a/header-translator/src/stmt.rs b/header-translator/src/stmt.rs index 24de13e72..727b4b012 100644 --- a/header-translator/src/stmt.rs +++ b/header-translator/src/stmt.rs @@ -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 { @@ -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"); @@ -329,10 +321,10 @@ impl ToTokens for Stmt { } Self::ClassDecl { name, - availability, + availability: _, superclass, generics, - protocols, + protocols: _, methods, } => { let name = format_ident!("{}", name); @@ -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 { @@ -408,9 +400,9 @@ impl ToTokens for Stmt { } Self::ProtocolDecl { name, - availability, - protocols, - methods, + availability: _, + protocols: _, + methods: _, } => { let name = format_ident!("{}", name);