diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 9950560b13a5a..4725272d2b69a 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -670,10 +670,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { let mut err = match warning_node_id { Some(_) => None, None => { - Some(struct_span_err!( - self.sess, span, E0038, - "the trait `{}` cannot be made into an object", - self.item_path_str(trait_def_id))) + let trait_str = self.item_path_str(trait_def_id); + let mut db = struct_span_err!( + self.sess, span, E0038, + "the trait `{}` cannot be made into an object", + trait_str); + db.span_label(span, + &format!("the trait `{}` cannot be made \ + into an object", trait_str)); + Some(db) } }; diff --git a/src/test/compile-fail/E0038.rs b/src/test/compile-fail/E0038.rs index 26d2f339763aa..6cf3f1ebf19e4 100644 --- a/src/test/compile-fail/E0038.rs +++ b/src/test/compile-fail/E0038.rs @@ -12,7 +12,10 @@ trait Trait { fn foo(&self) -> Self; } -fn call_foo(x: Box) { //~ ERROR E0038 +fn call_foo(x: Box) { + //~^ ERROR E0038 + //~| NOTE the trait `Trait` cannot be made into an object + //~| NOTE method `foo` references the `Self` type in its arguments or return type let y = x.foo(); } diff --git a/src/test/compile-fail/issue-20692.rs b/src/test/compile-fail/issue-20692.rs index 1c9e588cb2cd1..3e44053875552 100644 --- a/src/test/compile-fail/issue-20692.rs +++ b/src/test/compile-fail/issue-20692.rs @@ -15,10 +15,12 @@ fn f(x: &T) { //~^ ERROR `Array` cannot be made into an object //~| NOTE the trait cannot require that `Self : Sized` //~| NOTE requirements on the impl of `std::ops::CoerceUnsized<&Array>` + //~| NOTE the trait `Array` cannot be made into an object as &Array; //~^ ERROR `Array` cannot be made into an object //~| NOTE the trait cannot require that `Self : Sized` + //~| NOTE the trait `Array` cannot be made into an object } fn main() {} diff --git a/src/test/compile-fail/issue-26056.rs b/src/test/compile-fail/issue-26056.rs index 4e9cbc4f283b4..ded685152d49b 100644 --- a/src/test/compile-fail/issue-26056.rs +++ b/src/test/compile-fail/issue-26056.rs @@ -28,6 +28,7 @@ impl Map for K { fn main() { let _ = &() as &Map; - //~^ ERROR the trait `Map` cannot be made into an object + //~^ ERROR E0038 //~| NOTE the trait cannot use `Self` as a type parameter + //~| NOTE the trait `Map` cannot be made into an object } diff --git a/src/test/compile-fail/object-safety-generics.rs b/src/test/compile-fail/object-safety-generics.rs index 5097e3d7b10d4..6174d45b898d6 100644 --- a/src/test/compile-fail/object-safety-generics.rs +++ b/src/test/compile-fail/object-safety-generics.rs @@ -24,12 +24,14 @@ trait Quux { fn make_bar(t: &T) -> &Bar { //~^ ERROR E0038 //~| NOTE method `bar` has generic type parameters + //~| NOTE the trait `Bar` cannot be made into an object t } fn make_bar_explicit(t: &T) -> &Bar { //~^ ERROR E0038 - //~^^ NOTE method `bar` has generic type parameters + //~| NOTE method `bar` has generic type parameters + //~| NOTE the trait `Bar` cannot be made into an object t as &Bar } diff --git a/src/test/compile-fail/object-safety-mentions-Self.rs b/src/test/compile-fail/object-safety-mentions-Self.rs index edd31c1f79649..d85614fa5b538 100644 --- a/src/test/compile-fail/object-safety-mentions-Self.rs +++ b/src/test/compile-fail/object-safety-mentions-Self.rs @@ -27,12 +27,14 @@ trait Quux { fn make_bar(t: &T) -> &Bar { //~^ ERROR E0038 //~| NOTE method `bar` references the `Self` type in its arguments or return type + //~| NOTE the trait `Bar` cannot be made into an object loop { } } fn make_baz(t: &T) -> &Baz { //~^ ERROR E0038 //~| NOTE method `bar` references the `Self` type in its arguments or return type + //~| NOTE the trait `Baz` cannot be made into an object t } diff --git a/src/test/compile-fail/object-safety-sized.rs b/src/test/compile-fail/object-safety-sized.rs index 501d61d20fed1..accd7fa87ac29 100644 --- a/src/test/compile-fail/object-safety-sized.rs +++ b/src/test/compile-fail/object-safety-sized.rs @@ -18,6 +18,7 @@ trait Bar : Sized { fn make_bar(t: &T) -> &Bar { //~^ ERROR E0038 //~| NOTE the trait cannot require that `Self : Sized` + //~| NOTE the trait `Bar` cannot be made into an object t } diff --git a/src/test/compile-fail/object-safety-supertrait-mentions-Self.rs b/src/test/compile-fail/object-safety-supertrait-mentions-Self.rs index 0a79ec30e4b94..74d1ad62f14c3 100644 --- a/src/test/compile-fail/object-safety-supertrait-mentions-Self.rs +++ b/src/test/compile-fail/object-safety-supertrait-mentions-Self.rs @@ -25,6 +25,7 @@ fn make_bar>(t: &T) -> &Bar { fn make_baz(t: &T) -> &Baz { //~^ ERROR E0038 //~| NOTE the trait cannot use `Self` as a type parameter in the supertrait listing + //~| NOTE the trait `Baz` cannot be made into an object t }