Repository: intellij-rust/intellij-rust
Issue: Can't run tests on Rust 1.70-beta

IntelliJ Rust can't run Rust tests when using Rust 1.70-beta because of https://github.com/rust-lang/rust/pull/109044 (Stable Rust test framework does not support `-Z unstable-options --format json` options anymore)

![image](https://github.com/intellij-rust/intellij-rust/assets/3221931/3ab46588-ce2d-448b-8310-fbedebb36acc)

Changed files:
src/main/kotlin/org/rust/cargo/runconfig/command/CargoCommandConfiguration.kt

diff --git a/src/main/kotlin/org/rust/cargo/runconfig/command/CargoCommandConfiguration.kt b/src/main/kotlin/org/rust/cargo/runconfig/command/CargoCommandConfiguration.kt
index b3013bb99..022cc9359 100644
--- a/src/main/kotlin/org/rust/cargo/runconfig/command/CargoCommandConfiguration.kt
+++ b/src/main/kotlin/org/rust/cargo/runconfig/command/CargoCommandConfiguration.kt
@@ -44,6 +44,7 @@ import org.rust.cargo.toolchain.RsToolchainBase
 import org.rust.cargo.toolchain.RustChannel
 import org.rust.cargo.toolchain.tools.Cargo
 import org.rust.cargo.toolchain.tools.isRustupAvailable
+import org.rust.cargo.util.parseSemVer
 import org.rust.ide.experiments.RsExperiments
 import org.rust.ide.statistics.CargoCommandUsagesCollector
 import org.rust.openapiext.isFeatureEnabled
@@ -203,12 +204,27 @@ open class CargoCommandConfiguration(
         }
     }
 
-    private fun showTestToolWindow(commandLine: CargoCommandLine): Boolean = when {
-        !isFeatureEnabled(RsExperiments.TEST_TOOL_WINDOW) -> false
-        commandLine.command !in listOf("test", "bench") -> false
-        "--nocapture" in commandLine.additionalArguments -> false
-        Cargo.TEST_NOCAPTURE_ENABLED_KEY.asBoolean() -> false
-        else -> !hasRemoteTarget
+    private fun showTestToolWindow(commandLine: CargoCommandLine): Boolean {
+        val isAppropriateConfiguration = when {
+            !isFeatureEnabled(RsExperiments.TEST_TOOL_WINDOW) -> false
+            commandLine.command !in listOf("test", "bench") -> false
+            "--nocapture" in commandLine.additionalArguments -> false
+            Cargo.TEST_NOCAPTURE_ENABLED_KEY.asBoolean() -> false
+            else -> !hasRemoteTarget
+        }
+        if (!isAppropriateConfiguration) return false
+
+        val rustcVersion = findCargoProject(
+            project,
+            commandLine.additionalArguments,
+            commandLine.workingDirectory
+        )?.rustcInfo?.version ?: return true
+
+        // Stable Rust test framework does not support `-Z unstable-options --format json` since 1.70.0-beta
+        // (https://github.com/rust-lang/rust/pull/109044), and we can't use the test tool window without these options
+        return rustcVersion.channel == RustChannel.NIGHTLY
+            || rustcVersion.channel == RustChannel.DEV
+            || rustcVersion.semver < RUSTC_1_70_BETA
     }
 
     override fun createTestConsoleProperties(executor: Executor): SMTRunnerConsoleProperties? {
@@ -279,6 +295,10 @@ open class CargoCommandConfiguration(
     }
 
     companion object {
+        // Stable Rust test framework does not support `-Z unstable-options --format json` since 1.70.0-beta
+        // (https://github.com/rust-lang/rust/pull/109044), and we can't use the test tool window without these options
+        private val RUSTC_1_70_BETA = "1.70.0-beta".parseSemVer()
+
         fun findCargoProject(project: Project, additionalArgs: List<String>, workingDirectory: Path?): CargoProject? {
             val cargoProjects = project.cargoProjects
             cargoProjects.allProjects.singleOrNull()?.let { return it }