Clean up clippy.

This commit is contained in:
Stephen Chung
2022-07-27 16:04:24 +08:00
parent 21f822020f
commit 39dee556c4
36 changed files with 271 additions and 369 deletions

View File

@@ -29,7 +29,7 @@ fn print_source(lines: &[String], pos: Position, offset: usize, window: (usize,
println!("{0:>1$}", "^", pos + offset + line_no_len + 2);
}
} else {
for n in start..=end {
for (n, s) in lines.iter().enumerate().take(end + 1).skip(start) {
let marker = if n == line { "> " } else { " " };
println!(
@@ -38,7 +38,7 @@ fn print_source(lines: &[String], pos: Position, offset: usize, window: (usize,
marker,
n + 1,
line_no_len,
lines[n],
s,
if n == line { "\x1b[39m" } else { "" },
);
@@ -161,7 +161,7 @@ fn print_debug_help() {
// Load script to debug.
fn load_script(engine: &Engine) -> (rhai::AST, String) {
if let Some(filename) = env::args().skip(1).next() {
if let Some(filename) = env::args().nth(1) {
let mut contents = String::new();
let filename = match Path::new(&filename).canonicalize() {
@@ -301,12 +301,7 @@ fn debug_callback(
match stdin().read_line(&mut input) {
Ok(0) => break Ok(DebuggerCommand::Continue),
Ok(_) => match input
.trim()
.split_whitespace()
.collect::<Vec<_>>()
.as_slice()
{
Ok(_) => match input.split_whitespace().collect::<Vec<_>>().as_slice() {
["help" | "h"] => print_debug_help(),
["exit" | "quit" | "q" | "kill", ..] => {
println!("Script terminated. Bye!");
@@ -328,14 +323,14 @@ fn debug_callback(
["source"] => {
println!("{}", context.global_runtime_state().source().unwrap_or(""))
}
["list" | "l"] => print_current_source(&mut context, source, pos, &lines, (3, 6)),
["list" | "l"] => print_current_source(&mut context, source, pos, lines, (3, 6)),
["list" | "l", n] if n.parse::<usize>().is_ok() => {
let num = n.parse::<usize>().unwrap();
if num <= 0 || num > lines.len() {
if num == 0 || num > lines.len() {
eprintln!("\x1b[31mInvalid line: {}\x1b[39m", num);
} else {
let pos = Position::new(num as u16, 0);
print_current_source(&mut context, source, pos, &lines, (3, 6));
print_current_source(&mut context, source, pos, lines, (3, 6));
}
}
["continue" | "c"] => break Ok(DebuggerCommand::Continue),
@@ -405,7 +400,7 @@ fn debug_callback(
rhai::debugger::BreakPoint::AtPosition { pos, .. } => {
let line_num = format!("[{}] line ", i + 1);
print!("{}", line_num);
print_source(&lines, *pos, line_num.len(), (0, 0));
print_source(lines, *pos, line_num.len(), (0, 0));
}
_ => println!("[{}] {}", i + 1, bp),
},
@@ -580,7 +575,7 @@ fn debug_callback(
break Err(EvalAltResult::ErrorRuntime(value, pos).into());
}
["throw", ..] => {
let msg = input.trim().splitn(2, ' ').skip(1).next().unwrap_or("");
let msg = input.trim().split_once(' ').map(|(_, x)| x).unwrap_or("");
break Err(EvalAltResult::ErrorRuntime(msg.trim().into(), pos).into());
}
["run" | "r"] => {

View File

@@ -158,7 +158,7 @@ fn load_script_files(engine: &mut Engine) {
.map_err(|err| err.into())
.and_then(|mut ast| {
ast.set_source(filename.to_string_lossy().to_string());
Module::eval_ast_as_new(Scope::new(), &ast, &engine)
Module::eval_ast_as_new(Scope::new(), &ast, engine)
}) {
Err(err) => {
let filename = filename.to_string_lossy();
@@ -166,7 +166,7 @@ fn load_script_files(engine: &mut Engine) {
eprintln!("{:=<1$}", "", filename.len());
eprintln!("{}", filename);
eprintln!("{:=<1$}", "", filename.len());
eprintln!("");
eprintln!();
print_error(&contents, *err);
exit(1);
@@ -353,7 +353,7 @@ fn main() {
match rl.readline(prompt) {
// Line continuation
Ok(mut line) if line.ends_with("\\") => {
Ok(mut line) if line.ends_with('\\') => {
line.pop();
input += &line;
input.push('\n');
@@ -361,10 +361,12 @@ fn main() {
Ok(line) => {
input += &line;
let cmd = input.trim();
if !cmd.is_empty() && !cmd.starts_with('!') && cmd.trim() != "history" {
if rl.add_history_entry(input.clone()) {
history_offset += 1;
}
if !cmd.is_empty()
&& !cmd.starts_with('!')
&& cmd.trim() != "history"
&& rl.add_history_entry(input.clone())
{
history_offset += 1;
}
break;
}

View File

@@ -14,7 +14,7 @@ fn eprint_error(input: &str, mut err: EvalAltResult) {
line_no.len() + pos.position().unwrap(),
err_msg
);
eprintln!("");
eprintln!();
}
let lines: Vec<_> = input.split('\n').collect();
@@ -96,7 +96,7 @@ fn main() {
eprintln!("{:=<1$}", "", filename.len());
eprintln!("{}", filename);
eprintln!("{:=<1$}", "", filename.len());
eprintln!("");
eprintln!();
eprint_error(contents, *err);
}