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:
Antoine Stevan 2023-10-19 18:41:38 +02:00 committed by GitHub
parent 54bc662e0e
commit de1c7bb39f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 10 additions and 34 deletions

View File

@ -43,7 +43,7 @@ impl Completer for VariableCompletion {
options: &CompletionOptions, options: &CompletionOptions,
) -> Vec<Suggestion> { ) -> Vec<Suggestion> {
let mut output = vec![]; 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) let var_str = std::str::from_utf8(&self.var_context.0)
.unwrap_or("") .unwrap_or("")
.to_lowercase(); .to_lowercase();

View File

@ -6,8 +6,8 @@ use nu_protocol::{
Expression, Math, Operator, PathMember, PipelineElement, Redirection, Expression, Math, Operator, PathMember, PipelineElement, Redirection,
}, },
engine::{EngineState, Stack}, engine::{EngineState, Stack},
report_error_new, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, Range, Record, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, Range, Record, ShellError, Span,
ShellError, Span, Spanned, Unit, Value, VarId, ENV_VARIABLE_ID, Spanned, Unit, Value, VarId, ENV_VARIABLE_ID,
}; };
use std::collections::HashMap; use std::collections::HashMap;
@ -1128,20 +1128,6 @@ pub fn eval_variable(
span: Span, span: Span,
) -> Result<Value, ShellError> { ) -> Result<Value, ShellError> {
match var_id { 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
nu_protocol::NU_VARIABLE_ID => { nu_protocol::NU_VARIABLE_ID => {
if let Some(val) = engine_state.get_constant(var_id) { if let Some(val) = engine_state.get_constant(var_id) {

View File

@ -3043,7 +3043,7 @@ pub fn parse_let(working_set: &mut StateWorkingSet, spans: &[Span]) -> Pipeline
.trim_start_matches('$') .trim_start_matches('$')
.to_string(); .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)) 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(); .to_string();
// TODO: Remove the hard-coded variables, too error-prone // 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)) 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('$') .trim_start_matches('$')
.to_string(); .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)) working_set.error(ParseError::NameIsBuiltinVar(var_name, lvalue.span))
} }

View File

@ -18,7 +18,7 @@ use nu_protocol::{
engine::StateWorkingSet, engine::StateWorkingSet,
eval_const::{eval_constant, value_as_string}, eval_const::{eval_constant, value_as_string},
span, BlockId, DidYouMean, Flag, ParseError, PositionalArg, Signature, Span, Spanned, 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::{ 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 { pub fn parse_variable_expr(working_set: &mut StateWorkingSet, span: Span) -> Expression {
let contents = working_set.get_span_contents(span); let contents = working_set.get_span_contents(span);
if contents == b"$nothing" { if contents == b"$nu" {
return Expression {
expr: Expr::Var(nu_protocol::NOTHING_VARIABLE_ID),
span,
ty: Type::Nothing,
custom_completion: None,
};
} else if contents == b"$nu" {
return Expression { return Expression {
expr: Expr::Var(nu_protocol::NU_VARIABLE_ID), expr: Expr::Var(nu_protocol::NU_VARIABLE_ID),
span, span,
@ -5834,9 +5827,7 @@ pub fn discover_captures_in_expr(
discover_captures_in_expr(working_set, expr, seen, seen_blocks, output)?; discover_captures_in_expr(working_set, expr, seen, seen_blocks, output)?;
} }
Expr::Var(var_id) => { Expr::Var(var_id) => {
if (*var_id > NOTHING_VARIABLE_ID || *var_id == IN_VARIABLE_ID) if (*var_id > ENV_VARIABLE_ID || *var_id == IN_VARIABLE_ID) && !seen.contains(var_id) {
&& !seen.contains(var_id)
{
output.push((*var_id, expr.span)); output.push((*var_id, expr.span));
} }
} }

View File

@ -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 NU_VARIABLE_ID: usize = 0;
pub const IN_VARIABLE_ID: usize = 1; pub const IN_VARIABLE_ID: usize = 1;
pub const ENV_VARIABLE_ID: usize = 2; 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 // NOTE: If you add more to this list, make sure to update the > checks based on the last in the list
impl EngineState { impl EngineState {

View File

@ -27,7 +27,7 @@ pub use alias::*;
pub use cli_error::*; pub use cli_error::*;
pub use config::*; pub use config::*;
pub use did_you_mean::did_you_mean; 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 example::*;
pub use exportable::*; pub use exportable::*;
pub use id::*; pub use id::*;