rust-analyzer: Wrong type deduction #2

use std::ops;

#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Vec3 {
    v: [f64;3]
}
impl Vec3 {
    pub fn new(e0: f64, e1: f64, e2: f64) -> Vec3 {
        Vec3 {v: [e0, e1, e2]}
    }
}
impl ops::Mul<f64> for Vec3 {
    type Output = Vec3;
    fn mul(self, t: f64) -> Self::Output {
        Vec3::new(self.v[0]*t, self.v[1]*t, self.v[2]*t)
    }
}

#[cfg(test)]
mod tests {
    use super::Vec3;

    #[test]
    pub fn length() {
        let v = Vec3::new(1.0,1.0,1.0);
        let v2 = v * 2.0; //v2 type is Vec3, but rust analyzer shows f64
        assert!(v2.v[0] > v.v[0]);
    }
}

bug_png Rust-analyzer: 0.2.248

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 15 (15 by maintainers)

Commits related to this issue

Most upvoted comments