mirror of
https://github.com/nushell/nushell.git
synced 2024-11-25 01:43:47 +01:00
remove the $nothing
variable (#10567)
related to - https://github.com/nushell/nushell/pull/10478 # Description this PR is the followup removal to https://github.com/nushell/nushell/pull/10478. # User-Facing Changes `$nothing` is now an undefined variable, unless define by the user. ```nushell > $nothing Error: nu::parser::variable_not_found × Variable not found. ╭─[entry #1:1:1] 1 │ $nothing · ────┬─── · ╰── variable not found. ╰──── ``` # Tests + Formatting # After Submitting mention that in release notes
This commit is contained in:
parent
54bc662e0e
commit
de1c7bb39f
@ -43,7 +43,7 @@ impl Completer for VariableCompletion {
|
||||
options: &CompletionOptions,
|
||||
) -> Vec<Suggestion> {
|
||||
let mut output = vec![];
|
||||
let builtins = ["$nu", "$in", "$env", "$nothing"];
|
||||
let builtins = ["$nu", "$in", "$env"];
|
||||
let var_str = std::str::from_utf8(&self.var_context.0)
|
||||
.unwrap_or("")
|
||||
.to_lowercase();
|
||||
|
@ -6,8 +6,8 @@ use nu_protocol::{
|
||||
Expression, Math, Operator, PathMember, PipelineElement, Redirection,
|
||||
},
|
||||
engine::{EngineState, Stack},
|
||||
report_error_new, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, Range, Record,
|
||||
ShellError, Span, Spanned, Unit, Value, VarId, ENV_VARIABLE_ID,
|
||||
IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, Range, Record, ShellError, Span,
|
||||
Spanned, Unit, Value, VarId, ENV_VARIABLE_ID,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
|
||||
@ -1128,20 +1128,6 @@ pub fn eval_variable(
|
||||
span: Span,
|
||||
) -> Result<Value, ShellError> {
|
||||
match var_id {
|
||||
// $nothing
|
||||
nu_protocol::NOTHING_VARIABLE_ID => {
|
||||
report_error_new(
|
||||
engine_state,
|
||||
&ShellError::GenericError(
|
||||
"Deprecated variable".into(),
|
||||
"`$nothing` is deprecated and will be removed in 0.87.".into(),
|
||||
Some(span),
|
||||
Some("Use `null` instead".into()),
|
||||
vec![],
|
||||
),
|
||||
);
|
||||
Ok(Value::nothing(span))
|
||||
}
|
||||
// $nu
|
||||
nu_protocol::NU_VARIABLE_ID => {
|
||||
if let Some(val) = engine_state.get_constant(var_id) {
|
||||
|
@ -3043,7 +3043,7 @@ pub fn parse_let(working_set: &mut StateWorkingSet, spans: &[Span]) -> Pipeline
|
||||
.trim_start_matches('$')
|
||||
.to_string();
|
||||
|
||||
if ["in", "nu", "env", "nothing"].contains(&var_name.as_str()) {
|
||||
if ["in", "nu", "env"].contains(&var_name.as_str()) {
|
||||
working_set.error(ParseError::NameIsBuiltinVar(var_name, lvalue.span))
|
||||
}
|
||||
|
||||
@ -3151,7 +3151,7 @@ pub fn parse_const(working_set: &mut StateWorkingSet, spans: &[Span]) -> Pipelin
|
||||
.to_string();
|
||||
|
||||
// TODO: Remove the hard-coded variables, too error-prone
|
||||
if ["in", "nu", "env", "nothing"].contains(&var_name.as_str()) {
|
||||
if ["in", "nu", "env"].contains(&var_name.as_str()) {
|
||||
working_set.error(ParseError::NameIsBuiltinVar(var_name, lvalue.span))
|
||||
}
|
||||
|
||||
@ -3292,7 +3292,7 @@ pub fn parse_mut(working_set: &mut StateWorkingSet, spans: &[Span]) -> Pipeline
|
||||
.trim_start_matches('$')
|
||||
.to_string();
|
||||
|
||||
if ["in", "nu", "env", "nothing"].contains(&var_name.as_str()) {
|
||||
if ["in", "nu", "env"].contains(&var_name.as_str()) {
|
||||
working_set.error(ParseError::NameIsBuiltinVar(var_name, lvalue.span))
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ use nu_protocol::{
|
||||
engine::StateWorkingSet,
|
||||
eval_const::{eval_constant, value_as_string},
|
||||
span, BlockId, DidYouMean, Flag, ParseError, PositionalArg, Signature, Span, Spanned,
|
||||
SyntaxShape, Type, Unit, VarId, IN_VARIABLE_ID, NOTHING_VARIABLE_ID,
|
||||
SyntaxShape, Type, Unit, VarId, ENV_VARIABLE_ID, IN_VARIABLE_ID,
|
||||
};
|
||||
|
||||
use crate::parse_keywords::{
|
||||
@ -1784,14 +1784,7 @@ pub fn parse_string_interpolation(working_set: &mut StateWorkingSet, span: Span)
|
||||
pub fn parse_variable_expr(working_set: &mut StateWorkingSet, span: Span) -> Expression {
|
||||
let contents = working_set.get_span_contents(span);
|
||||
|
||||
if contents == b"$nothing" {
|
||||
return Expression {
|
||||
expr: Expr::Var(nu_protocol::NOTHING_VARIABLE_ID),
|
||||
span,
|
||||
ty: Type::Nothing,
|
||||
custom_completion: None,
|
||||
};
|
||||
} else if contents == b"$nu" {
|
||||
if contents == b"$nu" {
|
||||
return Expression {
|
||||
expr: Expr::Var(nu_protocol::NU_VARIABLE_ID),
|
||||
span,
|
||||
@ -5834,9 +5827,7 @@ pub fn discover_captures_in_expr(
|
||||
discover_captures_in_expr(working_set, expr, seen, seen_blocks, output)?;
|
||||
}
|
||||
Expr::Var(var_id) => {
|
||||
if (*var_id > NOTHING_VARIABLE_ID || *var_id == IN_VARIABLE_ID)
|
||||
&& !seen.contains(var_id)
|
||||
{
|
||||
if (*var_id > ENV_VARIABLE_ID || *var_id == IN_VARIABLE_ID) && !seen.contains(var_id) {
|
||||
output.push((*var_id, expr.span));
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +113,6 @@ const REGEX_CACHE_SIZE: usize = 100; // must be nonzero, otherwise will panic
|
||||
pub const NU_VARIABLE_ID: usize = 0;
|
||||
pub const IN_VARIABLE_ID: usize = 1;
|
||||
pub const ENV_VARIABLE_ID: usize = 2;
|
||||
pub const NOTHING_VARIABLE_ID: usize = 3;
|
||||
// NOTE: If you add more to this list, make sure to update the > checks based on the last in the list
|
||||
|
||||
impl EngineState {
|
||||
|
@ -27,7 +27,7 @@ pub use alias::*;
|
||||
pub use cli_error::*;
|
||||
pub use config::*;
|
||||
pub use did_you_mean::did_you_mean;
|
||||
pub use engine::{ENV_VARIABLE_ID, IN_VARIABLE_ID, NOTHING_VARIABLE_ID, NU_VARIABLE_ID};
|
||||
pub use engine::{ENV_VARIABLE_ID, IN_VARIABLE_ID, NU_VARIABLE_ID};
|
||||
pub use example::*;
|
||||
pub use exportable::*;
|
||||
pub use id::*;
|
||||
|
Loading…
Reference in New Issue
Block a user