报错error: failure removing component 'rustfmt-preview-x86_64-pc-windows-msvc':已解决

212 阅读1分钟
  • Rust在大型项目开发时总是无法识别不到文件
  • Rust报错不支持该平台Unfortunately we don't ship binaries for your platform yet. You need to manually clone the rust-analyzer repository and run cargo xtask install --server to build the language server from sources. If you feel that your
  • Rust格式化失败但是可以编译
  • cargo check可以检查错误但是编辑器无法检查错误

windows怎么可能不支持呢,原因是工具链损坏

解决方案一

更新Rust,需要关闭使用Rust的工具如Vscode、RustRover,出现问题大概率是之前更新的时候没关闭正在使用的工具

rustup update stable

失败先删除工具链

rustup toolchain remove stable

再安装工具链

rustup toolchain install stable

查看Rust版本

rustc --version

查看cargo版本

cargo --version

解决方案二

出错的地方太多了,分析不过来,多注释一些代码

解决方案三

手动编译rust-analyzer,在解决方案一的基础上保持最新版,然后本地编译

下载最新的包

git clone https://github.com/rust-lang/rust-analyzer

进入目录编译

cd rust-analyzer

cargo xtask install --server

将项目根目录的target\release复制到一个固定的目录

image.png

在vscode中指定rust-analyzer

image.png

搜索rust-analyzer

image.png

修改为rust-analyzer的绝对地址,需要\\\是转义

image.png

右下角会有一个restart now重启扩展即可,或者关闭vscode重新打开项目

RustRover检查代码

RustRover是内置的分析工具,你可以运行外部的Linter如cargo check检查代码,默认会将分析结果同步到代码编辑区

image.png