diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index 11448750618e2..637f3eaae9a6a 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -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); diff --git a/src/test/ui/issues/issue-31076.rs b/src/test/ui/issues/issue-31076.rs new file mode 100644 index 0000000000000..e4531072e9be4 --- /dev/null +++ b/src/test/ui/issues/issue-31076.rs @@ -0,0 +1,17 @@ +#![feature(no_core, lang_items)] +#![no_core] + +#[lang="sized"] +trait Sized {} + +#[lang="add"] +trait Add {} + +impl Add 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` +} diff --git a/src/test/ui/issues/issue-31076.stderr b/src/test/ui/issues/issue-31076.stderr new file mode 100644 index 0000000000000..3a13f02d9f45f --- /dev/null +++ b/src/test/ui/issues/issue-31076.stderr @@ -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`.