Skip to content

Commit 9e062c8

Browse files
committed
Report a targeted note for generic parameters
1 parent 12697fa commit 9e062c8

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

src/librustc_typeck/check/op.rs

+5
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
289289
// This has nothing here because it means we did string
290290
// concatenation (e.g. "Hello " + "World!"). This means
291291
// we don't want the note in the else clause to be emitted
292+
} else if let ty::TyParam(_) = lhs_ty.sty {
293+
// FIXME: point to span of param
294+
err.note(
295+
&format!("`{}` might need a bound for `{}`",
296+
lhs_ty, missing_trait));
292297
} else {
293298
err.note(
294299
&format!("an implementation of `{}` might be missing for `{}`",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
}
13+
14+
fn foo<T>(x: T, y: T) {
15+
let z = x + y; //~ ERROR binary operation `+` cannot be applied to type `T`
16+
//~^ NOTE `T` might need a bound for `std::ops::Add`
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error[E0369]: binary operation `+` cannot be applied to type `T`
2+
--> $DIR/missing_trait_impl.rs:15:13
3+
|
4+
15 | let z = x + y; //~ ERROR binary operation `+` cannot be applied to type `T`
5+
| ^^^^^
6+
|
7+
= note: `T` might need a bound for `std::ops::Add`
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)