From de1c7bb39fe86bbdeec0a9d223cf098425da8413 Mon Sep 17 00:00:00 2001 From: Antoine Stevan <44101798+amtoine@users.noreply.github.com> Date: Thu, 19 Oct 2023 18:41:38 +0200 Subject: [PATCH] remove the `$nothing` variable (#10567) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../src/completions/variable_completions.rs | 2 +- crates/nu-engine/src/eval.rs | 18 ++---------------- crates/nu-parser/src/parse_keywords.rs | 6 +++--- crates/nu-parser/src/parser.rs | 15 +++------------ crates/nu-protocol/src/engine/engine_state.rs | 1 - crates/nu-protocol/src/lib.rs | 2 +- 6 files changed, 10 insertions(+), 34 deletions(-) diff --git a/crates/nu-cli/src/completions/variable_completions.rs b/crates/nu-cli/src/completions/variable_completions.rs index 650d87fc63..ab755d1d85 100644 --- a/crates/nu-cli/src/completions/variable_completions.rs +++ b/crates/nu-cli/src/completions/variable_completions.rs @@ -43,7 +43,7 @@ impl Completer for VariableCompletion { options: &CompletionOptions, ) -> 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) .unwrap_or("") .to_lowercase(); diff --git a/crates/nu-engine/src/eval.rs b/crates/nu-engine/src/eval.rs index 92b871d9cc..f3af6bfcd3 100644 --- a/crates/nu-engine/src/eval.rs +++ b/crates/nu-engine/src/eval.rs @@ -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 { 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) { diff --git a/crates/nu-parser/src/parse_keywords.rs b/crates/nu-parser/src/parse_keywords.rs index 619625846a..267938f6a8 100644 --- a/crates/nu-parser/src/parse_keywords.rs +++ b/crates/nu-parser/src/parse_keywords.rs @@ -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)) } diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 010db7201d..8b002f3a0b 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -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)); } } diff --git a/crates/nu-protocol/src/engine/engine_state.rs b/crates/nu-protocol/src/engine/engine_state.rs index 41b8bda672..952aec11cc 100644 --- a/crates/nu-protocol/src/engine/engine_state.rs +++ b/crates/nu-protocol/src/engine/engine_state.rs @@ -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 { diff --git a/crates/nu-protocol/src/lib.rs b/crates/nu-protocol/src/lib.rs index 2cf80de213..854f5aa30a 100644 --- a/crates/nu-protocol/src/lib.rs +++ b/crates/nu-protocol/src/lib.rs @@ -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::*;