Skip to content

Commit c4eca64

Browse files
authored
Remove all usages of internal_span (nushell#16799)
This PR removes all usages of `internal_span`. Hooray! It also upgrades the `ast-grep` for `internal_span` from a warning to an error, so we can prevent accidentally reintroducing `internal_span` Related: nushell#12963
1 parent 2f88a09 commit c4eca64

File tree

14 files changed

+97
-153
lines changed

14 files changed

+97
-153
lines changed

ast-grep/rules/internal_span.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
id: internal_span
44
language: rust
5-
severity: warning
5+
severity: error
66
message: "Using `internal_span` directly is deprecated."
77
note: "You can get the span using the `Value::span()` method."
88

crates/nu-cmd-extra/src/extra/filters/update_cells.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,16 @@ impl Command for UpdateCells {
114114

115115
let metadata = input.metadata();
116116

117+
let span = input.span();
117118
match input {
118-
PipelineData::Value(
119-
Value::Record {
120-
ref mut val,
121-
internal_span,
122-
},
123-
..,
124-
) => {
119+
PipelineData::Value(Value::Record { ref mut val, .. }, ..) => {
120+
// SAFETY: we have a value in the input, so we must have a span
121+
let span = span.expect("value had no span");
125122
let val = val.to_mut();
126123
update_record(
127124
val,
128125
&mut ClosureEval::new(engine_state, stack, closure),
129-
internal_span,
126+
span,
130127
columns.as_ref(),
131128
);
132129
Ok(input)

crates/nu-command/src/conversions/into/value.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,10 @@ impl Command for IntoValue {
8181
call: &Call,
8282
input: PipelineData,
8383
) -> Result<PipelineData, ShellError> {
84-
if let PipelineData::Value(Value::Custom { val, internal_span }, metadata) = input {
85-
return Ok(PipelineData::value(
86-
val.to_base_value(internal_span)?,
87-
metadata,
88-
));
84+
if let PipelineData::Value(v @ Value::Custom { .. }, metadata) = input {
85+
let span = v.span();
86+
let val = v.into_custom_value()?;
87+
return Ok(PipelineData::value(val.to_base_value(span)?, metadata));
8988
}
9089

9190
if let Some(block_id) = DEPRECATED_REDIRECT_BLOCK_ID.get() {

crates/nu-command/src/filesystem/save.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,16 @@ impl Command for Save {
233233
};
234234

235235
// Save custom value however they implement saving
236-
if let PipelineData::Value(Value::Custom { val, internal_span }, ..) = converted {
236+
if let PipelineData::Value(v @ Value::Custom { .. }, ..) = converted {
237+
let val_span = v.span();
238+
let val = v.into_custom_value()?;
237239
return val
238240
.save(
239241
Spanned {
240242
item: &path.item,
241243
span: path.span,
242244
},
243-
internal_span,
245+
val_span,
244246
span,
245247
)
246248
.map(|()| PipelineData::empty());

crates/nu-command/src/generators/seq_date.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,24 @@ impl Command for SeqDate {
200200
let end_date: Option<Spanned<String>> = call.get_flag(engine_state, stack, "end-date")?;
201201

202202
let increment = match call.get_flag::<Value>(engine_state, stack, "increment")? {
203-
Some(increment) => match increment {
204-
Value::Int { val, internal_span } => Some(
205-
val.checked_mul(NANOSECONDS_IN_DAY)
206-
.ok_or_else(|| ShellError::GenericError {
207-
error: "increment is too large".into(),
208-
msg: "increment is too large".into(),
209-
span: Some(internal_span),
210-
help: None,
211-
inner: vec![],
212-
})?
213-
.into_spanned(internal_span),
214-
),
215-
Value::Duration { val, internal_span } => Some(val.into_spanned(internal_span)),
216-
_ => None,
217-
},
203+
Some(increment) => {
204+
let span = increment.span();
205+
match increment {
206+
Value::Int { val, .. } => Some(
207+
val.checked_mul(NANOSECONDS_IN_DAY)
208+
.ok_or_else(|| ShellError::GenericError {
209+
error: "increment is too large".into(),
210+
msg: "increment is too large".into(),
211+
span: Some(span),
212+
help: None,
213+
inner: vec![],
214+
})?
215+
.into_spanned(span),
216+
),
217+
Value::Duration { val, .. } => Some(val.into_spanned(span)),
218+
_ => None,
219+
}
220+
}
218221
None => None,
219222
};
220223

crates/nu-command/src/math/abs.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,9 @@ impl Command for MathAbs {
4848
input: PipelineData,
4949
) -> Result<PipelineData, ShellError> {
5050
let head = call.head;
51-
if let PipelineData::Value(
52-
Value::Range {
53-
ref val,
54-
internal_span,
55-
},
56-
..,
57-
) = input
58-
{
59-
ensure_bounded(val.as_ref(), internal_span, head)?;
51+
if let PipelineData::Value(ref v @ Value::Range { ref val, .. }, ..) = input {
52+
let span = v.span();
53+
ensure_bounded(val, span, head)?;
6054
}
6155
input.map(move |value| abs_helper(value, head), engine_state.signals())
6256
}
@@ -68,15 +62,9 @@ impl Command for MathAbs {
6862
input: PipelineData,
6963
) -> Result<PipelineData, ShellError> {
7064
let head = call.head;
71-
if let PipelineData::Value(
72-
Value::Range {
73-
ref val,
74-
internal_span,
75-
},
76-
..,
77-
) = input
78-
{
79-
ensure_bounded(val.as_ref(), internal_span, head)?;
65+
if let PipelineData::Value(ref v @ Value::Range { ref val, .. }, ..) = input {
66+
let span = v.span();
67+
ensure_bounded(val, span, head)?;
8068
}
8169
input.map(
8270
move |value| abs_helper(value, head),

crates/nu-command/src/math/ceil.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,9 @@ impl Command for MathCeil {
4747
if let PipelineData::Empty = input {
4848
return Err(ShellError::PipelineEmpty { dst_span: head });
4949
}
50-
if let PipelineData::Value(
51-
Value::Range {
52-
ref val,
53-
internal_span,
54-
},
55-
..,
56-
) = input
57-
{
58-
ensure_bounded(val.as_ref(), internal_span, head)?;
50+
if let PipelineData::Value(ref v @ Value::Range { ref val, .. }, ..) = input {
51+
let span = v.span();
52+
ensure_bounded(val, span, head)?;
5953
}
6054
input.map(move |value| operate(value, head), engine_state.signals())
6155
}
@@ -71,15 +65,9 @@ impl Command for MathCeil {
7165
if let PipelineData::Empty = input {
7266
return Err(ShellError::PipelineEmpty { dst_span: head });
7367
}
74-
if let PipelineData::Value(
75-
Value::Range {
76-
ref val,
77-
internal_span,
78-
},
79-
..,
80-
) = input
81-
{
82-
ensure_bounded(val.as_ref(), internal_span, head)?;
68+
if let PipelineData::Value(ref v @ Value::Range { ref val, .. }, ..) = input {
69+
let span = v.span();
70+
ensure_bounded(val, span, head)?;
8371
}
8472
input.map(
8573
move |value| operate(value, head),

crates/nu-command/src/math/floor.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,9 @@ impl Command for MathFloor {
6565
if let PipelineData::Empty = input {
6666
return Err(ShellError::PipelineEmpty { dst_span: head });
6767
}
68-
if let PipelineData::Value(
69-
Value::Range {
70-
ref val,
71-
internal_span,
72-
},
73-
..,
74-
) = input
75-
{
76-
ensure_bounded(val.as_ref(), internal_span, head)?;
68+
if let PipelineData::Value(ref v @ Value::Range { ref val, .. }, ..) = input {
69+
let span = v.span();
70+
ensure_bounded(val, span, head)?;
7771
}
7872
input.map(
7973
move |value| operate(value, head),

crates/nu-command/src/math/log.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,9 @@ impl Command for MathLog {
5050
) -> Result<PipelineData, ShellError> {
5151
let head = call.head;
5252
let base: Spanned<f64> = call.req(engine_state, stack, 0)?;
53-
if let PipelineData::Value(
54-
Value::Range {
55-
ref val,
56-
internal_span,
57-
},
58-
..,
59-
) = input
60-
{
61-
ensure_bounded(val.as_ref(), internal_span, head)?;
53+
if let PipelineData::Value(ref v @ Value::Range { ref val, .. }, ..) = input {
54+
let span = v.span();
55+
ensure_bounded(val, span, head)?;
6256
}
6357
log(base, call.head, input, engine_state.signals())
6458
}
@@ -71,15 +65,9 @@ impl Command for MathLog {
7165
) -> Result<PipelineData, ShellError> {
7266
let head = call.head;
7367
let base: Spanned<f64> = call.req_const(working_set, 0)?;
74-
if let PipelineData::Value(
75-
Value::Range {
76-
ref val,
77-
internal_span,
78-
},
79-
..,
80-
) = input
81-
{
82-
ensure_bounded(val.as_ref(), internal_span, head)?;
68+
if let PipelineData::Value(ref v @ Value::Range { ref val, .. }, ..) = input {
69+
let span = v.span();
70+
ensure_bounded(val, span, head)?;
8371
}
8472
log(base, call.head, input, working_set.permanent().signals())
8573
}

crates/nu-command/src/math/round.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,9 @@ impl Command for MathRound {
5454
if let PipelineData::Empty = input {
5555
return Err(ShellError::PipelineEmpty { dst_span: head });
5656
}
57-
if let PipelineData::Value(
58-
Value::Range {
59-
ref val,
60-
internal_span,
61-
},
62-
..,
63-
) = input
64-
{
65-
ensure_bounded(val.as_ref(), internal_span, head)?;
57+
if let PipelineData::Value(ref v @ Value::Range { ref val, .. }, ..) = input {
58+
let span = v.span();
59+
ensure_bounded(val, span, head)?;
6660
}
6761
input.map(
6862
move |value| operate(value, head, precision_param),
@@ -82,15 +76,9 @@ impl Command for MathRound {
8276
if let PipelineData::Empty = input {
8377
return Err(ShellError::PipelineEmpty { dst_span: head });
8478
}
85-
if let PipelineData::Value(
86-
Value::Range {
87-
ref val,
88-
internal_span,
89-
},
90-
..,
91-
) = input
92-
{
93-
ensure_bounded(val.as_ref(), internal_span, head)?;
79+
if let PipelineData::Value(ref v @ Value::Range { ref val, .. }, ..) = input {
80+
let span = v.span();
81+
ensure_bounded(val, span, head)?;
9482
}
9583
input.map(
9684
move |value| operate(value, head, precision_param),

0 commit comments

Comments
 (0)