about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJonathan Turner <jonathandturner@users.noreply.github.com>2016-10-24 15:41:29 -0700
committerGitHub <noreply@github.com>2016-10-24 15:41:29 -0700
commit050499c407218fb6b0044bc4a16ffbfb906ec3a4 (patch)
tree64d636d1593a2510e3ebc5b7cbe7dba07b4aa073
parent855f3e740c35af413c27f12a85be1557ca36633a (diff)
parent1fadd868cd4fbb16d9d9a7d07fa02997b50194f5 (diff)
downloadrust-050499c407218fb6b0044bc4a16ffbfb906ec3a4.tar.gz
rust-050499c407218fb6b0044bc4a16ffbfb906ec3a4.zip
Rollup merge of #37324 - GuillaumeGomez:trait_error_message, r=jonathandturner
Improve E0277 help message

Fixes #37319.

r? @jonathandturner
-rw-r--r--src/librustc/traits/error_reporting.rs6
-rw-r--r--src/test/compile-fail/E0277.rs2
-rw-r--r--src/test/compile-fail/associated-types-ICE-when-projecting-out-of-err.rs2
-rw-r--r--src/test/compile-fail/cast-rfc0401.rs4
-rw-r--r--src/test/compile-fail/const-unsized.rs8
-rw-r--r--src/test/compile-fail/impl-trait/auto-trait-leak.rs8
-rw-r--r--src/test/compile-fail/on-unimplemented/multiple-impls.rs6
-rw-r--r--src/test/compile-fail/on-unimplemented/on-impl.rs9
-rw-r--r--src/test/compile-fail/on-unimplemented/on-trait.rs4
-rw-r--r--src/test/compile-fail/on-unimplemented/slice-index.rs14
-rw-r--r--src/test/compile-fail/trait-suggest-where-clause.rs14
11 files changed, 41 insertions, 36 deletions
diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs
index 52ddd8ab5da..fafdf161b2d 100644
--- a/src/librustc/traits/error_reporting.rs
+++ b/src/librustc/traits/error_reporting.rs
@@ -445,8 +445,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
                                 let mut err = struct_span_err!(self.tcx.sess, span, E0277,
                                     "the trait bound `{}` is not satisfied",
                                     trait_ref.to_predicate());
-                                err.span_label(span, &format!("trait `{}` not satisfied",
-                                                              trait_ref.to_predicate()));
+                                err.span_label(span, &format!("the trait `{}` is not implemented \
+                                                               for `{}`",
+                                                              trait_ref,
+                                                              trait_ref.self_ty()));
 
                                 // Try to report a help message
 
diff --git a/src/test/compile-fail/E0277.rs b/src/test/compile-fail/E0277.rs
index 12f9417f944..e4cb50cd3f2 100644
--- a/src/test/compile-fail/E0277.rs
+++ b/src/test/compile-fail/E0277.rs
@@ -19,6 +19,6 @@ fn some_func<T: Foo>(foo: T) {
 fn main() {
     some_func(5i32);
     //~^ ERROR the trait bound `i32: Foo` is not satisfied
-    //~| NOTE trait `i32: Foo` not satisfied
+    //~| NOTE the trait `Foo` is not implemented for `i32`
     //~| NOTE required by `some_func`
 }
diff --git a/src/test/compile-fail/associated-types-ICE-when-projecting-out-of-err.rs b/src/test/compile-fail/associated-types-ICE-when-projecting-out-of-err.rs
index 08461696467..5a19aecf667 100644
--- a/src/test/compile-fail/associated-types-ICE-when-projecting-out-of-err.rs
+++ b/src/test/compile-fail/associated-types-ICE-when-projecting-out-of-err.rs
@@ -32,5 +32,5 @@ fn ice<A>(a: A) {
     let r = loop {};
     r = r + a;
     //~^ ERROR the trait bound `(): Add<A>` is not satisfied
-    //~| NOTE trait `(): Add<A>` not satisfied
+    //~| NOTE the trait `Add<A>` is not implemented for `()`
 }
diff --git a/src/test/compile-fail/cast-rfc0401.rs b/src/test/compile-fail/cast-rfc0401.rs
index ee622a17ab1..0c373057c76 100644
--- a/src/test/compile-fail/cast-rfc0401.rs
+++ b/src/test/compile-fail/cast-rfc0401.rs
@@ -92,7 +92,7 @@ fn main()
     let _ = v as *const [u8]; //~ ERROR cannot cast
     let _ = fat_v as *const Foo;
     //~^ ERROR the trait bound `[u8]: std::marker::Sized` is not satisfied
-    //~| NOTE trait `[u8]: std::marker::Sized` not satisfied
+    //~| NOTE the trait `std::marker::Sized` is not implemented for `[u8]`
     //~| NOTE `[u8]` does not have a constant size known at compile-time
     //~| NOTE required for the cast to the object type `Foo`
     let _ = foo as *const str; //~ ERROR casting
@@ -107,7 +107,7 @@ fn main()
     let a : *const str = "hello";
     let _ = a as *const Foo;
     //~^ ERROR the trait bound `str: std::marker::Sized` is not satisfied
-    //~| NOTE trait `str: std::marker::Sized` not satisfied
+    //~| NOTE the trait `std::marker::Sized` is not implemented for `str`
     //~| NOTE `str` does not have a constant size known at compile-time
     //~| NOTE required for the cast to the object type `Foo`
 
diff --git a/src/test/compile-fail/const-unsized.rs b/src/test/compile-fail/const-unsized.rs
index a73164b957c..226b567c546 100644
--- a/src/test/compile-fail/const-unsized.rs
+++ b/src/test/compile-fail/const-unsized.rs
@@ -12,25 +12,25 @@ use std::fmt::Debug;
 
 const CONST_0: Debug+Sync = *(&0 as &(Debug+Sync));
 //~^ ERROR `std::fmt::Debug + Sync + 'static: std::marker::Sized` is not satisfied
-//~| NOTE `std::fmt::Debug + Sync + 'static: std::marker::Sized` not satisfied
+//~| NOTE the trait `std::marker::Sized` is not implemented for `std::fmt::Debug + Sync + 'static`
 //~| NOTE does not have a constant size known at compile-time
 //~| NOTE constant expressions must have a statically known size
 
 const CONST_FOO: str = *"foo";
 //~^ ERROR `str: std::marker::Sized` is not satisfied
-//~| NOTE `str: std::marker::Sized` not satisfied
+//~| NOTE the trait `std::marker::Sized` is not implemented for `str`
 //~| NOTE does not have a constant size known at compile-time
 //~| NOTE constant expressions must have a statically known size
 
 static STATIC_1: Debug+Sync = *(&1 as &(Debug+Sync));
 //~^ ERROR `std::fmt::Debug + Sync + 'static: std::marker::Sized` is not satisfied
-//~| NOTE `std::fmt::Debug + Sync + 'static: std::marker::Sized` not satisfied
+//~| NOTE the trait `std::marker::Sized` is not implemented for `std::fmt::Debug + Sync + 'static`
 //~| NOTE does not have a constant size known at compile-time
 //~| NOTE constant expressions must have a statically known size
 
 static STATIC_BAR: str = *"bar";
 //~^ ERROR `str: std::marker::Sized` is not satisfied
-//~| NOTE `str: std::marker::Sized` not satisfied
+//~| NOTE the trait `std::marker::Sized` is not implemented for `str`
 //~| NOTE does not have a constant size known at compile-time
 //~| NOTE constant expressions must have a statically known size
 
diff --git a/src/test/compile-fail/impl-trait/auto-trait-leak.rs b/src/test/compile-fail/impl-trait/auto-trait-leak.rs
index 60ad266e7f7..f055d20e134 100644
--- a/src/test/compile-fail/impl-trait/auto-trait-leak.rs
+++ b/src/test/compile-fail/impl-trait/auto-trait-leak.rs
@@ -26,7 +26,7 @@ fn send<T: Send>(_: T) {}
 fn main() {
     send(before());
     //~^ ERROR the trait bound `std::rc::Rc<std::cell::Cell<i32>>: std::marker::Send` is not satisfied
-    //~| NOTE trait `std::rc::Rc<std::cell::Cell<i32>>: std::marker::Send` not satisfied
+    //~| NOTE the trait `std::marker::Send` is not implemented for `std::rc::Rc<std::cell::Cell<i32>>`
     //~| NOTE `std::rc::Rc<std::cell::Cell<i32>>` cannot be sent between threads safely
     //~| NOTE required because it appears within the type `[closure
     //~| NOTE required because it appears within the type `impl std::ops::Fn<(i32,)>`
@@ -34,7 +34,7 @@ fn main() {
 
     send(after());
     //~^ ERROR the trait bound `std::rc::Rc<std::cell::Cell<i32>>: std::marker::Send` is not satisfied
-    //~| NOTE trait `std::rc::Rc<std::cell::Cell<i32>>: std::marker::Send` not satisfied
+    //~| NOTE the trait `std::marker::Send` is not implemented for `std::rc::Rc<std::cell::Cell<i32>>`
     //~| NOTE `std::rc::Rc<std::cell::Cell<i32>>` cannot be sent between threads safely
     //~| NOTE required because it appears within the type `[closure
     //~| NOTE required because it appears within the type `impl std::ops::Fn<(i32,)>`
@@ -54,7 +54,7 @@ fn after() -> impl Fn(i32) {
 fn cycle1() -> impl Clone {
     send(cycle2().clone());
     //~^ ERROR the trait bound `std::rc::Rc<std::string::String>: std::marker::Send` is not satisfied
-    //~| NOTE trait `std::rc::Rc<std::string::String>: std::marker::Send` not satisfied
+    //~| NOTE the trait `std::marker::Send` is not implemented for `std::rc::Rc<std::string::String>`
     //~| NOTE `std::rc::Rc<std::string::String>` cannot be sent between threads safely
     //~| NOTE required because it appears within the type `impl std::clone::Clone`
     //~| NOTE required by `send`
@@ -65,7 +65,7 @@ fn cycle1() -> impl Clone {
 fn cycle2() -> impl Clone {
     send(cycle1().clone());
     //~^ ERROR the trait bound `std::rc::Rc<std::cell::Cell<i32>>: std::marker::Send` is not satisfied
-    //~| NOTE trait `std::rc::Rc<std::cell::Cell<i32>>: std::marker::Send` not satisfied
+    //~| NOTE the trait `std::marker::Send` is not implemented for `std::rc::Rc<std::cell::Cell<i32>>`
     //~| NOTE `std::rc::Rc<std::cell::Cell<i32>>` cannot be sent between threads safely
     //~| NOTE required because it appears within the type `impl std::clone::Clone`
     //~| NOTE required by `send`
diff --git a/src/test/compile-fail/on-unimplemented/multiple-impls.rs b/src/test/compile-fail/on-unimplemented/multiple-impls.rs
index cc7c2f4f796..0ad9f21e098 100644
--- a/src/test/compile-fail/on-unimplemented/multiple-impls.rs
+++ b/src/test/compile-fail/on-unimplemented/multiple-impls.rs
@@ -42,17 +42,17 @@ impl Index<Bar<usize>> for [i32] {
 fn main() {
     Index::index(&[] as &[i32], 2u32);
     //~^ ERROR E0277
-    //~| NOTE not satisfied
+    //~| NOTE the trait `Index<u32>` is not implemented for `[i32]`
     //~| NOTE trait message
     //~| NOTE required by
     Index::index(&[] as &[i32], Foo(2u32));
     //~^ ERROR E0277
-    //~| NOTE not satisfied
+    //~| NOTE the trait `Index<Foo<u32>>` is not implemented for `[i32]`
     //~| NOTE on impl for Foo
     //~| NOTE required by
     Index::index(&[] as &[i32], Bar(2u32));
     //~^ ERROR E0277
-    //~| NOTE not satisfied
+    //~| NOTE the trait `Index<Bar<u32>>` is not implemented for `[i32]`
     //~| NOTE on impl for Bar
     //~| NOTE required by
 }
diff --git a/src/test/compile-fail/on-unimplemented/on-impl.rs b/src/test/compile-fail/on-unimplemented/on-impl.rs
index c22e48bede4..a7c599330a0 100644
--- a/src/test/compile-fail/on-unimplemented/on-impl.rs
+++ b/src/test/compile-fail/on-unimplemented/on-impl.rs
@@ -29,8 +29,9 @@ impl Index<usize> for [i32] {
 
 #[rustc_error]
 fn main() {
-    Index::<u32>::index(&[1, 2, 3] as &[i32], 2u32); //~ ERROR E0277
-                                                     //~| NOTE not satisfied
-                                                     //~| NOTE a usize is required
-                                                     //~| NOTE required by
+    Index::<u32>::index(&[1, 2, 3] as &[i32], 2u32);
+    //~^ ERROR E0277
+    //~| NOTE the trait `Index<u32>` is not implemented for `[i32]`
+    //~| NOTE a usize is required
+    //~| NOTE required by
 }
diff --git a/src/test/compile-fail/on-unimplemented/on-trait.rs b/src/test/compile-fail/on-unimplemented/on-trait.rs
index 9ea2809374c..ef7695af3e1 100644
--- a/src/test/compile-fail/on-unimplemented/on-trait.rs
+++ b/src/test/compile-fail/on-unimplemented/on-trait.rs
@@ -35,9 +35,9 @@ pub fn main() {
     //~^ ERROR
     //~^^ NOTE a collection of type `std::option::Option<std::vec::Vec<u8>>` cannot be built from an iterator over elements of type `&u8`
     //~^^^ NOTE required by `collect`
-    //~| NOTE trait `std::option::Option<std::vec::Vec<u8>>: MyFromIterator<&u8>` not satisfied
+    //~| NOTE the trait `MyFromIterator<&u8>` is not implemented for `std::option::Option<std::vec::Vec<u8>>`
     let x: String = foobar(); //~ ERROR
     //~^ NOTE test error `std::string::String` with `u8` `_` `u32`
     //~^^ NOTE required by `foobar`
-    //~| NOTE trait `std::string::String: Foo<u8, _, u32>` not satisfied
+    //~| NOTE the trait `Foo<u8, _, u32>` is not implemented for `std::string::String`
 }
diff --git a/src/test/compile-fail/on-unimplemented/slice-index.rs b/src/test/compile-fail/on-unimplemented/slice-index.rs
index 5c548b5d5bf..d528d0e626a 100644
--- a/src/test/compile-fail/on-unimplemented/slice-index.rs
+++ b/src/test/compile-fail/on-unimplemented/slice-index.rs
@@ -17,10 +17,12 @@ use std::ops::Index;
 #[rustc_error]
 fn main() {
     let x = &[1, 2, 3] as &[i32];
-    x[1i32]; //~ ERROR E0277
-             //~| NOTE trait `[i32]: std::ops::Index<i32>` not satisfied
-             //~| NOTE slice indices are of type `usize`
-    x[..1i32]; //~ ERROR E0277
-               //~| NOTE trait `[i32]: std::ops::Index<std::ops::RangeTo<i32>>` not satisfied
-               //~| NOTE slice indices are of type `usize`
+    x[1i32];
+    //~^ ERROR E0277
+    //~| NOTE the trait `std::ops::Index<i32>` is not implemented for `[i32]`
+    //~| NOTE slice indices are of type `usize`
+    x[..1i32];
+    //~^ ERROR E0277
+    //~| NOTE the trait `std::ops::Index<std::ops::RangeTo<i32>>` is not implemented for `[i32]`
+    //~| NOTE slice indices are of type `usize`
 }
diff --git a/src/test/compile-fail/trait-suggest-where-clause.rs b/src/test/compile-fail/trait-suggest-where-clause.rs
index d15e3536d60..7530d8890b9 100644
--- a/src/test/compile-fail/trait-suggest-where-clause.rs
+++ b/src/test/compile-fail/trait-suggest-where-clause.rs
@@ -16,13 +16,13 @@ fn check<T: Iterator, U: ?Sized>() {
     // suggest a where-clause, if needed
     mem::size_of::<U>();
     //~^ ERROR `U: std::marker::Sized` is not satisfied
-    //~| NOTE trait `U: std::marker::Sized` not satisfied
+    //~| NOTE the trait `std::marker::Sized` is not implemented for `U`
     //~| HELP consider adding a `where U: std::marker::Sized` bound
     //~| NOTE required by `std::mem::size_of`
 
     mem::size_of::<Misc<U>>();
     //~^ ERROR `U: std::marker::Sized` is not satisfied
-    //~| NOTE trait `U: std::marker::Sized` not satisfied
+    //~| NOTE the trait `std::marker::Sized` is not implemented for `U`
     //~| HELP consider adding a `where U: std::marker::Sized` bound
     //~| NOTE required because it appears within the type `Misc<U>`
     //~| NOTE required by `std::mem::size_of`
@@ -31,13 +31,13 @@ fn check<T: Iterator, U: ?Sized>() {
 
     <u64 as From<T>>::from;
     //~^ ERROR `u64: std::convert::From<T>` is not satisfied
-    //~| NOTE trait `u64: std::convert::From<T>` not satisfied
+    //~| NOTE the trait `std::convert::From<T>` is not implemented for `u64`
     //~| HELP consider adding a `where u64: std::convert::From<T>` bound
     //~| NOTE required by `std::convert::From::from`
 
     <u64 as From<<T as Iterator>::Item>>::from;
     //~^ ERROR `u64: std::convert::From<<T as std::iter::Iterator>::Item>` is not satisfied
-    //~| NOTE trait `u64: std::convert::From<<T as std::iter::Iterator>::Item>` not satisfied
+    //~| NOTE the trait `std::convert::From<<T as std::iter::Iterator>::Item>` is not implemented
     //~| HELP consider adding a `where u64:
     //~| NOTE required by `std::convert::From::from`
 
@@ -45,20 +45,20 @@ fn check<T: Iterator, U: ?Sized>() {
 
     <Misc<_> as From<T>>::from;
     //~^ ERROR `Misc<_>: std::convert::From<T>` is not satisfied
-    //~| NOTE trait `Misc<_>: std::convert::From<T>` not satisfied
+    //~| NOTE the trait `std::convert::From<T>` is not implemented for `Misc<_>`
     //~| NOTE required by `std::convert::From::from`
 
     // ... and also not if the error is not related to the type
 
     mem::size_of::<[T]>();
     //~^ ERROR `[T]: std::marker::Sized` is not satisfied
-    //~| NOTE `[T]: std::marker::Sized` not satisfied
+    //~| NOTE the trait `std::marker::Sized` is not implemented for `[T]`
     //~| NOTE `[T]` does not have a constant size
     //~| NOTE required by `std::mem::size_of`
 
     mem::size_of::<[&U]>();
     //~^ ERROR `[&U]: std::marker::Sized` is not satisfied
-    //~| NOTE `[&U]: std::marker::Sized` not satisfied
+    //~| NOTE the trait `std::marker::Sized` is not implemented for `[&U]`
     //~| NOTE `[&U]` does not have a constant size
     //~| NOTE required by `std::mem::size_of`
 }