Skip to content

internal compiler error: no ref #12252

Closed
Closed
@dangets

Description

@dangets

May be similar to #11450, but maybe not. Running on Arch Linux, pulled rust master today.

use std::num::sqrt;

struct Vec2 {
    x: f32,
    y: f32,
}

impl Vec2 {
    fn new(x: f32, y: f32) -> Vec2 {
        Vec2 {x: x, y: y}
    }

    fn normalized(&self) -> Vec2 {
        self / self.length()
    }

    fn length(&self) -> f32 {
        sqrt(self.length_squared())
    }

    fn length_squared(&self) -> f32 {
        self.x * self.x +
        self.y * self.y
    }
}

impl Div<f32, Vec2> for Vec2 {
    fn div(&self, scalar: f32) -> Vec2 {
        let inverse = 1.0f32 / scalar;
        Vec2 {
            x: self.x * inverse,
            y: self.y * inverse,
        }
    }
}

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

    #[test]
    fn test_length() {
        let v = Vec2::new(3, 4);
        let len = v.length();
        assert!(len > 0.49 && len < 0.51);
    }
}
[127] dg@dg-devbox> rustc vector-min.rs --test
vector-min.rs:14:16: 14:29 error: internal compiler error: no ref
This message reflects a bug in the Rust compiler. 
We would appreciate a bug report: http://static.rust-lang.org/doc/master/complement-bugreport.html
vector-min.rs:14         self / self.length()
dg@dg-devbox> rustc -v
rustc 0.10-pre (cfb87f1 2014-02-13 10:32:18 -0800)
host: x86_64-unknown-linux-gnu

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions