rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.04k stars 1.56k forks source link

Wrong errors reported: expected Expr #17424

Closed yipu3 closed 48 minutes ago

yipu3 commented 2 months ago

rust-analyzer version: rust-analyzer version: 0.3.1995-standalone (c86d6230f 2024-06-10) [/Users/Philip/.vscode/extensions/rust-lang.rust-analyzer-0.3.1995-darwin-x64/server/rust-analyzer]

rustc version: rustc 1.58.1 (db9d1b20b 2022-01-20)

editor or extension: VSCode, v0.3.1995

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTC, RUSTUP_HOME or CARGO_HOME)

repository link (if public, optional): https://github.com/yipu3/algorithm-practice/tree/main/leetcode/502/rust

code snippet to reproduce:

use std::collections::BinaryHeap;

#[derive(Debug)]
struct Project {
    profit: i32,
    capital: i32,
}

pub fn find_maximized_capital(k: i32, w: i32, profits: Vec<i32>, capital: Vec<i32>) -> i32 {
    let mut projects = Vec::new();
    for i in 0..profits.len() {
        projects.push(Project {
            profit: profits[i],
            capital: capital[i],
        });
    }
    projects.sort_by(|a, b| a.capital.cmp(&b.capital));
    // println!("{:?}", projects);

    let mut w = w;
    let mut h = BinaryHeap::new();
    let mut c = 0;
    let mut i = 0;

    loop {
        while i < projects.len() && projects[i].capital <= w {
            h.push(projects[i].profit);
            i += 1;
        }
        if h.peek().is_none() {
            break;
        }
        w += h.pop().unwrap();
        c += 1;
        if c == k {
            break;
        }
    }

    w
}

fn main() {
    assert_eq!(
        find_maximized_capital(2, 0, vec![1, 2, 3], vec![0, 1, 1]),
        4
    );
}
Screen Shot 2024-06-15 at 08 28 58 Screen Shot 2024-06-15 at 08 31 24
Veykril commented 2 months ago

Your rustc version is very old compared to the rust-analyzer releases so its likely to fail because of that given the error is within a standard library macro. Either upgrade your rust toolchain or downgrade your rust-analyzer, we generally dont support more than the ~2 latest stable releases for a given rust-analyzer version

TroyKomodo commented 3 hours ago

I also have this issue on the latest version of rust / nightly release of rust-analyzer.

image

Cargo check / build reports no errors and if i restart rust analyzer the error disappears but then will reappear after some time.

I suspect its something to do with my macro, ill try make a smaller example