Skip to content

Commit a174941

Browse files
committed
librustc: Don't ICE when operator traits are not implemented properly. Fixes #11450
1 parent 58ea029 commit a174941

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

Diff for: src/librustc/middle/typeck/check/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,13 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
17321732
ty::ty_rptr(_, mt) => formal_ty = mt.ty,
17331733
ty::ty_err => (),
17341734
_ => {
1735-
fcx.ccx.tcx.sess.span_bug(arg.span, "no ref");
1735+
// So we hit this case when one implements the
1736+
// operator traits but leaves an argument as
1737+
// just T instead of &T. We'll catch it in the
1738+
// mismatch impl/trait method phase no need to
1739+
// ICE here.
1740+
// See: #11450
1741+
formal_ty = ty::mk_err();
17361742
}
17371743
}
17381744
}

Diff for: src/test/compile-fail/wrong-mul-method-signature.rs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// This test is to make sure we don't just ICE if the trait
12+
// method for an operator is not implemented properly.
13+
// (In this case the mul method should take &f64 and not f64)
14+
// See: #11450
15+
16+
struct Vec2 {
17+
x: f64,
18+
y: f64
19+
}
20+
21+
impl Mul<Vec2, f64> for Vec2 {
22+
fn mul(&self, s: f64) -> Vec2 {
23+
//~^ ERROR: method `mul` has an incompatible type: expected &-ptr but found f64
24+
Vec2 {
25+
x: self.x * s,
26+
y: self.y * s
27+
}
28+
}
29+
}
30+
31+
pub fn main() {
32+
Vec2 { x: 1.0, y: 2.0 } * 2.0;
33+
}

0 commit comments

Comments
 (0)