fix clippy. check pr: PASS

This commit is contained in:
Devyn Cairns 2024-07-08 21:10:41 -07:00
parent 0a399011e3
commit 1ce2096b72
12 changed files with 59 additions and 72 deletions

View File

@ -67,7 +67,7 @@ impl Command for OverlayUse {
let maybe_origin_module_id =
if let Some(overlay_expr) = call.get_parser_info(caller_stack, "overlay_expr") {
if let Expr::Overlay(module_id) = &overlay_expr.expr {
module_id.clone()
*module_id
} else {
return Err(ShellError::NushellFailedSpanned {
msg: "Not an overlay".to_string(),

View File

@ -45,14 +45,12 @@ impl Command for ViewIr {
// This helps display the actual compilation error
let ir_block = match &block.ir_block {
Some(ir_block) => Cow::Borrowed(ir_block),
None => Cow::Owned(
compile(&StateWorkingSet::new(engine_state), &block).map_err(|err| {
ShellError::IrCompileError {
span: block.span,
errors: vec![err],
}
})?,
),
None => Cow::Owned(compile(&StateWorkingSet::new(engine_state), block).map_err(
|err| ShellError::IrCompileError {
span: block.span,
errors: vec![err],
},
)?),
};
let formatted = if json {

View File

@ -420,7 +420,7 @@ impl BlockBuilder {
self.file_count = self
.file_count
.checked_add(1)
.ok_or_else(|| CompileError::FileOverflow)?;
.ok_or(CompileError::FileOverflow)?;
Ok(next)
}

View File

@ -230,7 +230,7 @@ pub(crate) fn compile_external_call(
// Pass everything to run-external
let run_external_id = working_set
.find_decl(b"run-external")
.ok_or_else(|| CompileError::RunExternalNotFound { span: head.span })?;
.ok_or(CompileError::RunExternalNotFound { span: head.span })?;
let mut call = Call::new(head.span);
call.decl_id = run_external_id;

View File

@ -133,7 +133,7 @@ pub(crate) fn compile_expression(
Expr::Call(call) => {
move_in_reg_to_out_reg(builder)?;
compile_call(working_set, builder, &call, redirect_modes, out_reg)
compile_call(working_set, builder, call, redirect_modes, out_reg)
}
Expr::ExternalCall(head, args) => {
move_in_reg_to_out_reg(builder)?;
@ -161,9 +161,9 @@ pub(crate) fn compile_expression(
compile_binary_op(
working_set,
builder,
&lhs,
lhs,
operator.clone().into_spanned(op.span),
&rhs,
rhs,
out_reg,
)
} else {
@ -172,14 +172,7 @@ pub(crate) fn compile_expression(
}
Expr::Subexpression(block_id) => {
let block = working_set.get_block(*block_id);
compile_block(
working_set,
builder,
&block,
redirect_modes,
in_reg,
out_reg,
)
compile_block(working_set, builder, block, redirect_modes, in_reg, out_reg)
}
Expr::Block(block_id) => lit(builder, Literal::Block(*block_id)),
Expr::Closure(block_id) => lit(builder, Literal::Closure(*block_id)),

View File

@ -31,7 +31,7 @@ impl RedirectModes {
pub(crate) fn with_capture_out(&self, span: Span) -> Self {
RedirectModes {
out: Some(RedirectMode::Capture.into_spanned(span)),
err: self.err.clone(),
err: self.err,
}
}
}
@ -76,14 +76,14 @@ pub(crate) fn redirect_modes_of_expression(
expression: &Expression,
redir_span: Span,
) -> Result<RedirectModes, CompileError> {
let (out, err) = expression.expr.pipe_redirection(&working_set);
let (out, err) = expression.expr.pipe_redirection(working_set);
Ok(RedirectModes {
out: out
.map(|out| out_dest_to_redirect_mode(out))
.map(out_dest_to_redirect_mode)
.transpose()?
.map(|mode| mode.into_spanned(redir_span)),
err: err
.map(|err| out_dest_to_redirect_mode(err))
.map(out_dest_to_redirect_mode)
.transpose()?
.map(|mode| mode.into_spanned(redir_span)),
})
@ -95,32 +95,30 @@ pub(crate) fn finish_redirection(
modes: RedirectModes,
out_reg: RegId,
) -> Result<(), CompileError> {
match modes.out {
Some(Spanned {
item: RedirectMode::File { file_num },
span,
}) => {
// If out is a file and err is a pipe, we must not consume the expression result -
// that is actually the err, in that case.
if !matches!(
modes.err,
Some(Spanned {
item: RedirectMode::Pipe { .. },
..
})
) {
builder.push(
Instruction::WriteFile {
file_num,
src: out_reg,
}
.into_spanned(span),
)?;
builder.load_empty(out_reg)?;
}
builder.push(Instruction::CloseFile { file_num }.into_spanned(span))?;
if let Some(Spanned {
item: RedirectMode::File { file_num },
span,
}) = modes.out
{
// If out is a file and err is a pipe, we must not consume the expression result -
// that is actually the err, in that case.
if !matches!(
modes.err,
Some(Spanned {
item: RedirectMode::Pipe { .. },
..
})
) {
builder.push(
Instruction::WriteFile {
file_num,
src: out_reg,
}
.into_spanned(span),
)?;
builder.load_empty(out_reg)?;
}
_ => (),
builder.push(Instruction::CloseFile { file_num }.into_spanned(span))?;
}
match modes.err {

View File

@ -811,7 +811,7 @@ fn literal_value(
}
Literal::String(s) => Value::string(ctx.get_str(*s, span)?, span),
Literal::RawString(s) => Value::string(ctx.get_str(*s, span)?, span),
Literal::CellPath(path) => Value::cell_path(CellPath::clone(&path), span),
Literal::CellPath(path) => Value::cell_path(CellPath::clone(path), span),
Literal::Date(dt) => Value::date(**dt, span),
Literal::Nothing => Value::nothing(span),
})
@ -928,7 +928,7 @@ fn eval_call<D: DebugContext>(
// Move environment variables back into the caller stack scope if requested to do so
if block.redirect_env {
redirect_env(engine_state, &mut caller_stack, &mut callee_stack);
redirect_env(engine_state, &mut caller_stack, &callee_stack);
}
} else {
// FIXME: precalculate this and save it somewhere
@ -937,7 +937,7 @@ fn eval_call<D: DebugContext>(
caller_stack
.arguments
.get_args(*args_base, args_len)
.into_iter()
.iter()
.flat_map(|arg| arg.span()),
),
);
@ -1134,8 +1134,7 @@ fn get_env_var_case_insensitive<'a>(ctx: &'a mut EvalContext<'_>, key: &str) ->
.active_overlays
.iter()
.rev()
.map(|name| overlays.get(name))
.flatten()
.filter_map(|name| overlays.get(name))
})
.find_map(|map| {
// Use the hashmap first to try to be faster?
@ -1163,18 +1162,17 @@ fn get_env_var_name_case_insensitive<'a>(ctx: &mut EvalContext<'_>, key: &'a str
.active_overlays
.iter()
.rev()
.map(|name| overlays.get(name))
.flatten()
.filter_map(|name| overlays.get(name))
})
.find_map(|map| {
// Use the hashmap first to try to be faster?
if map.contains_key(key) {
Some(Cow::Borrowed(key))
} else if let Some(k) = map.keys().find(|k| k.eq_ignore_case(key)) {
// it exists, but with a different case
Some(Cow::Owned(k.to_owned()))
} else {
None
map.keys().find(|k| k.eq_ignore_case(key)).map(|k| {
// it exists, but with a different case
Cow::Owned(k.to_owned())
})
}
})
// didn't exist.
@ -1271,7 +1269,7 @@ fn eval_iterate(
let mut data = ctx.take_reg(stream);
if let PipelineData::ListStream(list_stream, _) = &mut data {
// Modify the stream, taking one value off, and branching if it's empty
if let Some(val) = list_stream.next() {
if let Some(val) = list_stream.next_value() {
ctx.put_reg(dst, val.into_pipeline_data());
ctx.put_reg(stream, data); // put the stream back so it can be iterated on again
Ok(InstructionResult::Continue)
@ -1294,6 +1292,7 @@ fn eval_iterate(
/// Redirect environment from the callee stack to the caller stack
fn redirect_env(engine_state: &EngineState, caller_stack: &mut Stack, callee_stack: &Stack) {
// TODO: make this more efficient
// Grab all environment variables from the callee
let caller_env_vars = caller_stack.get_env_var_names(engine_state);

View File

@ -62,15 +62,15 @@ impl Command for KnownExternal {
command.run(engine_state, stack, &(&extern_call).into(), input)
}
CallImpl::AstBox(call) => {
let extern_call = ast_call_to_extern_call(engine_state, &call, &extern_name)?;
let extern_call = ast_call_to_extern_call(engine_state, call, &extern_name)?;
command.run(engine_state, stack, &(&extern_call).into(), input)
}
CallImpl::IrRef(call) => {
let extern_call = ir_call_to_extern_call(stack, &call, &extern_name)?;
let extern_call = ir_call_to_extern_call(stack, call, &extern_name)?;
command.run(engine_state, stack, &(&extern_call).into(), input)
}
CallImpl::IrBox(call) => {
let extern_call = ir_call_to_extern_call(stack, &call, &extern_name)?;
let extern_call = ir_call_to_extern_call(stack, call, &extern_name)?;
command.run(engine_state, stack, &(&extern_call).into(), input)
}
}
@ -100,7 +100,7 @@ fn ast_call_to_extern_call(
extern_call.add_positional(arg_extern_name);
for subcommand in extern_name.into_iter().skip(1) {
for subcommand in extern_name.iter().skip(1) {
extern_call.add_positional(Expression::new_existing(
Expr::String(subcommand.to_string()),
call.head,

View File

@ -5849,7 +5849,7 @@ pub fn parse_block(
/// Compile an IR block for the `Block`, adding a parse warning on failure
fn compile_block(working_set: &mut StateWorkingSet<'_>, block: &mut Block) {
match nu_engine::compile(working_set, &block) {
match nu_engine::compile(working_set, block) {
Ok(ir_block) => {
block.ir_block = Some(ir_block);
}

View File

@ -53,7 +53,7 @@ impl Call<'_> {
pub fn assert_ast_call(&self) -> Result<&ast::Call, ShellError> {
match &self.inner {
CallImpl::AstRef(call) => Ok(call),
CallImpl::AstBox(call) => Ok(&call),
CallImpl::AstBox(call) => Ok(call),
_ => Err(ShellError::NushellFailedSpanned {
msg: "Can't be used in IR context".into(),
label: "this command is not yet supported by IR evaluation".into(),

View File

@ -155,8 +155,7 @@ impl Call {
_ => None,
})
.nth(index)
.map(|option| option.as_ref())
.flatten()
.and_then(|option| option.as_ref())
}
/// Returns every argument to the rest parameter, as well as whether each argument

View File

@ -40,7 +40,7 @@ impl ListStream {
}
/// Take a single value from the inner `Iterator`, modifying the stream.
pub fn next(&mut self) -> Option<Value> {
pub fn next_value(&mut self) -> Option<Value> {
self.stream.next()
}