Improve empty pipelines (#7383)

# Description

This fix changes pipelines to allow them to actually be empty. Mapping
over empty pipelines gives empty pipelines. Empty pipelines immediately
return `None` when iterated.

This removes a some of where `Span::new(0, 0)` was coming from, though
there are other cases where we still use it.

# User-Facing Changes

None

# Tests + Formatting

Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
This commit is contained in:
JT
2022-12-08 07:31:57 +13:00
committed by GitHub
parent d18587330a
commit eaec480f42
80 changed files with 194 additions and 190 deletions

View File

@ -350,7 +350,7 @@ fn get_converted_value(
engine_state,
&mut stack,
block,
PipelineData::new(val_span),
PipelineData::new_with_metadata(None, val_span),
true,
true,
);

View File

@ -339,10 +339,7 @@ pub fn eval_expression(
}
Expr::Call(call) => {
// FIXME: protect this collect with ctrl-c
Ok(
eval_call(engine_state, stack, call, PipelineData::new(call.head))?
.into_value(call.head),
)
Ok(eval_call(engine_state, stack, call, PipelineData::empty())?.into_value(call.head))
}
Expr::ExternalCall(head, args, is_subexpression) => {
let span = head.span;
@ -352,7 +349,7 @@ pub fn eval_expression(
stack,
head,
args,
PipelineData::new(span),
PipelineData::empty(),
false,
false,
*is_subexpression,
@ -536,7 +533,7 @@ pub fn eval_expression(
// FIXME: protect this collect with ctrl-c
Ok(
eval_subexpression(engine_state, stack, block, PipelineData::new(expr.span))?
eval_subexpression(engine_state, stack, block, PipelineData::empty())?
.into_value(expr.span),
)
}
@ -1087,14 +1084,28 @@ pub fn eval_block(
match engine_state.find_decl("table".as_bytes(), &[]) {
Some(decl_id) => {
let table = engine_state.get_decl(decl_id).run(
engine_state,
stack,
&Call::new(Span::new(0, 0)),
input,
)?;
let table = engine_state.get_decl(decl_id);
print_or_return(table, config)?;
if let Some(block_id) = table.get_block_id() {
let block = engine_state.get_block(block_id);
eval_block(
engine_state,
stack,
block,
input,
redirect_stdout,
redirect_stderr,
)?;
} else {
let table = table.run(
engine_state,
stack,
&Call::new(Span::new(0, 0)),
input,
)?;
print_or_return(table, config)?;
}
}
None => {
print_or_return(input, config)?;
@ -1103,7 +1114,7 @@ pub fn eval_block(
}
}
input = PipelineData::new(Span::unknown())
input = PipelineData::empty()
}
}