Skip to content

False positive E0107 with std::sync::Weak::upgrade and std::io::Write #22297

@Meralis40

Description

@Meralis40

rust-analyzer resolves incorrectly types when using std::sync::Weak::upgrade (the resulting type is shown as Arc<{unknown}>. This cause E0107 when calling upgrade() on a Weak<RwLock<T>> and std::io::Write is in the scope, and RwLock::write() is called on the upgraded Arc.
This does not happen with std::rc::Weak.
In both case, cargo check returns without any error.

rust-analyzer version: rust-analyzer version: 0.3.2887-standalone (f04c372 2026-05-03)

rustc version: rustc 1.97.0-nightly (e95e73209 2026-05-05)

editor or extension: VSCode v1.118.1 + rust-analyzer v0.3.2887

relevant settings: rust-analyzer extension settings:

{
    "rust-analyzer.cargo.targetDir": "${workspaceFolder}/target/rust-analyzer",
    "rust-analyzer.hover.actions.references.enable": true,
    "rust-analyzer.restartServerOnConfigChange": true,
    "rust-analyzer.testExplorer": true,
    "rust-analyzer.assist.emitMustUse": true,
    "rust-analyzer.server.extraEnv": {
        "CMAKE_GENERATOR": "Ninja"
    },
    "rust-analyzer.cargo.extraEnv": {
        "CMAKE_GENERATOR": "Ninja"
    }
}

code snippet to reproduce:

use std::sync::Weak;
// use std::rc::Weak;
use std::io::Write;
use std::sync::RwLock;

fn main() {
    let t : Weak<RwLock<()>> = Weak::new();
    if let Some(x) = t.upgrade() {
        // r-a shows error E0107 here (expected 1 argument, found 0)
        // If std::rc::Weak is used instead, r-a shows no error
        let _unused = x.write();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions