Skip to content

Commit 54bc9c2

Browse files
committed
Rollup merge of #55694 - jsirs:issue-31076, r=oli-obk
Fixes #31076
2 parents 8b3d9e5 + 3063977 commit 54bc9c2

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

src/librustc_typeck/check/method/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
289289
// Trait must have a method named `m_name` and it should not have
290290
// type parameters or early-bound regions.
291291
let tcx = self.tcx;
292-
let method_item =
293-
self.associated_item(trait_def_id, m_name, Namespace::Value).unwrap();
292+
let method_item = match self.associated_item(trait_def_id, m_name, Namespace::Value) {
293+
Some(method_item) => method_item,
294+
None => {
295+
tcx.sess.delay_span_bug(span,
296+
"operator trait does not have corresponding operator method");
297+
return None;
298+
}
299+
};
294300
let def_id = method_item.def_id;
295301
let generics = tcx.generics_of(def_id);
296302
assert_eq!(generics.params.len(), 0);

src/test/ui/issues/issue-31076.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![feature(no_core, lang_items)]
2+
#![no_core]
3+
4+
#[lang="sized"]
5+
trait Sized {}
6+
7+
#[lang="add"]
8+
trait Add<T> {}
9+
10+
impl Add<i32> for i32 {}
11+
12+
fn main() {
13+
let x = 5 + 6;
14+
//~^ ERROR binary operation `+` cannot be applied to type `{integer}`
15+
let y = 5i32 + 6i32;
16+
//~^ ERROR binary operation `+` cannot be applied to type `i32`
17+
}

src/test/ui/issues/issue-31076.stderr

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0369]: binary operation `+` cannot be applied to type `{integer}`
2+
--> $DIR/issue-31076.rs:13:13
3+
|
4+
LL | let x = 5 + 6;
5+
| ^^^^^
6+
|
7+
= note: an implementation of `std::ops::Add` might be missing for `{integer}`
8+
9+
error[E0369]: binary operation `+` cannot be applied to type `i32`
10+
--> $DIR/issue-31076.rs:15:13
11+
|
12+
LL | let y = 5i32 + 6i32;
13+
| ^^^^^^^^^^^
14+
|
15+
= note: an implementation of `std::ops::Add` might be missing for `i32`
16+
17+
error: aborting due to 2 previous errors
18+
19+
For more information about this error, try `rustc --explain E0369`.

0 commit comments

Comments
 (0)