Skip to content

Commit 98a96b0

Browse files
committed
Auto merge of #46403 - oli-obk:generic_missing_impl, r=nikomatsakis
Report a targeted note for generic parameters that are missing a trait bound
2 parents a4fa23a + 9e062c8 commit 98a96b0

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

src/librustc/ty/sty.rs

-7
Original file line numberDiff line numberDiff line change
@@ -1196,13 +1196,6 @@ impl RegionKind {
11961196

11971197
/// Type utilities
11981198
impl<'a, 'gcx, 'tcx> TyS<'tcx> {
1199-
pub fn as_opt_param_ty(&self) -> Option<ty::ParamTy> {
1200-
match self.sty {
1201-
ty::TyParam(ref d) => Some(d.clone()),
1202-
_ => None,
1203-
}
1204-
}
1205-
12061199
pub fn is_nil(&self) -> bool {
12071200
match self.sty {
12081201
TyTuple(ref tys, _) => tys.is_empty(),

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)