From 928f0445534c07466db0e8bfdfefcab04078d108 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Tue, 24 Mar 2020 17:30:04 +0800 Subject: [PATCH] Fix lint warnings in examples --- examples/repl.rs | 8 ++++---- examples/rhai_runner.rs | 13 +++++-------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/examples/repl.rs b/examples/repl.rs index 91bfcfa0..39daf39c 100644 --- a/examples/repl.rs +++ b/examples/repl.rs @@ -13,7 +13,7 @@ fn print_error(input: &str, err: EvalAltResult) { iter::repeat(pad).take(len).collect::() } - let lines: Vec<_> = input.trim().split("\n").collect(); + let lines: Vec<_> = input.trim().split('\n').collect(); let line_no = if lines.len() > 1 { match err.position() { @@ -161,7 +161,7 @@ fn main() { #[cfg(not(feature = "no_optimize"))] { 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); } @@ -178,9 +178,9 @@ fn main() { }) }) { - println!(""); + println!(); print_error(&input, err); - println!(""); + println!(); } } } diff --git a/examples/rhai_runner.rs b/examples/rhai_runner.rs index 2b9b2077..b26b4aa1 100644 --- a/examples/rhai_runner.rs +++ b/examples/rhai_runner.rs @@ -10,7 +10,7 @@ fn padding(pad: &str, len: usize) -> String { } 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 pos_text = format!(" (line {}, position {})", line, pos); @@ -23,7 +23,7 @@ fn eprint_error(input: &str, err: EvalAltResult) { eprintln!(""); } - let lines: Vec<_> = input.split("\n").collect(); + let lines: Vec<_> = input.split('\n').collect(); // Print error match err.position() { @@ -72,12 +72,9 @@ fn main() { let mut contents = String::new(); - match f.read_to_string(&mut contents) { - Err(err) => { - eprintln!("Error reading script file: {}\n{}", filename, err); - exit(1); - } - _ => (), + if let Err(err) = f.read_to_string(&mut contents) { + eprintln!("Error reading script file: {}\n{}", filename, err); + exit(1); } if let Err(err) = engine.consume(false, &contents) {