Strange behavior of rust-analyzer in Rust 1.97.0
⚓ Rust 📅 2026-07-11 👤 surdeus 👁️ 1Hi,
I am exposing a strange behavior in rust-analyzer in VScode, that I'm experiencing since I upgraded Rust from 1.96.1 to 1.97.0: I'm receiving dead code warnings in two cases, through a project consisting of several thousands LOCs. The warnings are the following:
warning: associated function `new` is never used
--> src\task\internal_task.rs:34:12
|
33 | impl CommandRunner {
| ------------------ associated function in this implementation
34 | pub fn new() -> Self {
| ^^^
|
= note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default
which is related to this piece of code:
// a command runner function type
type CommandRunnerFunction = fn(&str) -> Result<bool>;
// and the command runner structure to be instantiated only once
struct CommandRunner {
command_runner: Option<CommandRunnerFunction>,
}
impl CommandRunner {
pub fn new() -> Self {
CommandRunner {
command_runner: None,
}
}
pub fn set_runner(&mut self, f: CommandRunnerFunction) {
self.command_runner = Some(f);
}
}
// an instance of the command runner that will be used by all tasks to run
// internal commands: it is synchronized in order to avoid collisions
lazy_static! {
static ref COMMAND_RUNNER: Mutex<CommandRunner> = Mutex::new(CommandRunner::new());
}
(I pasted the entire context just to show that the function is actually used). The second warning is about a pub const:
warning: constant `APP_GUID` is never used
--> src\constants.rs:21:11
|
21 | pub const APP_GUID: &str = "663f98a9-a1ef-46ef-a7bc-bb2482f42440_DEBUG";
| ^^^^^^^^
Well, no need to waste space reporting where the const is defined, it is exactly where rust-analyzer says. It is used, however, in another module (main), this time too in a lazy_static! context:
// single instance name
static ref INSTANCE_GUID: String = format!(
"{APP_NAME}-{}-{APP_GUID}",
{ if let Ok(s) = username() { s } else { String::from(STR_UNKNOWN_VALUE) }},
);
I've started thinking that this might be part of the process of deprecating lazy_static!, but I've found that the related issue is not closed yet.
I tried to switch from the rust-analyzer that is provided with the extension, to the one that can be installed directly to the toolchain by using rustup component add rust-analyzer, with the same results.
This happens on two different VScode setups, one on Windows, and the other one on Linux.
This said, the code shows no warning by cargo checking directly, or by compiling it. And the problem popped up only after the above mentioned upgrade.
Anyone is experiencing something similar? I'd like to know, because I really wouldn't want to file an issue being the only affected person in the whole universe.
Thank you,
Francesco
4 posts - 2 participants
🏷️ Rust_feed