zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
39.2k stars 2.03k forks source link

Wrong Inlay Hints for Rust #13381

Open GreenYun opened 1 week ago

GreenYun commented 1 week ago

Check for existing issues

Describe the bug / provide steps to reproduce it

Try this code:

use std::env;

fn main() {
    let mut var1 = String::new();
    let mut var2 = String::new();

    env::vars_os()
        .map(|(k, v)| {
            (
                k.to_string_lossy().into_owned().to_uppercase(),
                v.to_string_lossy().into_owned(),
            )
        })
        .for_each(|(key, val)| match key.as_str() {
            "VAR1" => var1 = val,
            "VAR2" => var2 = val,
            _ => (),
        });

    println!("{var1}, {var2}");
}

Also, configure Zed and rust-analyzer to show inlay hints:

{
  "inlay_hints": { "enabled": true },
  "lsp": {
    "rust-analyzer": { "initialization_options": {
        "inlayHints": {
          "expressionAdjustmentHints": { "enable": "reborrow" },
          "typeHints": { "hideNamedConstructor": true }
        }
    }}
  }
}

This is what Zed shows (Please focus on line 10, missing an opening parenthesis for the closing one):

image

If I slightly edit line 10, e.g. add an dot before .to_uppercase(), then delete it, Zed shows:

image

Different changes to line 10 then rolling back will produce different the inlay hints. This is fun.

Environment

Zed: v0.140.5 (Zed) OS: macOS 12.7.5 Memory: 8 GiB Architecture: x86_64

If applicable, add mockups / screenshots to help explain present your vision of the feature

For reference, VS Code with rust-analyzer gives stable, correct output of inlay hints:

image

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

Zed.log


SomeoneToIgnore commented 1 week ago

This seems very similar to https://github.com/zed-industries/zed/issues/7928 , at least the underlying ordering issue is shared.