Skip to content

Commit a1ef7ee

Browse files
committed
Fix basic compiler warnings
1 parent 4c4ed5f commit a1ef7ee

File tree

9 files changed

+104
-96
lines changed

9 files changed

+104
-96
lines changed

src/clojure_std/thread.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use crate::value::{ToValue, Value};
2-
use std::rc::Rc;
3-
use crate::ifn::IFn;
4-
use std::io::Read;
5-
use std::error::Error;
61
use crate::error_message;
7-
use nom::lib::std::convert::TryFrom;
2+
use crate::ifn::IFn;
83
use crate::type_tag::TypeTag;
4+
use crate::value::{ToValue, Value};
5+
use nom::lib::std::convert::TryFrom;
6+
use std::error::Error;
7+
use std::io::Read;
8+
use std::rc::Rc;
99

1010
use std::thread;
1111
use std::time;
@@ -25,14 +25,14 @@ impl IFn for SleepFn {
2525
let arg = &**args.get(0).unwrap();
2626
match arg {
2727
Value::I32(i) => {
28-
std::thread::sleep(time::Duration::new(0, (*i as u32) * 1000000));
29-
return Value::Nil
30-
},
31-
_ => error_message::type_mismatch(TypeTag::I32, args.get(0).unwrap())
28+
std::thread::sleep(time::Duration::new(0, (*i as u32) * 100_0000));
29+
Value::Nil
30+
}
31+
_ => error_message::type_mismatch(TypeTag::I32, args.get(0).unwrap()),
3232
}
3333
} else {
3434
error_message::wrong_arg_count(1, args.len());
35-
return Value::Nil
35+
Value::Nil
3636
}
3737
}
38-
}
38+
}

src/clojure_std/time.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use crate::value::{ToValue, Value};
2-
use std::rc::Rc;
3-
use crate::ifn::IFn;
4-
use std::io::Read;
5-
use std::error::Error;
61
use crate::error_message;
7-
use nom::lib::std::convert::TryFrom;
2+
use crate::ifn::IFn;
83
use crate::type_tag::TypeTag;
4+
use crate::value::{ToValue, Value};
5+
use nom::lib::std::convert::TryFrom;
6+
use std::error::Error;
7+
use std::io::Read;
8+
use std::rc::Rc;
99

1010
use std::thread;
1111
use std::time::{SystemTime, UNIX_EPOCH};
@@ -21,12 +21,15 @@ impl ToValue for NanoTimeFn {
2121

2222
impl IFn for NanoTimeFn {
2323
fn invoke(&self, args: Vec<Rc<Value>>) -> Value {
24-
if args.len() == 0 {
25-
let ns = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_nanos();
26-
return Value::F64(ns as f64)
24+
if args.is_empty() {
25+
let ns = SystemTime::now()
26+
.duration_since(UNIX_EPOCH)
27+
.unwrap()
28+
.as_nanos();
29+
Value::F64(ns as f64)
2730
} else {
2831
error_message::wrong_arg_count(0, args.len());
29-
return Value::Nil
32+
Value::Nil
3033
}
3134
}
32-
}
35+
}

src/error_message.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
11
use crate::type_tag::TypeTag;
22
use crate::value::Value;
3-
use nom::Err;
43
use nom::error::ErrorKind;
4+
use nom::Err;
55
use std::error::Error;
66

77
pub fn type_mismatch(expected: TypeTag, got: &Value) -> Value {
88
Value::Condition(format!(
99
"Type mismatch; Expected instance of {}, Recieved type {}",
10-
expected,
11-
got
10+
expected, got
1211
))
1312
}
1413

1514
pub fn wrong_arg_count(expected: usize, got: usize) -> Value {
1615
Value::Condition(format!(
1716
"Wrong number of arguments given to function (Given: {}, Expected: {})",
18-
got,
19-
expected
17+
got, expected
2018
))
2119
}
2220

2321
pub fn wrong_varg_count(expected: &[usize], got: usize) -> Value {
2422
Value::Condition(format!(
2523
"Wrong number of arguments given to function (Given: {}, Expected: {:?})",
26-
got,
27-
expected
24+
got, expected
2825
))
2926
}
3027

3128
pub fn zero_arg_count(got: usize) -> Value {
3229
Value::Condition(format!(
33-
"Wrong number of arguments given to function (Given: {})", got))
30+
"Wrong number of arguments given to function (Given: {})",
31+
got
32+
))
3433
}
3534

3635
pub fn index_out_of_bounds(ind: usize, count: usize) -> Value {
@@ -44,6 +43,6 @@ pub fn index_cannot_be_negative(ind: usize) -> Value {
4443
Value::Condition(format!("Index cannot be negative; Index ({})", ind))
4544
}
4645

47-
pub fn generic_err(error: Box<Error>) -> Value {
48-
Value::Condition(format!("{}", error.to_string()))
49-
}
46+
pub fn generic_err(error: Box<dyn Error>) -> Value {
47+
Value::Condition(error.to_string())
48+
}

src/persistent_list_map.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ mod tests {
176176

177177
#[test]
178178
fn test_persistent_list_map() {
179-
let empty = PersistentListMap::Empty;
180179
let map1 = vec![
181180
MapEntry {
182181
key: Symbol::intern("a").to_rc_value(),

src/reader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ pub fn read<R: BufRead>(reader: &mut R) -> Value {
471471
match maybe_line {
472472
Some(Err(e)) => return Value::Condition(format!("Reader error: {}", e)),
473473
Some(Ok(line)) => input_buffer.push_str(&line),
474-
None => return Value::Condition(format!("Tried to read empty stream; unexpected EOF")),
474+
None => return Value::Condition(String::from("Tried to read empty stream; unexpected EOF")),
475475
}
476476

477477
let line_read = try_read(&input_buffer);

src/repl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl Repl {
3939
let _ = io::stdout().flush();
4040

4141
// Read
42-
let mut next = Repl::read(&mut stdin_reader);
42+
let next = Repl::read(&mut stdin_reader);
4343
// Eval
4444
let evaled_next = self.eval(&next);
4545
// Print

src/rust_core/_divide_.rs

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::ifn::IFn;
2-
use crate::value::{Value, ToValue};
2+
use crate::value::{ToValue, Value};
33
use std::rc::Rc;
44

55
use crate::error_message;
@@ -16,41 +16,45 @@ impl ToValue for DivideFn {
1616
impl IFn for DivideFn {
1717
fn invoke(&self, args: Vec<Rc<Value>>) -> Value {
1818
match args.len() {
19-
0 => { error_message::zero_arg_count(args.len()) },
19+
0 => error_message::zero_arg_count(args.len()),
2020
1 => {
2121
let val = args.get(0).unwrap().to_value();
2222
match val {
2323
Value::I32(a_) => Value::F64(1.0 / a_ as f64),
2424
Value::F64(f_) => Value::F64(1.0 / f_),
25-
_ => Value::Condition(format!( // TODO: what error message should be returned regarding using typetags?
26-
"Type mismatch; Expecting: (i32 | i64 | f32 | f64), Found: {}",
27-
val.type_tag()
28-
))
25+
_ => Value::Condition(format!(
26+
// TODO: what error message should be returned regarding using typetags?
27+
"Type mismatch; Expecting: (i32 | i64 | f32 | f64), Found: {}",
28+
val.type_tag()
29+
)),
2930
}
30-
},
31+
}
3132
_ => {
3233
let mut args_iterator = args.into_iter();
3334
let first_arg = args_iterator.next().unwrap();
3435
args_iterator.fold(first_arg.to_value(), |a, b| match a {
3536
Value::I32(a_) => match *b {
3637
Value::I32(b_) => Value::I32(a_ / b_),
3738
Value::F64(b_) => Value::F64(a_ as f64 / b_),
38-
_ => Value::Condition(format!( // TODO: what error message should be returned regarding using typetags?
39-
"Type mismatch; Expecting: (i32 | i64 | f32 | f64), Found: {}",
40-
b.type_tag()
39+
_ => Value::Condition(format!(
40+
// TODO: what error message should be returned regarding using typetags?
41+
"Type mismatch; Expecting: (i32 | i64 | f32 | f64), Found: {}",
42+
b.type_tag()
4143
)),
4244
},
4345
Value::F64(a_) => match *b {
4446
Value::I32(b_) => Value::F64(a_ / b_ as f64),
4547
Value::F64(b_) => Value::F64(a_ / b_),
46-
_ => Value::Condition(format!( // TODO: what error message should be returned regarding using typetags?
47-
"Type mismatch; Expecting: (i32 | i64 | f32 | f64), Found: {}",
48-
b.type_tag()
48+
_ => Value::Condition(format!(
49+
// TODO: what error message should be returned regarding using typetags?
50+
"Type mismatch; Expecting: (i32 | i64 | f32 | f64), Found: {}",
51+
b.type_tag()
4952
)),
5053
},
51-
_ => Value::Condition(format!( // TODO: what error message should be returned regarding using typetags?
52-
"Type mismatch: Expecting: (i32 | i64 | f32 | f64), Found: {}",
53-
a.type_tag()
54+
_ => Value::Condition(format!(
55+
// TODO: what error message should be returned regarding using typetags?
56+
"Type mismatch: Expecting: (i32 | i64 | f32 | f64), Found: {}",
57+
a.type_tag()
5458
)),
5559
})
5660
}
@@ -60,68 +64,73 @@ impl IFn for DivideFn {
6064

6165
#[cfg(test)]
6266
mod tests {
63-
mod Divide_tests {
64-
use crate::rust_core::_divide_::DivideFn;
67+
mod divide_tests {
6568
use crate::ifn::IFn;
69+
use crate::rust_core::_divide_::DivideFn;
6670
use crate::value::Value;
6771
use std::rc::Rc;
6872

6973
#[test]
70-
fn Divide_without_arguments_returns_one() {
71-
let Divide = DivideFn {};
74+
fn divide_without_arguments_returns_one() {
75+
let divide = DivideFn {};
7276
let args = vec![];
73-
assert_eq!(Value::Condition(String::from("Wrong number of arguments given to function (Given: 0)")),
74-
Divide.invoke(args));
77+
assert_eq!(
78+
Value::Condition(String::from(
79+
"Wrong number of arguments given to function (Given: 0)"
80+
)),
81+
divide.invoke(args)
82+
);
7583
}
7684

7785
#[test]
78-
fn Divide_with_one_positive_argument_returns_reciprocal() {
86+
fn divide_with_one_positive_argument_returns_reciprocal() {
7987
let divide = DivideFn {};
8088
let args = vec![Rc::new(Value::I32(5))];
81-
assert_eq!(Value::F64(1.0/5.0), divide.invoke(args));
89+
assert_eq!(Value::F64(1.0 / 5.0), divide.invoke(args));
8290
}
8391

8492
#[test]
85-
fn Divide_with_one_negative_argument_returns_reciprocal() {
93+
fn divide_with_one_negative_argument_returns_reciprocal() {
8694
let divide = DivideFn {};
8795
let args = vec![Rc::new(Value::I32(-5))];
8896
assert_eq!(Value::F64(1.0 / -5.0), divide.invoke(args));
8997
}
9098

9199
#[test]
92-
fn Divide_with_two_integer_argument_returns_quotient() {
100+
fn divide_with_two_integer_argument_returns_quotient() {
93101
let divide = DivideFn {};
94102
let args = vec![Rc::new(Value::I32(24)), Rc::new(Value::I32(6))];
95103
assert_eq!(Value::I32(4), divide.invoke(args));
96104
}
97105

98106
#[test]
99-
fn Divide_with_one_double_argument_returns_quotient() {
107+
fn divide_with_one_double_argument_returns_quotient() {
100108
let divide = DivideFn {};
101109
let args = vec![Rc::new(Value::I32(24)), Rc::new(Value::F64(1.5))];
102110
assert_eq!(Value::F64(16.0), divide.invoke(args));
103111
}
104112

105113
#[test]
106-
fn Divide_with_multiple_integer_arguments_returns_quotient() {
107-
let Divide = DivideFn {};
114+
fn divide_with_multiple_integer_arguments_returns_quotient() {
115+
let divide = DivideFn {};
108116
let args = vec![
109117
Rc::new(Value::I32(100)),
110118
Rc::new(Value::I32(5)),
111-
Rc::new(Value::I32(4))];
112-
assert_eq!(Value::I32(5), Divide.invoke(args));
119+
Rc::new(Value::I32(4)),
120+
];
121+
assert_eq!(Value::I32(5), divide.invoke(args));
113122
}
114123

115124
#[test]
116-
fn Divide_with_multiple_mixed_arguments_returns_quotient() {
117-
let Divide = DivideFn {};
125+
fn divide_with_multiple_mixed_arguments_returns_quotient() {
126+
let divide = DivideFn {};
118127
let args = vec![
119128
Rc::new(Value::I32(100)),
120129
Rc::new(Value::I32(5)),
121130
Rc::new(Value::I32(4)),
122-
Rc::new(Value::F64(2.0))];
123-
assert_eq!(Value::F64(2.5), Divide.invoke(args));
131+
Rc::new(Value::F64(2.0)),
132+
];
133+
assert_eq!(Value::F64(2.5), divide.invoke(args));
124134
}
125-
126135
}
127-
}
136+
}

src/rust_core/nth.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use crate::ifn::IFn;
2-
use crate::value::{Value, ToValue};
3-
use std::rc::Rc;
42
use crate::type_tag::TypeTag;
3+
use crate::value::{ToValue, Value};
4+
use std::rc::Rc;
55

66
use crate::error_message;
7-
use crate::persistent_list::PersistentList::Cons;
7+
use crate::persistent_list::PersistentList::{Cons, Empty};
88
use crate::persistent_list::ToPersistentListIter;
99
use crate::persistent_vector::PersistentVector;
1010

@@ -21,13 +21,13 @@ impl IFn for NthFn {
2121
fn invoke(&self, args: Vec<Rc<Value>>) -> Value {
2222
// @TODO generalize arity exceptions, and other exceptions
2323
if args.len() != 2 {
24-
return error_message::wrong_varg_count(&[2,3], args.len())
24+
return error_message::wrong_varg_count(&[2, 3], args.len());
2525
}
2626
// @TODO change iteration to work with Value references, or even change invoke to work on Rc<..>
2727
// as we do everything else; surely we don't want to clone just to read from a collection
2828
if let Value::I32(ind) = **args.get(1).unwrap() {
2929
if ind < 0 {
30-
return error_message::index_cannot_be_negative(ind as usize)
30+
return error_message::index_cannot_be_negative(ind as usize);
3131
}
3232
let ind = ind as usize;
3333

@@ -56,4 +56,4 @@ impl IFn for NthFn {
5656
error_message::type_mismatch(TypeTag::Integer, &**args.get(1).unwrap())
5757
}
5858
}
59-
}
59+
}

0 commit comments

Comments
 (0)