Skip to content
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

Fix clippy lints #320

Merged
merged 9 commits into from
Jun 24, 2020
Merged
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
25 changes: 24 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,30 @@ jobs:
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-targets --all-features
args: --all-targets --all-features -- -D warnings

clippy-windows:
name: Clippy-Windows
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- name: Install Erlang/Elixir
run: choco install elixir
- name: Extend PATH
run: echo "::add-path::C:\\ProgramData\\chocolatey\\lib\\Elixir\\bin"
- name: Build API
working-directory: rustler_sys
run: |
cargo build
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: clippy
override: true
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-targets --all-features -- -D warnings

format:
name: Format
Expand Down
13 changes: 8 additions & 5 deletions rustler/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ fn activate_versions(version: &str) {
let index = NIF_VERSION
.iter()
.position(|&v| v == version)
.expect(&format!(
"Erlang version {} not handled, please file a a bug report.",
version
));

.unwrap_or_else(|| {
panic!(
"Erlang version {} not handled, please file a a bug report.",
version
)
});

#[allow(clippy::needless_range_loop)]
for i in 0..=index {
println!(
"cargo:rustc-cfg=nif_version_{}",
Expand Down
1 change: 1 addition & 0 deletions rustler/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(non_camel_case_types)]
#![allow(clippy::missing_safety_doc)]

//! [Github](https://github.com/rusterlium/rustler)
//! [Example](https://github.com/hansihe/Rustler_Example)
Expand Down
4 changes: 2 additions & 2 deletions rustler_codegen/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Parse for InitMacroInput {
fn parse_expr_assigns(input: ParseStream) -> Vec<syn::ExprAssign> {
let mut vec = Vec::new();

while let Ok(_) = <Token![,]>::parse(input) {
while <Token![,]>::parse(input).is_ok() {
match syn::ExprAssign::parse(input) {
Ok(expr) => vec.push(expr),
Err(err) => panic!("{} (i.e. `load = load`)", err),
Expand All @@ -41,7 +41,7 @@ fn extract_option(args: Vec<syn::ExprAssign>, name: &str) -> TokenStream {
if let syn::Expr::Path(syn::ExprPath { path, .. }) = &*left {
if let Some(ident) = path.get_ident() {
if *ident == name {
let value = *right.clone();
let value = *right;
return quote!(Some(#value));
}
}
Expand Down
2 changes: 1 addition & 1 deletion rustler_codegen/src/nif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn transcoder_decorator(args: syn::AttributeArgs, fun: syn::ItemFn) -> Token
let arity = arity(inputs.clone());
let decoded_terms = extract_inputs(inputs.clone());
let argument_names = create_function_params(inputs.clone());
let erl_func_name = extract_attr_value(args.clone(), "name")
let erl_func_name = extract_attr_value(args, "name")
.map(|ref n| syn::Ident::new(n, Span::call_site()))
.unwrap_or_else(|| name.clone());

Expand Down
2 changes: 1 addition & 1 deletion rustler_sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const SNIPPET_NAME: &str = "nif_api.snippet";

fn try_gen_api(dst: &Path, pointer_size: usize) -> bool {
// use environment escript if available
let escript = env::var("ESCRIPT").unwrap_or("escript".to_string());
let escript = env::var("ESCRIPT").unwrap_or_else(|_| "escript".to_string());

if let Ok(res) = Command::new(escript)
.arg("gen_api.erl")
Expand Down
3 changes: 1 addition & 2 deletions rustler_sys/src/initmacro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ mod initmacro_namespace_tests {
// use rustler_sys_api::*;
use crate::rustler_sys_api;

use std;
use std::ffi::{CStr, CString};
use std::ptr;
use std::slice;
Expand Down Expand Up @@ -355,7 +354,7 @@ mod initmacro_namespace_tests {
#[cfg(test)]
mod initmacro_tests {
use crate::rustler_sys_api::*;
use std;

use std::ffi::{CStr, CString};
use std::ptr;
use std::slice;
Expand Down
2 changes: 2 additions & 0 deletions rustler_sys/src/rustler_sys_api.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::missing_safety_doc)]

#[cfg(windows)]
use unreachable::UncheckedOptionExt; // unchecked unwrap used in generated Windows code

Expand Down