Skip to content

Code compiles but Rust-analyzer makes error. #12846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
RylanYancey opened this issue Jul 22, 2022 · 3 comments
Closed

Code compiles but Rust-analyzer makes error. #12846

RylanYancey opened this issue Jul 22, 2022 · 3 comments

Comments

@RylanYancey
Copy link

RylanYancey commented Jul 22, 2022

rust-analyzer version: rust-analyzer version: 0.3.1131-standalone (897a7ec 2022-07-17)

rustc version: 1.62.1

relevant settings:
Bug appears on both Windows and WSL. On Windows 11 / Ubuntu 20.04

The code compiles and runs fine, no issues, but Rust-analyzer gives me an error when using DMatrix (typed as Matrix)'s associated functions.

Code example:

extern crate csv;
use csv::Reader;

use std::vec::Vec;
use std::fs;

extern crate nalgebra as na;
type Matrix = na::DMatrix<f32>

pub struct Dataset <const I: usize, const A: usize> {
    filename: String,
    dataset: Vec<Matrix>,
}

impl <const I: usize, const A: usize> Dataset <I, A> {

    pub fn new(name: &str) -> Self {
        Dataset { filename: name.to_string(), dataset: Vec::new() }
    }

    pub fn load_csv<F: Fn(&Vec<String>, &mut [[f32; I]; A])>(&mut self, conversion: F) {
        let contents = fs::read_to_string(
                "data/".to_string() + &self.filename + ".csv").unwrap();

        let mut reader = csv::ReaderBuilder::new()
            .delimiter(b',')
            .from_reader(contents.as_bytes());

        let mut output = [[0.0; I]; A];

        for result in reader.records() {

            let record = result.unwrap();
            let mut features: Vec<String> = Vec::new();

            for f in &record {
                features.push(f.to_string());
            }   

            (conversion)(&features, &mut output);

            let newmat = Matrix::from_fn(I - 1, A - 1, |i, j| { //<--- Error occurs here
                output[i][j]
            });

        }
    }
}

Error:
image
This code lines up with nalgebra's documentation, as found here: https://nalgebra.org/docs/user_guide/vectors_and_matrices#matrix-construction
Cargo.toml:

[package]
name = "canyon"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
nalgebra = "0.31.0"
csv = "1.1.6"
@lnicola
Copy link
Member

lnicola commented Jul 22, 2022

CC #5441.

@RylanYancey
Copy link
Author

RylanYancey commented Jul 22, 2022

CC #5441.

Interesting, looks like this issue has been persisting since 2019? Is there a known workaround?

It is kind of annoying to see the red

@lnicola
Copy link
Member

lnicola commented Aug 2, 2022

You can add it to rust-analyzer.diagnostics.disabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants