Rollup merge of #55694 - jsirs:issue-31076, r=oli-obk

Fixes #31076
This commit is contained in:
kennytm 2018-11-06 15:21:09 +08:00
commit 54bc9c27e4
No known key found for this signature in database
GPG Key ID: FEF6C8051D0E013C
3 changed files with 44 additions and 2 deletions

View File

@ -289,8 +289,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// Trait must have a method named `m_name` and it should not have
// type parameters or early-bound regions.
let tcx = self.tcx;
let method_item =
self.associated_item(trait_def_id, m_name, Namespace::Value).unwrap();
let method_item = match self.associated_item(trait_def_id, m_name, Namespace::Value) {
Some(method_item) => method_item,
None => {
tcx.sess.delay_span_bug(span,
"operator trait does not have corresponding operator method");
return None;
}
};
let def_id = method_item.def_id;
let generics = tcx.generics_of(def_id);
assert_eq!(generics.params.len(), 0);

View File

@ -0,0 +1,17 @@
#![feature(no_core, lang_items)]
#![no_core]
#[lang="sized"]
trait Sized {}
#[lang="add"]
trait Add<T> {}
impl Add<i32> for i32 {}
fn main() {
let x = 5 + 6;
//~^ ERROR binary operation `+` cannot be applied to type `{integer}`
let y = 5i32 + 6i32;
//~^ ERROR binary operation `+` cannot be applied to type `i32`
}

View File

@ -0,0 +1,19 @@
error[E0369]: binary operation `+` cannot be applied to type `{integer}`
--> $DIR/issue-31076.rs:13:13
|
LL | let x = 5 + 6;
| ^^^^^
|
= note: an implementation of `std::ops::Add` might be missing for `{integer}`
error[E0369]: binary operation `+` cannot be applied to type `i32`
--> $DIR/issue-31076.rs:15:13
|
LL | let y = 5i32 + 6i32;
| ^^^^^^^^^^^
|
= note: an implementation of `std::ops::Add` might be missing for `i32`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0369`.