]> git.lizzy.rs Git - rust.git/commitdiff
On object safety violation, point at source when possible
authorEsteban Küber <esteban@kuber.com.ar>
Tue, 3 Sep 2019 03:22:22 +0000 (20:22 -0700)
committerEsteban Küber <esteban@kuber.com.ar>
Tue, 3 Sep 2019 03:22:22 +0000 (20:22 -0700)
26 files changed:
src/librustc/traits/error_reporting.rs
src/librustc/traits/object_safety.rs
src/test/ui/associated-const/associated-const-in-trait.stderr
src/test/ui/coherence/coherence-impl-trait-for-trait-object-safe.old.stderr
src/test/ui/coherence/coherence-impl-trait-for-trait-object-safe.re.stderr
src/test/ui/did_you_mean/issue-40006.stderr
src/test/ui/error-codes/E0033-teach.rs
src/test/ui/error-codes/E0033-teach.stderr
src/test/ui/error-codes/E0033.rs
src/test/ui/error-codes/E0033.stderr
src/test/ui/error-codes/E0038.stderr
src/test/ui/issues/issue-18959.stderr
src/test/ui/issues/issue-19380.stderr
src/test/ui/issues/issue-19538.stderr
src/test/ui/issues/issue-50781.stderr
src/test/ui/object-safety/object-safety-associated-consts.stderr
src/test/ui/object-safety/object-safety-generics.stderr
src/test/ui/object-safety/object-safety-mentions-Self.stderr
src/test/ui/object-safety/object-safety-no-static.stderr
src/test/ui/resolve/issue-3907-2.stderr
src/test/ui/self/arbitrary-self-types-not-object-safe.stderr
src/test/ui/traits/trait-item-privacy.stderr
src/test/ui/traits/trait-object-safety.stderr
src/test/ui/traits/trait-test-2.stderr
src/test/ui/type/type-parameter-defaults-referencing-Self-ppaux.stderr
src/test/ui/wf/wf-object-safe.stderr

index b38e1f5f83937808602c863b60b1f95fbce9e312..03cc00d87e3cd3091843b68545bb2e32672efc5e 100644 (file)
@@ -1384,7 +1384,10 @@ pub fn report_object_safety_error(
         let mut reported_violations = FxHashSet::default();
         for violation in violations {
             if reported_violations.insert(violation.clone()) {
-                err.note(&violation.error_msg());
+                match violation.span() {
+                    Some(span) => err.span_label(span, violation.error_msg()),
+                    None => err.note(&violation.error_msg()),
+                };
             }
         }
         Some(err)
index aac722b56a9831f417b80cdcb2a81318ee5a1623..50f497e302e6d68c815c4f03bb570def496f09a2 100644 (file)
@@ -32,10 +32,10 @@ pub enum ObjectSafetyViolation {
     SupertraitSelf,
 
     /// Method has something illegal.
-    Method(ast::Name, MethodViolationCode),
+    Method(ast::Name, MethodViolationCode, Span),
 
     /// Associated const.
-    AssocConst(ast::Name),
+    AssocConst(ast::Name, Span),
 }
 
 impl ObjectSafetyViolation {
@@ -46,24 +46,33 @@ pub fn error_msg(&self) -> Cow<'static, str> {
             ObjectSafetyViolation::SupertraitSelf =>
                 "the trait cannot use `Self` as a type parameter \
                  in the supertraits or where-clauses".into(),
-            ObjectSafetyViolation::Method(name, MethodViolationCode::StaticMethod) =>
+            ObjectSafetyViolation::Method(name, MethodViolationCode::StaticMethod, _) =>
                 format!("associated function `{}` has no `self` parameter", name).into(),
-            ObjectSafetyViolation::Method(name, MethodViolationCode::ReferencesSelf) => format!(
+            ObjectSafetyViolation::Method(name, MethodViolationCode::ReferencesSelf, _) => format!(
                 "method `{}` references the `Self` type in its arguments or return type",
                 name,
             ).into(),
             ObjectSafetyViolation::Method(
                 name,
-                MethodViolationCode::WhereClauseReferencesSelf(_),
+                MethodViolationCode::WhereClauseReferencesSelf,
+                _,
             ) => format!("method `{}` references the `Self` type in where clauses", name).into(),
-            ObjectSafetyViolation::Method(name, MethodViolationCode::Generic) =>
+            ObjectSafetyViolation::Method(name, MethodViolationCode::Generic, _) =>
                 format!("method `{}` has generic type parameters", name).into(),
-            ObjectSafetyViolation::Method(name, MethodViolationCode::UndispatchableReceiver) =>
+            ObjectSafetyViolation::Method(name, MethodViolationCode::UndispatchableReceiver, _) =>
                 format!("method `{}`'s receiver cannot be dispatched on", name).into(),
-            ObjectSafetyViolation::AssocConst(name) =>
+            ObjectSafetyViolation::AssocConst(name, _) =>
                 format!("the trait cannot contain associated consts like `{}`", name).into(),
         }
     }
+
+    pub fn span(&self) -> Option<Span> {
+        match self {
+            ObjectSafetyViolation::AssocConst(_, span) |
+            ObjectSafetyViolation::Method(_, _, span) => Some(*span),
+            _ => None,
+        }
+    }
 }
 
 /// Reasons a method might not be object-safe.
@@ -76,7 +85,7 @@ pub enum MethodViolationCode {
     ReferencesSelf,
 
     /// e.g., `fn foo(&self) where Self: Clone`
-    WhereClauseReferencesSelf(Span),
+    WhereClauseReferencesSelf,
 
     /// e.g., `fn foo<A>()`
     Generic,
@@ -90,9 +99,10 @@ impl<'tcx> TyCtxt<'tcx> {
     /// astconv -- currently, `Self` in supertraits. This is needed
     /// because `object_safety_violations` can't be used during
     /// type collection.
-    pub fn astconv_object_safety_violations(self, trait_def_id: DefId)
-                                            -> Vec<ObjectSafetyViolation>
-    {
+    pub fn astconv_object_safety_violations(
+        self,
+        trait_def_id: DefId,
+    ) -> Vec<ObjectSafetyViolation> {
         debug_assert!(self.generics_of(trait_def_id).has_self);
         let violations = traits::supertrait_def_ids(self, trait_def_id)
             .filter(|&def_id| self.predicates_reference_self(def_id, true))
@@ -130,7 +140,7 @@ pub fn is_vtable_safe_method(self, trait_def_id: DefId, method: &ty::AssocItem)
         }
 
         match self.virtual_call_violation_for_method(trait_def_id, method) {
-            None | Some(MethodViolationCode::WhereClauseReferencesSelf(_)) => true,
+            None | Some(MethodViolationCode::WhereClauseReferencesSelf) => true,
             Some(_) => false,
         }
     }
@@ -140,12 +150,15 @@ fn object_safety_violations_for_trait(self, trait_def_id: DefId) -> Vec<ObjectSa
         let mut violations: Vec<_> = self.associated_items(trait_def_id)
             .filter(|item| item.kind == ty::AssocKind::Method)
             .filter_map(|item|
-                self.object_safety_violation_for_method(trait_def_id, &item)
-                    .map(|code| ObjectSafetyViolation::Method(item.ident.name, code))
+                self.object_safety_violation_for_method(trait_def_id, &item).map(|code| {
+                    ObjectSafetyViolation::Method(item.ident.name, code, item.ident.span)
+                })
             ).filter(|violation| {
-                if let ObjectSafetyViolation::Method(_,
-                    MethodViolationCode::WhereClauseReferencesSelf(span)) = violation
-                {
+                if let ObjectSafetyViolation::Method(
+                    _,
+                    MethodViolationCode::WhereClauseReferencesSelf,
+                    span,
+                ) = violation {
                     // Using `CRATE_NODE_ID` is wrong, but it's hard to get a more precise id.
                     // It's also hard to get a use site span, so we use the method definition span.
                     self.lint_node_note(
@@ -171,7 +184,7 @@ fn object_safety_violations_for_trait(self, trait_def_id: DefId) -> Vec<ObjectSa
 
         violations.extend(self.associated_items(trait_def_id)
             .filter(|item| item.kind == ty::AssocKind::Const)
-            .map(|item| ObjectSafetyViolation::AssocConst(item.ident.name)));
+            .map(|item| ObjectSafetyViolation::AssocConst(item.ident.name, item.ident.span)));
 
         debug!("object_safety_violations_for_trait(trait_def_id={:?}) = {:?}",
                trait_def_id,
@@ -327,8 +340,7 @@ fn virtual_call_violation_for_method(
                 .visit_tys_shallow(|t| {
                     self.contains_illegal_self_type_reference(trait_def_id, t)
                 }) {
-            let span = self.def_span(method.def_id);
-            return Some(MethodViolationCode::WhereClauseReferencesSelf(span));
+            return Some(MethodViolationCode::WhereClauseReferencesSelf);
         }
 
         let receiver_ty = self.liberate_late_bound_regions(
index dff268a55c909dd6e3e945e454459005a48661d4..a5d7fc5b7024685e0d7d9b677bb7a6853f3f8934 100644 (file)
@@ -1,10 +1,11 @@
 error[E0038]: the trait `Trait` cannot be made into an object
   --> $DIR/associated-const-in-trait.rs:9:6
    |
+LL |     const N: usize;
+   |           - the trait cannot contain associated consts like `N`
+...
 LL | impl dyn Trait {
    |      ^^^^^^^^^ the trait `Trait` cannot be made into an object
-   |
-   = note: the trait cannot contain associated consts like `N`
 
 error: aborting due to previous error
 
index c38d7456a995219eed1a3848c044b1eaa133784a..2626eab3cbf23388a6ce1c3913980f1b0bd40089 100644 (file)
@@ -1,10 +1,10 @@
 error[E0038]: the trait `NotObjectSafe` cannot be made into an object
   --> $DIR/coherence-impl-trait-for-trait-object-safe.rs:11:6
    |
+LL | trait NotObjectSafe { fn eq(&self, other: Self); }
+   |                          -- method `eq` references the `Self` type in its arguments or return type
 LL | impl NotObjectSafe for dyn NotObjectSafe { }
    |      ^^^^^^^^^^^^^ the trait `NotObjectSafe` cannot be made into an object
-   |
-   = note: method `eq` references the `Self` type in its arguments or return type
 
 error: aborting due to previous error
 
index c38d7456a995219eed1a3848c044b1eaa133784a..2626eab3cbf23388a6ce1c3913980f1b0bd40089 100644 (file)
@@ -1,10 +1,10 @@
 error[E0038]: the trait `NotObjectSafe` cannot be made into an object
   --> $DIR/coherence-impl-trait-for-trait-object-safe.rs:11:6
    |
+LL | trait NotObjectSafe { fn eq(&self, other: Self); }
+   |                          -- method `eq` references the `Self` type in its arguments or return type
 LL | impl NotObjectSafe for dyn NotObjectSafe { }
    |      ^^^^^^^^^^^^^ the trait `NotObjectSafe` cannot be made into an object
-   |
-   = note: method `eq` references the `Self` type in its arguments or return type
 
 error: aborting due to previous error
 
index 6f219a6e0b1feabbd5c96ea660904dece1961b76..5b384045a486abce4305ac22682809efd07ead89 100644 (file)
@@ -61,8 +61,9 @@ error[E0038]: the trait `X` cannot be made into an object
    |
 LL | impl dyn X {
    |      ^^^^^ the trait `X` cannot be made into an object
-   |
-   = note: associated function `xxx` has no `self` parameter
+...
+LL |     fn xxx() { ### }
+   |        --- associated function `xxx` has no `self` parameter
 
 error: aborting due to 9 previous errors
 
index 9b5e719781281769cd8e18ef1d0e69e0f721c228..19439651394234071986e9fd56e3f16f9a4b1a12 100644 (file)
@@ -1,14 +1,13 @@
 // compile-flags: -Z teach
 
 trait SomeTrait {
-    fn foo();
+    fn foo(); //~ associated function `foo` has no `self` parameter
 }
 
 fn main() {
     let trait_obj: &dyn SomeTrait = SomeTrait;
     //~^ ERROR expected value, found trait `SomeTrait`
     //~| ERROR E0038
-    //~| associated function `foo` has no `self` parameter
 
     let &invalid = trait_obj;
     //~^ ERROR E0033
index 1d4c2d788a43b7a04ae69a1e973e7e1cc9e01e96..80f3d4441bd9faf6acfd0bc1350aa7b79a8cedc4 100644 (file)
@@ -7,13 +7,14 @@ LL |     let trait_obj: &dyn SomeTrait = SomeTrait;
 error[E0038]: the trait `SomeTrait` cannot be made into an object
   --> $DIR/E0033-teach.rs:8:20
    |
+LL |     fn foo();
+   |        --- associated function `foo` has no `self` parameter
+...
 LL |     let trait_obj: &dyn SomeTrait = SomeTrait;
    |                    ^^^^^^^^^^^^^^ the trait `SomeTrait` cannot be made into an object
-   |
-   = note: associated function `foo` has no `self` parameter
 
 error[E0033]: type `&dyn SomeTrait` cannot be dereferenced
-  --> $DIR/E0033-teach.rs:13:9
+  --> $DIR/E0033-teach.rs:12:9
    |
 LL |     let &invalid = trait_obj;
    |         ^^^^^^^^ type `&dyn SomeTrait` cannot be dereferenced
index 86dacfd1a47ba3d0ba1866a32c597e2d983472ee..e5f0530f45ff86ae0a5550512d394184db90fe58 100644 (file)
@@ -1,12 +1,11 @@
 trait SomeTrait {
-    fn foo();
+    fn foo(); //~ associated function `foo` has no `self` parameter
 }
 
 fn main() {
     let trait_obj: &dyn SomeTrait = SomeTrait;
     //~^ ERROR expected value, found trait `SomeTrait`
     //~| ERROR E0038
-    //~| associated function `foo` has no `self` parameter
 
     let &invalid = trait_obj;
     //~^ ERROR E0033
index 803d7917e5638b59decfebd244d51941ff335d23..c2843796cc851b82c578555ab57ccfbf1ce9dc66 100644 (file)
@@ -7,13 +7,14 @@ LL |     let trait_obj: &dyn SomeTrait = SomeTrait;
 error[E0038]: the trait `SomeTrait` cannot be made into an object
   --> $DIR/E0033.rs:6:20
    |
+LL |     fn foo();
+   |        --- associated function `foo` has no `self` parameter
+...
 LL |     let trait_obj: &dyn SomeTrait = SomeTrait;
    |                    ^^^^^^^^^^^^^^ the trait `SomeTrait` cannot be made into an object
-   |
-   = note: associated function `foo` has no `self` parameter
 
 error[E0033]: type `&dyn SomeTrait` cannot be dereferenced
-  --> $DIR/E0033.rs:11:9
+  --> $DIR/E0033.rs:10:9
    |
 LL |     let &invalid = trait_obj;
    |         ^^^^^^^^ type `&dyn SomeTrait` cannot be dereferenced
index e3d7593e42a7105b4e9f670a9c95be081a9d6728..93a7681393b29eef11602d8dae5ea3416ee3ee14 100644 (file)
@@ -1,10 +1,11 @@
 error[E0038]: the trait `Trait` cannot be made into an object
   --> $DIR/E0038.rs:5:1
    |
+LL |     fn foo(&self) -> Self;
+   |        --- method `foo` references the `Self` type in its arguments or return type
+...
 LL | fn call_foo(x: Box<dyn Trait>) {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` cannot be made into an object
-   |
-   = note: method `foo` references the `Self` type in its arguments or return type
 
 error: aborting due to previous error
 
index 63c33b7f4472d298f565c17b38e63bb4ac5b7834..d5e7092801ecd9b3806bc9fa5360f7b39940b20e 100644 (file)
@@ -1,10 +1,11 @@
 error[E0038]: the trait `Bar` cannot be made into an object
   --> $DIR/issue-18959.rs:11:1
    |
+LL | pub trait Foo { fn foo<T>(&self, ext_thing: &T); }
+   |                    --- method `foo` has generic type parameters
+...
 LL | fn foo(b: &dyn Bar) {
    | ^^^^^^^^^^^^^^^^^^^ the trait `Bar` cannot be made into an object
-   |
-   = note: method `foo` has generic type parameters
 
 error: aborting due to previous error
 
index d70a7c2b5299c6bbf6a2ce67a7c3fe47a3f055ed..92bfdf1f26e93828b4eb0796d05086b17dc7826d 100644 (file)
@@ -1,10 +1,11 @@
 error[E0038]: the trait `Qiz` cannot be made into an object
   --> $DIR/issue-19380.rs:11:3
    |
+LL |   fn qiz();
+   |      --- associated function `qiz` has no `self` parameter
+...
 LL |   foos: &'static [&'static (dyn Qiz + 'static)]
    |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Qiz` cannot be made into an object
-   |
-   = note: associated function `qiz` has no `self` parameter
 
 error: aborting due to previous error
 
index e5da0a9b0dac38e2f92cd3dc8b3b6aa84610dcfb..5415a45f7d621c41812f53ed39eb7bd0ed9fae59 100644 (file)
@@ -1,18 +1,21 @@
 error[E0038]: the trait `Bar` cannot be made into an object
   --> $DIR/issue-19538.rs:17:15
    |
+LL |     fn foo<T>(&self, val: T);
+   |        --- method `foo` has generic type parameters
+...
 LL |     let test: &mut dyn Bar = &mut thing;
    |               ^^^^^^^^^^^^ the trait `Bar` cannot be made into an object
-   |
-   = note: method `foo` has generic type parameters
 
 error[E0038]: the trait `Bar` cannot be made into an object
   --> $DIR/issue-19538.rs:17:30
    |
+LL |     fn foo<T>(&self, val: T);
+   |        --- method `foo` has generic type parameters
+...
 LL |     let test: &mut dyn Bar = &mut thing;
    |                              ^^^^^^^^^^ the trait `Bar` cannot be made into an object
    |
-   = note: method `foo` has generic type parameters
    = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<&mut dyn Bar>` for `&mut Thing`
 
 error: aborting due to 2 previous errors
index c98f78c51ee5f02e0b3c6d2211d5ccec0c15c73d..02475ea97e3d1fe81fd8a95851f873912b24bffc 100644 (file)
@@ -1,8 +1,8 @@
 error: the trait `X` cannot be made into an object
-  --> $DIR/issue-50781.rs:6:5
+  --> $DIR/issue-50781.rs:6:8
    |
 LL |     fn foo(&self) where Self: Trait;
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |        ^^^
    |
 note: lint level defined here
   --> $DIR/issue-50781.rs:1:9
index 55f9e3f9f138bd812f8dbe6d19fcdeec9a13ceb1..7d5aa00356e0b5b767cedf8af3c89e84c12d41f4 100644 (file)
@@ -1,10 +1,11 @@
 error[E0038]: the trait `Bar` cannot be made into an object
   --> $DIR/object-safety-associated-consts.rs:9:1
    |
+LL |     const X: usize;
+   |           - the trait cannot contain associated consts like `X`
+...
 LL | fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar` cannot be made into an object
-   |
-   = note: the trait cannot contain associated consts like `X`
 
 error: aborting due to previous error
 
index d66cdb98448d4edddb36b7f04a72e90645705553..b25e0052e4163f98c46a95c955af2671a7b68cad 100644 (file)
@@ -1,18 +1,20 @@
 error[E0038]: the trait `Bar` cannot be made into an object
   --> $DIR/object-safety-generics.rs:14:1
    |
+LL |     fn bar<T>(&self, t: T);
+   |        --- method `bar` has generic type parameters
+...
 LL | fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar` cannot be made into an object
-   |
-   = note: method `bar` has generic type parameters
 
 error[E0038]: the trait `Bar` cannot be made into an object
   --> $DIR/object-safety-generics.rs:19:1
    |
+LL |     fn bar<T>(&self, t: T);
+   |        --- method `bar` has generic type parameters
+...
 LL | fn make_bar_explicit<T:Bar>(t: &T) -> &dyn Bar {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar` cannot be made into an object
-   |
-   = note: method `bar` has generic type parameters
 
 error: aborting due to 2 previous errors
 
index c0c471c2b1e72893489503629c638005fc371d3e..e2d1e773809bbd55b4251f1f288680c2c96677e6 100644 (file)
@@ -1,18 +1,20 @@
 error[E0038]: the trait `Bar` cannot be made into an object
   --> $DIR/object-safety-mentions-Self.rs:17:1
    |
+LL |     fn bar(&self, x: &Self);
+   |        --- method `bar` references the `Self` type in its arguments or return type
+...
 LL | fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar` cannot be made into an object
-   |
-   = note: method `bar` references the `Self` type in its arguments or return type
 
 error[E0038]: the trait `Baz` cannot be made into an object
   --> $DIR/object-safety-mentions-Self.rs:22:1
    |
+LL |     fn bar(&self) -> Self;
+   |        --- method `bar` references the `Self` type in its arguments or return type
+...
 LL | fn make_baz<T:Baz>(t: &T) -> &dyn Baz {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Baz` cannot be made into an object
-   |
-   = note: method `bar` references the `Self` type in its arguments or return type
 
 error: aborting due to 2 previous errors
 
index c189c358b422340458fc873d7f589a4606fc64c5..0de783f60ea4743fd9c5a61ecc14c1a5bcdf502a 100644 (file)
@@ -1,10 +1,11 @@
 error[E0038]: the trait `Foo` cannot be made into an object
   --> $DIR/object-safety-no-static.rs:8:1
    |
+LL |     fn foo();
+   |        --- associated function `foo` has no `self` parameter
+...
 LL | fn foo_implicit<T:Foo+'static>(b: Box<T>) -> Box<dyn Foo + 'static> {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` cannot be made into an object
-   |
-   = note: associated function `foo` has no `self` parameter
 
 error: aborting due to previous error
 
index 63ac11dc8ae01b463a4269b14dbbdd3ca092fd8e..087d1a5b9d3656e2b96aaee5fca1ec90ff76889d 100644 (file)
@@ -3,8 +3,6 @@ error[E0038]: the trait `issue_3907::Foo` cannot be made into an object
    |
 LL | fn bar(_x: Foo) {}
    | ^^^^^^^^^^^^^^^ the trait `issue_3907::Foo` cannot be made into an object
-   |
-   = note: associated function `bar` has no `self` parameter
 
 error: aborting due to previous error
 
index e45bc2657f1ea03534d5e3b1490de3489ac239f6..9fb1500afce47aa9fa10bc8deadf76246e44bf42 100644 (file)
@@ -1,18 +1,21 @@
 error[E0038]: the trait `Foo` cannot be made into an object
   --> $DIR/arbitrary-self-types-not-object-safe.rs:31:32
    |
+LL |     fn foo(self: &Rc<Self>) -> usize;
+   |        --- method `foo`'s receiver cannot be dispatched on
+...
 LL |     let x = Rc::new(5usize) as Rc<dyn Foo>;
    |                                ^^^^^^^^^^^ the trait `Foo` cannot be made into an object
-   |
-   = note: method `foo`'s receiver cannot be dispatched on
 
 error[E0038]: the trait `Foo` cannot be made into an object
   --> $DIR/arbitrary-self-types-not-object-safe.rs:31:13
    |
+LL |     fn foo(self: &Rc<Self>) -> usize;
+   |        --- method `foo`'s receiver cannot be dispatched on
+...
 LL |     let x = Rc::new(5usize) as Rc<dyn Foo>;
    |             ^^^^^^^^^^^^^^^ the trait `Foo` cannot be made into an object
    |
-   = note: method `foo`'s receiver cannot be dispatched on
    = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<std::rc::Rc<dyn Foo>>` for `std::rc::Rc<usize>`
 
 error: aborting due to 2 previous errors
index de699a69fa8bc08a97b49e6177364499ed21bcc3..aec648d7b8473d0561d99a87b82bf773f80ae7f6 100644 (file)
@@ -103,12 +103,17 @@ LL |     C::A;
 error[E0038]: the trait `assoc_const::C` cannot be made into an object
   --> $DIR/trait-item-privacy.rs:101:5
    |
+LL |         const A: u8 = 0;
+   |               - the trait cannot contain associated consts like `A`
+...
+LL |         const B: u8 = 0;
+   |               - the trait cannot contain associated consts like `B`
+...
+LL |         const C: u8 = 0;
+   |               - the trait cannot contain associated consts like `C`
+...
 LL |     C::A;
    |     ^^^^ the trait `assoc_const::C` cannot be made into an object
-   |
-   = note: the trait cannot contain associated consts like `C`
-   = note: the trait cannot contain associated consts like `B`
-   = note: the trait cannot contain associated consts like `A`
 
 error[E0223]: ambiguous associated type
   --> $DIR/trait-item-privacy.rs:115:12
index 7f6bc0ebb70e51985242375a0bbbcab7daff9925..3ac1e96b30c95121989a9d3fdd11a980864f3a6b 100644 (file)
@@ -1,19 +1,22 @@
 error[E0038]: the trait `Tr` cannot be made into an object
   --> $DIR/trait-object-safety.rs:15:22
    |
+LL |     fn foo();
+   |        --- associated function `foo` has no `self` parameter
+...
 LL |     let _: &dyn Tr = &St;
    |                      ^^^ the trait `Tr` cannot be made into an object
    |
-   = note: associated function `foo` has no `self` parameter
    = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<&dyn Tr>` for `&St`
 
 error[E0038]: the trait `Tr` cannot be made into an object
   --> $DIR/trait-object-safety.rs:15:12
    |
+LL |     fn foo();
+   |        --- associated function `foo` has no `self` parameter
+...
 LL |     let _: &dyn Tr = &St;
    |            ^^^^^^^ the trait `Tr` cannot be made into an object
-   |
-   = note: associated function `foo` has no `self` parameter
 
 error: aborting due to 2 previous errors
 
index 5d5251925a1ae5bdf56c4d26ad0266879a288076..4d2aca0d4094ac6ae243e6eb625a48cf54bcdb1b 100644 (file)
@@ -13,20 +13,25 @@ LL |     10.blah::<i32, i32>();
 error[E0038]: the trait `bar` cannot be made into an object
   --> $DIR/trait-test-2.rs:11:16
    |
+LL | trait bar { fn dup(&self) -> Self; fn blah<X>(&self); }
+   |                ---                    ---- method `blah` has generic type parameters
+   |                |
+   |                method `dup` references the `Self` type in its arguments or return type
+...
 LL |     (box 10 as Box<dyn bar>).dup();
    |                ^^^^^^^^^^^^ the trait `bar` cannot be made into an object
-   |
-   = note: method `dup` references the `Self` type in its arguments or return type
-   = note: method `blah` has generic type parameters
 
 error[E0038]: the trait `bar` cannot be made into an object
   --> $DIR/trait-test-2.rs:11:6
    |
+LL | trait bar { fn dup(&self) -> Self; fn blah<X>(&self); }
+   |                ---                    ---- method `blah` has generic type parameters
+   |                |
+   |                method `dup` references the `Self` type in its arguments or return type
+...
 LL |     (box 10 as Box<dyn bar>).dup();
    |      ^^^^^^ the trait `bar` cannot be made into an object
    |
-   = note: method `dup` references the `Self` type in its arguments or return type
-   = note: method `blah` has generic type parameters
    = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<std::boxed::Box<dyn bar>>` for `std::boxed::Box<{integer}>`
 
 error: aborting due to 4 previous errors
index 58727ea0fef99646207d4b67678f1f98ed3c5cd5..03df5b821188952e0501df7d66db395cf5f9db1c 100644 (file)
@@ -13,10 +13,11 @@ LL |     let y = x as dyn MyAdd<i32>;
 error[E0038]: the trait `MyAdd` cannot be made into an object
   --> $DIR/type-parameter-defaults-referencing-Self-ppaux.rs:14:18
    |
+LL | trait MyAdd<Rhs=Self> { fn add(&self, other: &Rhs) -> Self; }
+   |                            --- method `add` references the `Self` type in its arguments or return type
+...
 LL |     let y = x as dyn MyAdd<i32>;
    |                  ^^^^^^^^^^^^^^ the trait `MyAdd` cannot be made into an object
-   |
-   = note: method `add` references the `Self` type in its arguments or return type
 
 error: aborting due to 2 previous errors
 
index 3b264ecd580ecb77367676784835ec90a120b735..d11af11f05051fff63b9e30eb9bb9488c918311e 100644 (file)
@@ -1,10 +1,11 @@
 error[E0038]: the trait `A` cannot be made into an object
   --> $DIR/wf-object-safe.rs:9:13
    |
+LL |     fn foo(&self, _x: &Self);
+   |        --- method `foo` references the `Self` type in its arguments or return type
+...
 LL |     let _x: &dyn A;
    |             ^^^^^^ the trait `A` cannot be made into an object
-   |
-   = note: method `foo` references the `Self` type in its arguments or return type
 
 error: aborting due to previous error