Skip to content

Commit

Permalink
fix new clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Riateche committed May 16, 2021
1 parent a2fd801 commit 7c19dfa
Show file tree
Hide file tree
Showing 26 changed files with 214 additions and 403 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__common: &common
language: rust
rust: 1.41.0
rust: 1.52.1
script: scripts/travis/run.bash
cache:
directories:
Expand All @@ -16,4 +16,4 @@ matrix:
os: osx
- <<: *common
os: windows
rust: 1.41.0-x86_64-pc-windows-msvc
rust: 1.52.1-x86_64-pc-windows-msvc
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ members = [
]

[patch.crates-io]
amq-proto = { git = "https://github.com/P0ntiuS/rust-amq-proto.git", branch = "error-chain" }
amq-proto = { git = "https://github.com/rust-qt/rust-amq-proto.git", rev = "616a86e7" }

[profile.release]
debug = true
3 changes: 0 additions & 3 deletions qt_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
#![deny(missing_docs)]

// TODO: this will be unneeded soon.
extern crate proc_macro;

use proc_macro::TokenStream;
use proc_macro_hack::proc_macro_hack;

Expand Down
7 changes: 2 additions & 5 deletions qt_ritual/src/bin/cluster_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,11 @@ fn run() -> Result<()> {
let dir = temp_dir.path().join(format!(
"{}_{}",
lib.crate_name,
lib.cpp_library_version
.as_ref()
.map(String::as_str)
.unwrap_or("noversion")
lib.cpp_library_version.as_deref().unwrap_or("noversion")
));
create_dir(&dir)?;

let qmake_path = qmake_path.as_ref().map(String::as_str);
let qmake_path = qmake_path.as_deref();
let config = create_config(CrateProperties::new(&lib.crate_name, ""), qmake_path)?;
let checker = LocalCppChecker::new(dir, &config)?;
let mut checker = checker.get("0")?;
Expand Down
2 changes: 1 addition & 1 deletion qt_ritual/src/detect_signal_argument_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn detect_signal_argument_types(data: &mut ProcessorData<'_>) -> Result<Hash
let mut types_with_omitted_args = HashSet::new();
for t in &all_types {
let mut types = t.clone();
while let Some(_) = types.pop() {
while types.pop().is_some() {
types_with_omitted_args.insert(types.clone());
}
}
Expand Down
10 changes: 3 additions & 7 deletions qt_ritual/src/doc_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
use log::{info, trace};
use ritual_common::errors::{bail, err_msg, Result, ResultExt};
use rusqlite;
use select::document::Document;
use std::io::Read;
use std::path::Path;

/// Decoded documentation data.
Expand All @@ -29,10 +29,6 @@ pub struct DocIndexItem {
pub accessed: bool,
}

use std::io::Read;

use compress;

impl DocData {
/// Returns all index items.
pub fn index(&self) -> &[DocIndexItem] {
Expand Down Expand Up @@ -70,9 +66,9 @@ impl DocData {
&mut self,
mut f: impl FnMut(&DocIndexItem) -> bool,
) -> Option<DocIndexItem> {
self.index.iter_mut().find(|item| f(item)).and_then(|item| {
self.index.iter_mut().find(|item| f(item)).map(|item| {
item.accessed = true;
Some(item.clone())
item.clone()
})
}

Expand Down
18 changes: 5 additions & 13 deletions qt_ritual/src/doc_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,13 +375,9 @@ impl DocParser {

/// Extracts portions of the declaration corresponding to the function's arguments
fn arguments_from_declaration(declaration: &str) -> Option<Vec<&str>> {
match declaration.find('(') {
None => None,
Some(start_index) => match declaration.rfind(')') {
None => None,
Some(end_index) => Some(declaration[start_index + 1..end_index].split(',').collect()),
},
}
let start_index = declaration.find('(')?;
let end_index = declaration.rfind(')')?;
Some(declaration[start_index + 1..end_index].split(',').collect())
}

/// Returns true if argument types in two declarations are equal.
Expand Down Expand Up @@ -482,7 +478,7 @@ fn reformat_qt_declaration(declaration: &str) -> String {
.replace("[virtual]", "virtual")
.replace("[signal]", "")
.replace("[slot]", "");
if declaration.find("[pure virtual]").is_some() {
if declaration.contains("[pure virtual]") {
declaration = format!("virtual {} = 0", declaration.replace("[pure virtual]", ""));
}
declaration
Expand Down Expand Up @@ -533,11 +529,7 @@ fn parse_item_doc(h3: Node<'_>, base_url: &str) -> Result<ItemDoc> {
Some(node)
} else {
let mut value_list_r = node.find(value_list_condition);
if let Some(value_list) = value_list_r.next() {
Some(value_list)
} else {
None
}
value_list_r.next()
};

if let Some(value_list_node) = value_list_node {
Expand Down
2 changes: 1 addition & 1 deletion qt_ritual/src/lib_configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ pub fn create_config(

let steps = config.processing_steps_mut();
let crate_name_clone = crate_name.to_string();
let docs_path = qt_config.installation_data.docs_path.clone();
let docs_path = qt_config.installation_data.docs_path;

steps.add_after(&["cpp_parser"], "qt_doc_parser", move |data| {
parse_docs(data, &crate_name_clone, &docs_path)
Expand Down
16 changes: 8 additions & 8 deletions ritual/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ impl Config {
}

pub fn cpp_lib_version(&self) -> Option<&str> {
self.cpp_lib_version.as_ref().map(String::as_str)
self.cpp_lib_version.as_deref()
}

pub fn processing_steps(&self) -> &ProcessingSteps {
Expand Down Expand Up @@ -412,7 +412,7 @@ impl Config {
pub fn movable_types_hook(
&self,
) -> Option<&(dyn Fn(&CppPath) -> Result<MovableTypesHookOutput> + 'static)> {
self.movable_types_hook.as_ref().map(|b| &**b)
self.movable_types_hook.as_deref()
}

/// Adds a C++ identifier that should be skipped
Expand All @@ -434,7 +434,7 @@ impl Config {
}

pub fn cpp_parser_path_hook(&self) -> Option<&(dyn Fn(&CppPath) -> Result<bool> + 'static)> {
self.cpp_parser_path_hook.as_ref().map(|b| &**b)
self.cpp_parser_path_hook.as_deref()
}

pub fn set_rust_path_scope_hook(
Expand All @@ -449,7 +449,7 @@ impl Config {
}

pub fn rust_path_scope_hook(&self) -> Option<&RustPathScopeHook> {
self.rust_path_scope_hook.as_ref().map(|b| &**b)
self.rust_path_scope_hook.as_deref()
}

pub fn set_rust_path_hook(
Expand All @@ -461,7 +461,7 @@ impl Config {
}

pub fn rust_path_hook(&self) -> Option<&RustPathHook> {
self.rust_path_hook.as_ref().map(|b| &**b)
self.rust_path_hook.as_deref()
}

pub fn set_rust_item_hook(
Expand All @@ -473,7 +473,7 @@ impl Config {
}

pub fn rust_item_hook(&self) -> Option<&RustItemHook> {
self.rust_item_hook.as_ref().map(|b| &**b)
self.rust_item_hook.as_deref()
}

pub fn add_after_cpp_parser_hook(
Expand All @@ -496,7 +496,7 @@ impl Config {
}

pub fn cpp_item_filter_hook(&self) -> Option<&CppItemFilterHook> {
self.cpp_item_filter_hook.as_ref().map(|b| &**b)
self.cpp_item_filter_hook.as_deref()
}

pub fn set_cluster_config(&mut self, cluster_config: ClusterConfig) {
Expand Down Expand Up @@ -549,7 +549,7 @@ impl GlobalConfig {
pub fn create_config_hook(
&mut self,
) -> Option<&mut (dyn FnMut(CrateProperties) -> Result<Config> + 'static)> {
self.create_config_hook.as_mut().map(|b| &mut **b)
self.create_config_hook.as_deref_mut()
}

pub fn set_all_crate_names(&mut self, names: Vec<String>) {
Expand Down
41 changes: 19 additions & 22 deletions ritual/src/cpp_casts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,25 @@ fn generate_casts_one(
kind: CppPointerLikeTypeKind::Pointer,
target: Box::new(CppType::Class(base_type.clone())),
};
let mut new_methods = Vec::new();
new_methods.push(create_cast_method(
CppCast::Static {
is_unsafe: true,
base_index: direct_base_index,
},
&base_ptr_type,
&target_ptr_type,
)?);
new_methods.push(create_cast_method(
CppCast::Static {
is_unsafe: false,
base_index: direct_base_index,
},
&target_ptr_type,
&base_ptr_type,
)?);
new_methods.push(create_cast_method(
CppCast::Dynamic,
&base_ptr_type,
&target_ptr_type,
)?);
let mut new_methods = vec![
create_cast_method(
CppCast::Static {
is_unsafe: true,
base_index: direct_base_index,
},
&base_ptr_type,
&target_ptr_type,
)?,
create_cast_method(
CppCast::Static {
is_unsafe: false,
base_index: direct_base_index,
},
&target_ptr_type,
&base_ptr_type,
)?,
create_cast_method(CppCast::Dynamic, &base_ptr_type, &target_ptr_type)?,
];

for item in data.db.all_cpp_items().filter_map(|i| i.item.as_base_ref()) {
if &item.derived_class_type == base_type {
Expand Down
10 changes: 2 additions & 8 deletions ritual/src/cpp_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,17 +390,11 @@ impl CppTypeDeclaration {
impl CppTypeDeclarationKind {
/// Checks if the type is a class type.
pub fn is_class(&self) -> bool {
match self {
CppTypeDeclarationKind::Class { .. } => true,
_ => false,
}
matches!(self, CppTypeDeclarationKind::Class { .. })
}

pub fn is_enum(&self) -> bool {
match self {
CppTypeDeclarationKind::Enum => true,
_ => false,
}
matches!(self, CppTypeDeclarationKind::Enum)
}
}

Expand Down
31 changes: 6 additions & 25 deletions ritual/src/cpp_ffi_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,7 @@ impl CppFfiArgumentMeaning {
/// Checks if this argument corresponds to an original
/// C++ method's argument
pub fn is_argument(&self) -> bool {
match *self {
CppFfiArgumentMeaning::Argument(..) => true,
_ => false,
}
matches!(self, CppFfiArgumentMeaning::Argument(..))
}
}

Expand Down Expand Up @@ -181,11 +178,7 @@ impl CppFfiFunction {
pub fn has_same_kind(&self, other: &Self) -> bool {
match &self.kind {
CppFfiFunctionKind::Function { .. } => {
if let CppFfiFunctionKind::Function { .. } = &other.kind {
true
} else {
false
}
matches!(&other.kind, CppFfiFunctionKind::Function { .. })
}
CppFfiFunctionKind::FieldAccessor { accessor_type, .. } => {
if let CppFfiFunctionKind::FieldAccessor {
Expand Down Expand Up @@ -242,8 +235,8 @@ impl CppFfiType {
conversion,
}),
CppToFfiTypeConversion::ImplicitCast { ffi_type } => Ok(CppFfiType {
ffi_type,
original_type,
ffi_type,
conversion,
}),
}
Expand Down Expand Up @@ -311,11 +304,7 @@ impl CppFfiItem {
}

pub fn is_function(&self) -> bool {
if let CppFfiItem::Function(_) = self {
true
} else {
false
}
matches!(self, CppFfiItem::Function(_))
}

pub fn as_slot_wrapper_ref(&self) -> Option<&QtSlotWrapper> {
Expand All @@ -335,19 +324,11 @@ impl CppFfiItem {
}

pub fn is_slot_wrapper(&self) -> bool {
if let CppFfiItem::QtSlotWrapper(_) = self {
true
} else {
false
}
matches!(self, CppFfiItem::QtSlotWrapper(_))
}

pub fn is_signal_wrapper(&self) -> bool {
if let CppFfiItem::QtSignalWrapper(_) = self {
true
} else {
false
}
matches!(self, CppFfiItem::QtSignalWrapper(_))
}

pub fn short_text(&self) -> String {
Expand Down
9 changes: 3 additions & 6 deletions ritual/src/cpp_ffi_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl FfiNameProvider {
.map(|f| f.item.path().to_cpp_code().unwrap())
.collect();

FfiNameProvider { prefix, names }
FfiNameProvider { names, prefix }
}

pub fn testing() -> Self {
Expand Down Expand Up @@ -202,16 +202,13 @@ fn generate_ffi_methods_for_method(
movable_types: &[CppPath],
name_provider: &mut FfiNameProvider,
) -> Result<Vec<CppFfiItem>> {
let mut methods = Vec::new();
methods.push(CppFfiItem::Function(to_ffi_method(
Ok(vec![CppFfiItem::Function(to_ffi_method(
NewFfiFunctionKind::Function {
cpp_function: method.clone(),
},
movable_types,
name_provider,
)?));

Ok(methods)
)?)])
}

pub enum NewFfiFunctionKind {
Expand Down
Loading

0 comments on commit 7c19dfa

Please sign in to comment.