Closed
Description
Compiling the following file:
// vec.rs
mod test {
#[test]
fn it_should_scale_a_vector() {
::Vec2 { x: 1.0, y: 2.0 } * 2.0
}
}
pub struct Vec2 {
x: f64,
y: f64
}
impl Mul<Vec2, f64> for Vec2 {
fn mul(&self, s: f64) -> Vec2 {
Vec2 {
x: self.x * s,
y: self.y * s }
}
}
Leads to the following error message:
$ rustc --test vec.rs
vec.rs:6:31: 6:34 error: internal compiler error: no ref
This message reflects a bug in the Rust compiler.
We would appreciate a bug report: https://github.com/mozilla/rust/wiki/HOWTO-submit-a-Rust-bug-report
vec.rs:6 ::Vec2 { x: 1.0, y: 2.0 } * 2.0
^~~
task 'rustc' failed at 'explicit failure', /home/hanno/Desktop/Stuff/tmp/rust/src/libsyntax/diagnostic.rs:41
task '<main>' failed at 'explicit failure', /home/hanno/Desktop/Stuff/tmp/rust/src/librustc/lib.rs:453
Rust version:
$ rustc --version
rustc 0.9 (6ea218d 2014-01-09 23:26:20 -0800)
host: x86_64-unknown-linux-gnu
Please note that moving the test function into the top-level module reveals what seems to be the root cause of the problem.
New file:
// vec.rs
pub struct Vec2 {
x: f64,
y: f64
}
impl Mul<Vec2, f64> for Vec2 {
fn mul(&self, s: f64) -> Vec2 {
Vec2 {
x: self.x * s,
y: self.y * s }
}
}
#[test]
fn it_should_scale_a_vector() {
::Vec2 { x: 1.0, y: 2.0 } * 2.0
}
New compiler error:
$ rustc --test vec.rs
vec.rs:9:2: 13:3 error: method `mul` has an incompatible type: expected &-ptr but found f64
vec.rs:9 fn mul(&self, s: f64) -> Vec2 {
vec.rs:10 Vec2 {
vec.rs:11 x: self.x * s,
vec.rs:12 y: self.y * s }
vec.rs:13 }
vec.rs:18:30: 18:33 error: internal compiler error: no ref
This message reflects a bug in the Rust compiler.
We would appreciate a bug report: https://github.com/mozilla/rust/wiki/HOWTO-submit-a-Rust-bug-report
vec.rs:18 ::Vec2 { x: 1.0, y: 2.0 } * 2.0
^~~
task 'rustc' failed at 'explicit failure', /home/hanno/Desktop/Stuff/tmp/rust/src/libsyntax/diagnostic.rs:41
task '<main>' failed at 'explicit failure', /home/hanno/Desktop/Stuff/tmp/rust/src/librustc/lib.rs:453
This fixed version compiles without any errors:
// vec.rs
pub struct Vec2 {
x: f64,
y: f64
}
impl Mul<f64, Vec2> for Vec2 {
fn mul(&self, s: &f64) -> Vec2 {
Vec2 {
x: self.x * *s,
y: self.y * *s }
}
}
#[test]
fn it_should_scale_a_vector() {
::Vec2 { x: 1.0, y: 2.0 } * 2.0;
}