Replace &Span with Span since Span is Copy (#9770)

# Description
`Span` is `Copy`, so we probably should not be passing references of
`Span` around. This PR replaces all instances of `&Span` with `Span`,
copying spans where necessary.

# User-Facing Changes
This alters some public functions to take `Span` instead of `&Span` as
input. Namely, `EngineState::get_span_contents`,
`nu_protocol::extract_value`, a bunch of the math commands, and
`Gstat::gstat`.
This commit is contained in:
Ian Manske
2023-07-31 19:47:46 +00:00
committed by GitHub
parent 94bec72079
commit 583ef8674e
35 changed files with 356 additions and 365 deletions

View File

@ -70,10 +70,10 @@ pub fn get_pipeline_elements(
while i < pipeline.elements.len() {
let pipeline_element = &pipeline.elements[i];
let pipeline_expression = pipeline_element.expression().clone();
let pipeline_span = &pipeline_element.span();
let pipeline_span = pipeline_element.span();
let element_str =
String::from_utf8_lossy(engine_state.get_span_contents(pipeline_span));
let value = Value::string(element_str.to_string(), *pipeline_span);
let value = Value::string(element_str.to_string(), pipeline_span);
let expr = pipeline_expression.expr.clone();
let (command_name, command_args_value) = if let Expr::Call(call) = expr {
let command = engine_state.get_decl(call.decl_id);

View File

@ -41,7 +41,7 @@ impl Command for ViewSource {
let block = engine_state.get_block(block_id);
if let Some(span) = block.span {
let contents = engine_state.get_span_contents(&span);
let contents = engine_state.get_span_contents(span);
Ok(Value::string(String::from_utf8_lossy(contents), call.head)
.into_pipeline_data())
} else {
@ -61,7 +61,7 @@ impl Command for ViewSource {
if let Some(block_id) = decl.get_block_id() {
let block = engine_state.get_block(block_id);
if let Some(block_span) = block.span {
let contents = engine_state.get_span_contents(&block_span);
let contents = engine_state.get_span_contents(block_span);
// name of function
let mut final_contents = format!("def {val} [ ");
for n in vec_of_required {
@ -117,7 +117,7 @@ impl Command for ViewSource {
// arg is a module
let module = engine_state.get_module(module_id);
if let Some(module_span) = module.span {
let contents = engine_state.get_span_contents(&module_span);
let contents = engine_state.get_span_contents(module_span);
Ok(Value::string(String::from_utf8_lossy(contents), call.head)
.into_pipeline_data())
} else {

View File

@ -42,7 +42,7 @@ impl Command for ViewSpan {
if start_span.item < end_span.item {
let bin_contents =
engine_state.get_span_contents(&Span::new(start_span.item, end_span.item));
engine_state.get_span_contents(Span::new(start_span.item, end_span.item));
Ok(
Value::string(String::from_utf8_lossy(bin_contents), call.head)
.into_pipeline_data(),