Skip to content

Commit

Permalink
Rollup merge of rust-lang#55694 - jsirs:issue-31076, r=oli-obk
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytm committed Nov 6, 2018
2 parents 8b3d9e5 + 3063977 commit 54bc9c2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/librustc_typeck/check/method/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 17 additions & 0 deletions src/test/ui/issues/issue-31076.rs
Original file line number Diff line number Diff line change
@@ -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`
}
19 changes: 19 additions & 0 deletions src/test/ui/issues/issue-31076.stderr
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit 54bc9c2

Please sign in to comment.