Skip to content

Commit

Permalink
Some clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
kvakvs committed Dec 17, 2017
1 parent 39bf64e commit 1bec595
Show file tree
Hide file tree
Showing 31 changed files with 63 additions and 75 deletions.
2 changes: 1 addition & 1 deletion codegen/create_gen_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def main():
#

# print("#[cfg(debug)]")
print("""const OPCODE_NAME_MAP: &'static [&'static str] = &[
print("""const OPCODE_NAME_MAP: &[&str] = &[
\"\", // opcode 0 does not exist""")
for opcode in range(conf.min_opcode, conf.max_opcode + 1):
op = tables.ops[opcode]
Expand Down
2 changes: 1 addition & 1 deletion src/beam/compact_term.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Module implements decoder for compact term format used in BEAM files.
//! http://beam-wisdoms.clau.se/en/latest/indepth-beam-file.html#beam-compact-term-encoding
//! <http://beam-wisdoms.clau.se/en/latest/indepth-beam-file.html#beam-compact-term-encoding>

use rt_defs::{Word, SWord};
use fail::{Hopefully, Error};
Expand Down
2 changes: 1 addition & 1 deletion src/beam/gen_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ pub fn opcode_arity(opcode: RawOpcode) -> u8 {
ARITY_MAP[opcode as usize]
}

const OPCODE_NAME_MAP: &'static [&'static str] = &[
const OPCODE_NAME_MAP: &[&str] = &[
"", // opcode 0 does not exist
"label", // opcode: 1
"func_info", // opcode: 2
Expand Down
2 changes: 1 addition & 1 deletion src/beam/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl Loader {
/// account special value 0 and offsets the index down by 1.
fn from_loadtime_atom_index(&self, n: u32) -> LTerm {
if n == 0 { return nil() }
return self.vm_atoms[n as usize - 1];
self.vm_atoms[n as usize - 1]
}


Expand Down
6 changes: 3 additions & 3 deletions src/beam/opcodes/op_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,21 @@ fn shared_call_ext(ctx: &mut Context,
if (*import).is_bif {
// Perform a BIF application
//
return call_bif(ctx, curr_p, arity, true)
call_bif(ctx, curr_p, arity, true)
} else {
// Perform a regular call to BEAM code, save CP and jump
//
if save_cp {
ctx.cp = ctx.ip; // Points at the next opcode after this
}
ctx.ip = (*import).resolve().unwrap();
return DispatchResult::Normal
DispatchResult::Normal
}
},
Err(_err) => {
// Create a `{badfun, _}` error
let badfun = make_badfun(imp0, &mut curr_p.heap);
return DispatchResult::Error(ExceptionType::Error, badfun)
DispatchResult::Error(ExceptionType::Error, badfun)
}
}
}
Expand Down
16 changes: 6 additions & 10 deletions src/beam/opcodes/op_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ pub fn opcode_is_nonempty_list(ctx: &mut Context,

let list = ctx.fetch_and_load(&curr_p.heap);

if list.is_nil() && !list.is_cons() {
if !fail.is_nil() {
// jump to fail label
ctx.ip = CodePtr::from_cp(fail)
}
if list.is_nil() && !list.is_cons() && !fail.is_nil() {
// jump to fail label
ctx.ip = CodePtr::from_cp(fail)
}

DispatchResult::Normal
Expand All @@ -50,11 +48,9 @@ pub fn opcode_is_nil(ctx: &mut Context,

let list = ctx.fetch_and_load(&curr_p.heap);

if !list.is_nil() {
if !fail.is_nil() {
// jump to fail label
ctx.ip = CodePtr::from_cp(fail)
}
if !list.is_nil() && !fail.is_nil() {
// jump to fail label
ctx.ip = CodePtr::from_cp(fail)
}

DispatchResult::Normal
Expand Down
6 changes: 2 additions & 4 deletions src/beam/opcodes/op_predicates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,9 @@ fn shared_equality_opcode(ctx: &mut Context,
if compare::cmp_terms(a, b, exact) == desired_result {
ctx.ip = CodePtr::from_cp(fail_label)
}
} else {
} else if compare::cmp_terms(a, b, exact) != desired_result {
// Other than desired_recult will cause jump to 'fail'
if compare::cmp_terms(a, b, exact) != desired_result {
ctx.ip = CodePtr::from_cp(fail_label)
}
ctx.ip = CodePtr::from_cp(fail_label)
}

DispatchResult::Normal
Expand Down
4 changes: 2 additions & 2 deletions src/bif/bif_arith.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn ubif_sminus_2_2(cur_proc: &mut Process,
let b: LTerm = args[1];
if a.is_small() {
if b.is_small() {
return subtract_two_small(cur_proc, a, b)
subtract_two_small(cur_proc, a, b)
} else {
panic!("{}subtract: b={} other than small notimpl", module(), b)
}
Expand All @@ -36,7 +36,7 @@ pub fn ubif_splus_2_2(cur_proc: &mut Process,
let b: LTerm = args[1];
if a.is_small() {
if b.is_small() {
return add_two_small(cur_proc, a, b)
add_two_small(cur_proc, a, b)
} else {
panic!("{}subtract: b={} other than small notimpl", module(), b)
}
Expand Down
2 changes: 1 addition & 1 deletion src/emulator/code_srv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl CodeServer {
}
// nope, keep searching
}
return None
None
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/emulator/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Module {
code: Vec::new(),
funs: BTreeMap::new(),
lit_heap: Heap::new(1),
mod_id: mod_id.clone(),
mod_id,
lambdas: Vec::new(),
}
))
Expand Down
8 changes: 4 additions & 4 deletions src/term/classify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ unsafe fn classify_header(v: Word, p: *const Word) -> TermClass {
let h_tag = primary::header::get_tag(v);
match h_tag {
primary::header::TAG_HEADER_TUPLE => TermClass::Tuple,
primary::header::TAG_HEADER_REF => TermClass::Ref,
primary::header::TAG_HEADER_REF |
primary::header::TAG_HEADER_EXTREF => TermClass::Ref,
primary::header::TAG_HEADER_FUN => TermClass::Fun,
primary::header::TAG_HEADER_FLOAT => TermClass::Number,
primary::header::TAG_HEADER_HEAPOBJ => {
Expand All @@ -87,7 +88,6 @@ unsafe fn classify_header(v: Word, p: *const Word) -> TermClass {
},
primary::header::TAG_HEADER_EXTPID => TermClass::Pid,
primary::header::TAG_HEADER_EXTPORT => TermClass::Port,
primary::header::TAG_HEADER_EXTREF => TermClass::Ref,
_ => panic!("classify: Unexpected header tag {} value {}",
h_tag, primary::get_value(v))
}
Expand All @@ -104,7 +104,8 @@ fn classify_immed(v: Word, t: LTerm) -> TermClass {
immediate::TAG_IMM1_PORT => TermClass::Port,
immediate::TAG_IMM1_IMM2 => {
match immediate::get_imm2_tag(v) {
immediate::TAG_IMM2_CATCH => TermClass::Special_,
immediate::TAG_IMM2_CATCH |
immediate::TAG_IMM2_IMM3 => TermClass::Special_,
immediate::TAG_IMM2_SPECIAL => {
if t.is_nil() {
TermClass::Nil
Expand All @@ -117,7 +118,6 @@ fn classify_immed(v: Word, t: LTerm) -> TermClass {
}
},
immediate::TAG_IMM2_ATOM => TermClass::Atom,
immediate::TAG_IMM2_IMM3 => TermClass::Special_,
_ => panic!("{}Invalid primary tag", module())
} // end match imm2
},
Expand Down
12 changes: 6 additions & 6 deletions src/term/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ fn cmp_numbers_not_exact(_a: LTerm, _b: LTerm) -> Ordering {
fn cmp_atoms(a: LTerm, b: LTerm) -> Ordering {
assert!(!a.is_nil());
let atomp_a = atom::lookup(a);
debug_assert!(atomp_a.is_null() == false,
debug_assert!(!atomp_a.is_null(),
"cmp_atoms: atom lookup {} failed", a);

assert!(!b.is_nil());
let atomp_b = atom::lookup(b);
debug_assert!(atomp_b.is_null() == false,
debug_assert!(!atomp_b.is_null(),
"cmp_atoms: atom lookup {} failed", b);

// This should really be safe, as pointers to Atom exist statically forever
Expand Down Expand Up @@ -166,13 +166,13 @@ fn cmp_terms_primary(a: LTerm, b: LTerm, exact: bool) -> EqResult {

match a_prim_tag {
primary::TAG_IMMED => {
return EqResult::Concluded(cmp_terms_immed(a, b, exact))
EqResult::Concluded(cmp_terms_immed(a, b, exact))
},
primary::TAG_CONS => unsafe {
return cmp_cons(a, b)
cmp_cons(a, b)
},
primary::TAG_BOX => {
return cmp_terms_box(a, b)
cmp_terms_box(a, b)
},
_ => panic!("Primary tag {} eq_terms unsupported", a_prim_tag)
}
Expand Down Expand Up @@ -371,7 +371,7 @@ unsafe fn cmp_cons(a: LTerm, b: LTerm) -> EqResult {
let ahd = aa.hd();
let bhd = bb.hd();

if LTerm::is_same(ahd, bhd) == false {
if !LTerm::is_same(ahd, bhd) {
//println!("cmp_cons ahd {} bhd {}", ahd, bhd);
// Recurse into a.hd and b.hd, but push a.tl and b.tl to continue
let continue_op = ContinueCompare::Cons(aa.tl(), bb.tl());
Expand Down
2 changes: 1 addition & 1 deletion src/term/integral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use num::ToPrimitive;


/// A type-safe way to represent an Erlang integer, which can be either small
/// enough to fit into a word, or a large one, stored as a BigInt. There is no
/// enough to fit into a word, or a large one, stored as a `BigInt`. There is no
/// way (and was no need) to represent a small signed integer.
#[derive(Debug, Eq, PartialEq)]
pub enum Integral {
Expand Down
4 changes: 2 additions & 2 deletions src/term/lterm/aspect_atom.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Functions to manipulate an LTerm as an Erlang atom. Part of LTerm impl.
//! Functions to manipulate an `LTerm` as an Erlang atom. Part of `LTerm` impl.

use rt_defs::Word;
use term::immediate;
Expand Down Expand Up @@ -27,7 +27,7 @@ impl AtomAspect for super::LTerm {
}


/// From atom index create an atom. To create from string use vm::new_atom
/// From atom index create an atom. To create from string use `vm::new_atom`
#[inline]
pub fn make_atom(index: Word) -> super::LTerm {
super::LTerm { value: immediate::make_atom_raw(index) }
Expand Down
4 changes: 2 additions & 2 deletions src/term/lterm/aspect_bignum.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Functions to manipulate an LTerm as an boxed pointer to an Erlang Bignum.
//! Part of LTerm impl.
//! Functions to manipulate an `LTerm` as an boxed pointer to an Erlang Bignum.
//! Part of `LTerm` impl.

//use rt_defs::Word;
//use term::immediate;
Expand Down
4 changes: 1 addition & 3 deletions src/term/lterm/aspect_binary.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use term::immediate;
//use term::primary;
//use rt_defs::Word;
use term::lterm::aspect_boxed::BoxedAspect;
use term::raw::ho_binary::HOBinary;


/// Implements features of LTerm related to binary values.
/// Implements features of `LTerm` related to binary values.
pub trait BinaryAspect {
unsafe fn is_binary(&self) -> bool;
fn is_empty_binary(&self) -> bool;
Expand Down
4 changes: 2 additions & 2 deletions src/term/lterm/aspect_boxed.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Functions to manipulate an LTerm as a boxed value on a process heap.
//! Part of LTerm impl.
//! Functions to manipulate an `LTerm` as a boxed value on a process heap.
//! Part of `LTerm` impl.

use rt_defs::Word;
use term::primary;
Expand Down
2 changes: 1 addition & 1 deletion src/term/lterm/aspect_cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use term::primary;
use term::lterm::aspect_boxed::{BoxedAspect, make_box};


/// Represents operations on LTerm which contains/is a CP value.
/// Represents operations on `LTerm` which contains/is a CP value.
pub trait CpAspect {
fn is_cp(&self) -> bool;
fn cp_get_ptr(&self) -> *const Word;
Expand Down
4 changes: 2 additions & 2 deletions src/term/lterm/aspect_export.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Functions to manipulate an LTerm as an boxed pointer to an Erlang Export.
//! Part of LTerm impl.
//! Functions to manipulate an `LTerm` as an boxed pointer to an Erlang Export.
//! Part of `LTerm` impl.

//use rt_defs::Word;
//use term::immediate;
Expand Down
3 changes: 1 addition & 2 deletions src/term/lterm/aspect_float.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Functions to manipulate an LTerm as a float. Part of LTerm impl.
//! Functions to manipulate an `LTerm` as a float. Part of `LTerm` impl.

use rt_defs::Float;
//use term::immediate;
use term::primary;
use term::lterm::aspect_boxed::BoxedAspect;

Expand Down
7 changes: 2 additions & 5 deletions src/term/lterm/aspect_fun.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
//! Functions to manipulate an LTerm as an boxed pointer to an Erlang Fun.
//! Part of LTerm impl.

//use rt_defs::Word;
//use term::immediate;
//! Functions to manipulate an `LTerm` as an boxed pointer to an Erlang Fun.
//! Part of `LTerm` impl.


pub trait FunAspect {
Expand Down
6 changes: 3 additions & 3 deletions src/term/lterm/aspect_list.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Functions to manipulate an LTerm as an Erlang CONS cell (two words on heap,
//! which contain a head and a tail). Part of LTerm impl.
//! Functions to manipulate an `LTerm` as an Erlang list cell (two words on
//! heap, which contain a head and a tail). Part of `LTerm` impl.

use rt_defs::Word;
use term::immediate;
Expand All @@ -13,7 +13,7 @@ use std::ptr;
fn module() -> &'static str { "lterm/cons_term: " }


/// Represents cons/list/NIL aspects of an LTerm.
/// Represents cons/list/NIL aspects of an `LTerm`.
pub trait ListAspect {
/// Check whether primary tag of a value is `TAG_CONS`.
fn is_cons(&self) -> bool;
Expand Down
4 changes: 2 additions & 2 deletions src/term/lterm/aspect_map.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Functions to manipulate an LTerm as an boxed pointer to an Erlang Map.
//! Part of LTerm impl.
//! Functions to manipulate an `LTerm` as an boxed pointer to an Erlang Map.
//! Part of `LTerm` impl.

//use rt_defs::Word;
//use term::immediate;
Expand Down
4 changes: 2 additions & 2 deletions src/term/lterm/aspect_pid.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Functions to manipulate an LTerm as an Erlang Pid (immediate or a box)
//! either local or external. Part of LTerm impl.
//! Functions to manipulate an `LTerm` as an Erlang Pid (immediate or a box)
//! either local or external. Part of `LTerm` impl.

//use rt_defs::Word;
use term::immediate;
Expand Down
4 changes: 2 additions & 2 deletions src/term/lterm/aspect_port.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Functions to manipulate an LTerm as an boxed pointer to an Erlang Port
//! either local or external. Part of LTerm impl.
//! Functions to manipulate an `LTerm` as an boxed pointer to an Erlang Port
//! either local or external. Part of `LTerm` impl.

//use rt_defs::Word;
//use term::immediate;
Expand Down
4 changes: 2 additions & 2 deletions src/term/lterm/aspect_reference.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Functions to manipulate an LTerm as an boxed pointer to an Erlang Reference
//! either local or external. Part of LTerm impl.
//! Functions to manipulate an `LTerm` as an boxed pointer to an Erlang
//! Reference either local or external. Part of `LTerm` impl.

//use rt_defs::Word;
//use term::immediate;
Expand Down
6 changes: 3 additions & 3 deletions src/term/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//!
//! Term package implements two types of Erlang values:
//!
//! * FTerm (or Friendly Term) - a typesafe Rust enum which represents most of
//! * `FTerm` (or Friendly Term) - a typesafe Rust enum which represents most of
//! possible values for load-time processing.
//! * LTerm (or a low level Term) - a tagged term Word, which uses some bits to
//! define its type, and can store either just values or pointers to heap.
//! * `LTerm` (or a low level Term) - a tagged term Word, which uses some bits
//! to define its type, and can store either just values or pointers to heap
//!
//! As well as operations on terms, such as arithmetic or comparisons.
//!
Expand Down
2 changes: 1 addition & 1 deletion src/term/raw/ho_bignum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl HOBignum {

ptr::write(this, HOBignum::new(n_words, value));

return Ok(this);
Ok(this)
}


Expand Down
2 changes: 1 addition & 1 deletion src/term/raw/ho_binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl HOBinary {
flavour: HOBinaryType::Heap,
});

return Ok(this)
Ok(this)
}


Expand Down
2 changes: 1 addition & 1 deletion src/term/raw/ho_closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl HOClosure {
ptr::write(this,
HOClosure::new(
HeapObjHeader::new(n_words, &HOCLASS_CLOSURE),
fe.mfa.clone(),
fe.mfa,
fe.nfree
));

Expand Down
Loading

0 comments on commit 1bec595

Please sign in to comment.