You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IntelliJ运行Rust测试自动添加-Z unstable-options报错,如何移除?

解决IntelliJ Rust插件自动添加-Z unstable-options导致测试失败的问题

问题背景

通过IntelliJ测试按钮运行Rust测试时,插件自动生成的命令包含-Z unstable-options,而稳定版Cargo不支持该选项,导致报错:

error: the option `Z` is only accepted on the nightly compiler

解决方案

方法1:切换至Nightly Rust编译器

如果项目允许使用Nightly版本,直接切换编译器即可兼容该选项:

  • 打开IntelliJ设置(快捷键Ctrl+Alt+S或File > Settings)
  • 导航到Languages & Frameworks > Rust
  • 在Toolchain区域,选择已安装的Nightly版本rustc(若未安装,可点击Download按钮获取)
  • 保存设置后重新运行测试

方法2:禁用插件的结构化输出功能

插件添加-Z unstable-options是为了获取结构化测试输出,禁用该功能即可移除该参数:

  • 打开IntelliJ设置,导航到Languages & Frameworks > Rust > Testing
  • 取消勾选Enable structured output选项
  • 保存设置后,重新点击测试按钮,生成的命令将不再包含-Z unstable-options

方法3:创建自定义测试运行配置

如果上述方法无效,可手动创建不含不稳定参数的测试配置:

  • 点击IntelliJ右上角的运行配置下拉框,选择Edit Configurations
  • 点击左上角的+号,选择Cargo Command
  • 在Command字段输入自定义测试命令,例如:
    cargo test --package myproject-rust --lib mycode::tests --no-fail-fast --show-output
    
  • 配置好后保存,后续直接使用该配置运行测试即可

内容的提问来源于stack exchange,提问作者user8473984

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 16:24:50