Repository: nushell/nushell (language: rust)

Issue:
Can't run `const` at parse time.
### Describe the bug

When I want to limit the scope of a variable to avoid polluting the global namespace I use this pattern:
```nushell
let foo = (
  let bar = "thing";
  $bar + $bar
)
```
Which works without a problem.

I recently tried the same with `const`
```nushell
const foo = (
  const bar = "thing";
  $bar + $bar
)
```

Which failed.

```
Error: 
  × Error: nu::shell::not_a_const_command
  │ 
  │   × Not a const command.
  │    ╭─[entry #8:2:3]
  │  1 │ const foo = (
  │  2 │   const bar = "thing";
  │    ·   ──┬──
  │    ·     ╰── This command cannot run at parse time.
  │  3 │   $bar + $bar
  │    ╰────
  │   help: Only a subset of builtin commands, and custom commands built only from those commands, can run at parse time.
  │ 
   ╭─[entry #8:1:13]
 1 │ ╭─▶ const foo = (
 2 │ │     const bar = "thing";
 3 │ │     $bar + $bar
 4 │ ├─▶ )
   · ╰──── Encountered error during parse-time evaluation
   ╰────
```

### How to reproduce

```nushell
const foo = (
  const bar = "thing";
  $bar + $bar
)
```

### Expected behavior

Allow const in a const context.

### Configuration

| key                | value                                       |
| ------------------ | ------------------------------------------- |
| version            | 0.100.1                                     |
| major              | 0                                           |
| minor              | 100                                         |
| patch              | 1                                           |
| branch             | nightly                                     |
| commit_hash        | 4f20c370f90a935fc6a999f732a92dc0e928c6c9    |
| build_os           | linux-x86_64                                |
| build_target       | x86_64-unknown-linux-gnu                    |
| rust_version       | rustc 1.81.0 (eeb90cda1 2024-09-04)         |
| rust_channel       | 1.81.0-x86_64-unknown-linux-gnu             |
| cargo_version      | cargo 1.81.0 (2dbb1af80 2024-08-20)         |
| build_time         | 2024-12-11 02:10:59 +00:00                  |
| build_rust_channel | release                                     |
| allocator          | mimalloc                                    |
| features           | default, sqlite, static-link-openssl, trash |
| installed_plugins  |                                             |


Discussion / hints:
Would it be helpful to allow nested const declarations? Happy to help if this is something we want to implement

Fix patch:
diff --git a/crates/nu-cmd-lang/src/core_commands/const_.rs b/crates/nu-cmd-lang/src/core_commands/const_.rs
index 67182faedd108..5727938c84e63 100644
--- a/crates/nu-cmd-lang/src/core_commands/const_.rs
+++ b/crates/nu-cmd-lang/src/core_commands/const_.rs
@@ -72,6 +72,19 @@ impl Command for Const {
         }
     }
 
+    fn run_const(
+        &self,
+        _working_set: &StateWorkingSet,
+        _call: &Call,
+        _input: PipelineData,
+    ) -> Result<PipelineData, ShellError> {
+        Ok(PipelineData::empty())
+    }
+
+    fn is_const(&self) -> bool {
+        true
+    }
+
     fn examples(&self) -> Vec<Example> {
         vec![
             Example {


Test patch:
diff --git a/tests/const_/mod.rs b/tests/const_/mod.rs
index fec81eba78401..d76c18d07b2ef 100644
--- a/tests/const_/mod.rs
+++ b/tests/const_/mod.rs
@@ -433,3 +433,12 @@ fn const_takes_pipeline() {
     let actual = nu!(r#"const list = 'bar_baz_quux' | split row '_'; $list | length"#);
     assert_eq!(actual.out, "3");
 }
+
+#[test]
+fn const_const() {
+    let actual = nu!(r#"const y = (const x = "foo"; $x + $x); $y"#);
+    assert_eq!(actual.out, "foofoo");
+
+    let actual = nu!(r#"const y = (const x = "foo"; $x + $x); $x"#);
+    assert!(actual.err.contains("nu::parser::variable_not_found"));
+}