Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

librustc: Don't ICE when operator traits are not implemented properly. #12638

Merged
merged 1 commit into from
Mar 1, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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;
}