2014-02-28 21:59:15 -06:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
// This test is to make sure we don't just ICE if the trait
|
|
|
|
// method for an operator is not implemented properly.
|
|
|
|
// (In this case the mul method should take &f64 and not f64)
|
|
|
|
// See: #11450
|
|
|
|
|
2014-12-22 11:04:23 -06:00
|
|
|
use std::ops::Mul;
|
|
|
|
|
2014-04-04 20:19:33 -05:00
|
|
|
struct Vec1 {
|
|
|
|
x: f64
|
|
|
|
}
|
|
|
|
|
2014-12-01 16:52:10 -06:00
|
|
|
// Expecting value in input signature
|
2014-12-31 14:45:13 -06:00
|
|
|
impl Mul<f64> for Vec1 {
|
|
|
|
type Output = Vec1;
|
|
|
|
|
2014-12-01 16:52:10 -06:00
|
|
|
fn mul(self, s: &f64) -> Vec1 {
|
2015-01-12 00:01:44 -06:00
|
|
|
//~^ ERROR method `mul` has an incompatible type for trait
|
2014-04-04 20:19:33 -05:00
|
|
|
Vec1 {
|
2014-12-01 16:52:10 -06:00
|
|
|
x: self.x * *s
|
2014-04-04 20:19:33 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-28 21:59:15 -06:00
|
|
|
struct Vec2 {
|
|
|
|
x: f64,
|
|
|
|
y: f64
|
|
|
|
}
|
|
|
|
|
2014-04-04 20:19:33 -05:00
|
|
|
// Wrong type parameter ordering
|
2014-12-31 14:45:13 -06:00
|
|
|
impl Mul<Vec2> for Vec2 {
|
|
|
|
type Output = f64;
|
|
|
|
|
2014-12-01 16:52:10 -06:00
|
|
|
fn mul(self, s: f64) -> Vec2 {
|
2015-01-12 00:01:44 -06:00
|
|
|
//~^ ERROR method `mul` has an incompatible type for trait
|
2014-02-28 21:59:15 -06:00
|
|
|
Vec2 {
|
|
|
|
x: self.x * s,
|
|
|
|
y: self.y * s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-04 20:19:33 -05:00
|
|
|
struct Vec3 {
|
|
|
|
x: f64,
|
|
|
|
y: f64,
|
|
|
|
z: f64
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unexpected return type
|
2014-12-31 14:45:13 -06:00
|
|
|
impl Mul<f64> for Vec3 {
|
|
|
|
type Output = i32;
|
|
|
|
|
2014-12-01 16:52:10 -06:00
|
|
|
fn mul(self, s: f64) -> f64 {
|
2015-01-12 00:01:44 -06:00
|
|
|
//~^ ERROR method `mul` has an incompatible type for trait
|
2014-12-01 16:52:10 -06:00
|
|
|
s
|
2014-04-04 20:19:33 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-28 21:59:15 -06:00
|
|
|
pub fn main() {
|
2014-10-17 08:11:10 -05:00
|
|
|
// Check that the usage goes from the trait declaration:
|
|
|
|
|
|
|
|
let x: Vec1 = Vec1 { x: 1.0 } * 2.0; // this is OK
|
|
|
|
|
|
|
|
let x: Vec2 = Vec2 { x: 1.0, y: 2.0 } * 2.0; // trait had reversed order
|
2015-04-14 07:23:02 -05:00
|
|
|
// (we no longer signal a compile error here, since the
|
|
|
|
// error in the trait signature will cause compilation to
|
|
|
|
// abort before we bother looking at function bodies.)
|
2014-10-17 08:11:10 -05:00
|
|
|
|
|
|
|
let x: i32 = Vec3 { x: 1.0, y: 2.0, z: 3.0 } * 2.0;
|
2014-02-28 21:59:15 -06:00
|
|
|
}
|