Skip to content

Commit

Permalink
librustc: Don't ICE when operator traits are not implemented properly.
Browse files Browse the repository at this point in the history
…Fixes #11450
  • Loading branch information
luqmana committed Mar 1, 2014
1 parent 58ea029 commit a174941
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/librustc/middle/typeck/check/mod.rs
Expand Up @@ -1732,7 +1732,13 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
ty::ty_rptr(_, mt) => formal_ty = mt.ty,
ty::ty_err => (),
_ => {
fcx.ccx.tcx.sess.span_bug(arg.span, "no ref");
// So we hit this case when one implements the
// operator traits but leaves an argument as
// just T instead of &T. We'll catch it in the
// mismatch impl/trait method phase no need to
// ICE here.
// See: #11450
formal_ty = ty::mk_err();
}
}
}
Expand Down
33 changes: 33 additions & 0 deletions src/test/compile-fail/wrong-mul-method-signature.rs
@@ -0,0 +1,33 @@
// 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

struct Vec2 {
x: f64,
y: f64
}

impl Mul<Vec2, f64> for Vec2 {
fn mul(&self, s: f64) -> Vec2 {
//~^ ERROR: method `mul` has an incompatible type: expected &-ptr but found f64
Vec2 {
x: self.x * s,
y: self.y * s
}
}
}

pub fn main() {
Vec2 { x: 1.0, y: 2.0 } * 2.0;
}

5 comments on commit a174941

@bors
Copy link
Contributor

@bors bors commented on a174941 Mar 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at luqmana@a174941

@bors
Copy link
Contributor

@bors bors commented on a174941 Mar 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging luqmana/rust/op-no-ref = a174941 into auto

@bors
Copy link
Contributor

@bors bors commented on a174941 Mar 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

luqmana/rust/op-no-ref = a174941 merged ok, testing candidate = d60e43d

@bors
Copy link
Contributor

@bors bors commented on a174941 Mar 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on a174941 Mar 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = d60e43d

Please sign in to comment.