rust-lang / rust-lang/rust-analyzer

Analyzer indicates wrong return type for function

Open
#17,212 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-nameres C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

The matrix-sdk and it's subcrates contain several structs with the name SyncResponse. When calling client.sync_once as seen below, the function returns matrix_sdk::sync::SyncResponse. However, rust-analyzer determines the type to be from the matrix_sdk_base it indicates matrix_sdk_base::sync::SyncResponse. This can be seen by doing either of those:

  1. Ctrl+Click on the Type jumps in to the source code of matrix_sdk_base
  2. Trying to extract SyncResponse::next_batch as seen in the code below. This field does exist in matrix_sdk::sync::SyncResponse but not in matrix_sdk_base::sync::SyncResponse. Since rust-analyzer resolves to matrix_sdk_base::sync::SyncResponse, the type of token cannot be resolved.

rust-analyzer version: 0.4.1954-standalone

rustc version: rustc 1.78.0 (9b00956e5 2024-04-29)

editor or extension: VSCode extension v0.3.1950

relevant settings: Unchanged default settings

code snippet to reproduce:

use matrix_sdk::{config::SyncSettings, ruma::user_id, Client};

#[tokio::main(flavor = "current_thread")]
async fn main() {
    let user = user_id!("@user:example.org");

    let client = Client::builder()
        .server_name(user.server_name())
        .build()
        .await
        .unwrap();

    let sync_response = client.sync_once(SyncSettings::new()).await.unwrap();
    let token = sync_response.next_batch;

    println!("{:?}", token);
}
[package]
name = "analyzer-bug"
version = "0.1.0"
edition = "2021"

[dependencies]
matrix-sdk = "0.7.1"
tokio = { version = "1.37.0", features = ["macros", "rt"] }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the provided Rust snippet and matrix-sdk 0.7.1, then follow rust-analyzer's handling of the client.sync_once return type and Ctrl+Click target. Done means the type resolves to matrix_sdk::sync::SyncResponse and sync_response.next_batch resolves successfully without errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.