Fix lint warnings in examples

This commit is contained in:
Stephen Chung 2020-03-24 17:30:04 +08:00
parent d21f66b911
commit 928f044553
2 changed files with 9 additions and 12 deletions

View File

@ -13,7 +13,7 @@ fn print_error(input: &str, err: EvalAltResult) {
iter::repeat(pad).take(len).collect::<String>() iter::repeat(pad).take(len).collect::<String>()
} }
let lines: Vec<_> = input.trim().split("\n").collect(); let lines: Vec<_> = input.trim().split('\n').collect();
let line_no = if lines.len() > 1 { let line_no = if lines.len() > 1 {
match err.position() { match err.position() {
@ -161,7 +161,7 @@ fn main() {
#[cfg(not(feature = "no_optimize"))] #[cfg(not(feature = "no_optimize"))]
{ {
engine.set_optimization_level(OptimizationLevel::Full); engine.set_optimization_level(OptimizationLevel::Full);
ast = Some(engine.optimize_ast(&mut scope, ast_u.as_ref().unwrap())); ast = Some(engine.optimize_ast(&scope, ast_u.as_ref().unwrap()));
engine.set_optimization_level(OptimizationLevel::None); engine.set_optimization_level(OptimizationLevel::None);
} }
@ -178,9 +178,9 @@ fn main() {
}) })
}) })
{ {
println!(""); println!();
print_error(&input, err); print_error(&input, err);
println!(""); println!();
} }
} }
} }

View File

@ -10,7 +10,7 @@ fn padding(pad: &str, len: usize) -> String {
} }
fn eprint_error(input: &str, err: EvalAltResult) { fn eprint_error(input: &str, err: EvalAltResult) {
fn eprint_line(lines: &Vec<&str>, line: usize, pos: usize, err: &str) { fn eprint_line(lines: &[&str], line: usize, pos: usize, err: &str) {
let line_no = format!("{}: ", line); let line_no = format!("{}: ", line);
let pos_text = format!(" (line {}, position {})", line, pos); let pos_text = format!(" (line {}, position {})", line, pos);
@ -23,7 +23,7 @@ fn eprint_error(input: &str, err: EvalAltResult) {
eprintln!(""); eprintln!("");
} }
let lines: Vec<_> = input.split("\n").collect(); let lines: Vec<_> = input.split('\n').collect();
// Print error // Print error
match err.position() { match err.position() {
@ -72,13 +72,10 @@ fn main() {
let mut contents = String::new(); let mut contents = String::new();
match f.read_to_string(&mut contents) { if let Err(err) = f.read_to_string(&mut contents) {
Err(err) => {
eprintln!("Error reading script file: {}\n{}", filename, err); eprintln!("Error reading script file: {}\n{}", filename, err);
exit(1); exit(1);
} }
_ => (),
}
if let Err(err) = engine.consume(false, &contents) { if let Err(err) = engine.consume(false, &contents) {
eprintln!("{}", padding("=", filename.len())); eprintln!("{}", padding("=", filename.len()));