]> git.lizzy.rs Git - rust.git/commitdiff
Wording changes to object unsafe trait errors
authorEsteban Küber <esteban@kuber.com.ar>
Sat, 1 Feb 2020 00:47:00 +0000 (16:47 -0800)
committerEsteban Küber <esteban@kuber.com.ar>
Sun, 2 Feb 2020 19:53:10 +0000 (11:53 -0800)
Stemming from the thread at https://twitter.com/indygreg/status/1223279056398929920

51 files changed:
src/librustc/traits/error_reporting/mod.rs
src/librustc/traits/object_safety.rs
src/test/ui/associated-const/associated-const-in-trait.stderr
src/test/ui/associated-item/issue-48027.stderr
src/test/ui/coherence/coherence-impl-trait-for-trait-object-safe.stderr
src/test/ui/did_you_mean/trait-object-reference-without-parens-suggestion.stderr
src/test/ui/error-codes/E0033-teach.stderr
src/test/ui/error-codes/E0033.stderr
src/test/ui/error-codes/E0038.stderr
src/test/ui/feature-gates/feature-gate-object_safe_for_dispatch.stderr
src/test/ui/impl-trait/object-unsafe-trait-in-return-position-dyn-trait.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-20692.stderr
src/test/ui/issues/issue-26056.stderr
src/test/ui/issues/issue-28576.stderr
src/test/ui/issues/issue-38404.stderr
src/test/ui/issues/issue-38604.stderr
src/test/ui/issues/issue-50781.stderr
src/test/ui/kindck/kindck-inherited-copy-bound.curr.stderr
src/test/ui/kindck/kindck-inherited-copy-bound.object_safe_for_dispatch.stderr
src/test/ui/object-safety/object-safety-associated-consts.curr.stderr
src/test/ui/object-safety/object-safety-associated-consts.object_safe_for_dispatch.stderr
src/test/ui/object-safety/object-safety-generics.curr.stderr
src/test/ui/object-safety/object-safety-generics.object_safe_for_dispatch.stderr
src/test/ui/object-safety/object-safety-issue-22040.stderr
src/test/ui/object-safety/object-safety-mentions-Self.curr.stderr
src/test/ui/object-safety/object-safety-mentions-Self.object_safe_for_dispatch.stderr
src/test/ui/object-safety/object-safety-no-static.curr.stderr
src/test/ui/object-safety/object-safety-no-static.object_safe_for_dispatch.stderr
src/test/ui/object-safety/object-safety-sized-2.curr.stderr
src/test/ui/object-safety/object-safety-sized-2.object_safe_for_dispatch.stderr
src/test/ui/object-safety/object-safety-sized.curr.stderr
src/test/ui/object-safety/object-safety-sized.object_safe_for_dispatch.stderr
src/test/ui/object-safety/object-safety-supertrait-mentions-Self.stderr
src/test/ui/resolve/issue-3907-2.stderr
src/test/ui/self/arbitrary-self-types-not-object-safe.curr.stderr
src/test/ui/self/arbitrary-self-types-not-object-safe.object_safe_for_dispatch.stderr
src/test/ui/suggestions/object-unsafe-trait-should-use-self.stderr
src/test/ui/traits/trait-alias/trait-alias-object-fail.stderr
src/test/ui/traits/trait-item-privacy.stderr
src/test/ui/traits/trait-object-macro-matcher.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-convert-unsafe-trait-obj-box.stderr
src/test/ui/wf/wf-convert-unsafe-trait-obj.stderr
src/test/ui/wf/wf-fn-where-clause.stderr
src/test/ui/wf/wf-object-safe.stderr
src/test/ui/wf/wf-unsafe-trait-obj-match.stderr

index f15fa779534e0c9dd8b316eefeed85b20549d109..f2cc8a303a95216f2d35650bb947bf712aada14c 100644 (file)
@@ -1034,6 +1034,10 @@ pub fn report_object_safety_error(
     violations: Vec<ObjectSafetyViolation>,
 ) -> DiagnosticBuilder<'tcx> {
     let trait_str = tcx.def_path_str(trait_def_id);
+    let trait_span = tcx.hir().get_if_local(trait_def_id).and_then(|node| match node {
+        hir::Node::Item(item) => Some(item.ident.span),
+        _ => None,
+    });
     let span = tcx.sess.source_map().def_span(span);
     let mut err = struct_span_err!(
         tcx.sess,
@@ -1045,6 +1049,7 @@ pub fn report_object_safety_error(
     err.span_label(span, format!("the trait `{}` cannot be made into an object", trait_str));
 
     let mut reported_violations = FxHashSet::default();
+    let mut had_span_label = false;
     for violation in violations {
         if let ObjectSafetyViolation::SizedSelf(sp) = &violation {
             if !sp.is_empty() {
@@ -1055,15 +1060,28 @@ pub fn report_object_safety_error(
         }
         if reported_violations.insert(violation.clone()) {
             let spans = violation.spans();
+            let msg = if trait_span.is_none() || spans.is_empty() {
+                format!("the trait cannot be made into an object because {}", violation.error_msg())
+            } else {
+                had_span_label = true;
+                format!("...because {}", violation.error_msg())
+            };
             if spans.is_empty() {
-                err.note(&violation.error_msg());
+                err.note(&msg);
             } else {
                 for span in spans {
-                    err.span_label(span, violation.error_msg());
+                    err.span_label(span, &msg);
                 }
             }
+            if let (Some(_), Some(note)) = (trait_span, violation.solution()) {
+                // Only provide the help if its a local trait, otherwise it's not actionable.
+                err.help(&note);
+            }
         }
     }
+    if let (Some(trait_span), true) = (trait_span, had_span_label) {
+        err.span_label(trait_span, "this trait cannot be made into an object...");
+    }
 
     if tcx.sess.trait_methods_not_found.borrow().contains(&span) {
         // Avoid emitting error caused by non-existing method (#58734)
index dec9ef4f4216f242ee4cc452b183cbb396e4f601..ac9e4950b72cf22640bcd68cd2b9211239ec0628 100644 (file)
@@ -43,12 +43,9 @@ pub enum ObjectSafetyViolation {
 impl ObjectSafetyViolation {
     pub fn error_msg(&self) -> Cow<'static, str> {
         match *self {
-            ObjectSafetyViolation::SizedSelf(_) => {
-                "traits that require `Self: Sized` cannot be made into an object".into()
-            }
+            ObjectSafetyViolation::SizedSelf(_) => "it requires `Self: Sized`".into(),
             ObjectSafetyViolation::SupertraitSelf => {
-                "the trait cannot use `Self` as a type parameter \
-                 in the supertraits or where-clauses"
+                "it cannot use `Self` as a type parameter in the supertraits or `where`-clauses"
                     .into()
             }
             ObjectSafetyViolation::Method(name, MethodViolationCode::StaticMethod, _) => {
@@ -63,19 +60,45 @@ pub fn error_msg(&self) -> Cow<'static, str> {
                 name,
                 MethodViolationCode::WhereClauseReferencesSelf,
                 _,
-            ) => format!("method `{}` references the `Self` type in where clauses", name).into(),
+            ) => {
+                format!("method `{}` references the `Self` type in its `where` clause", name).into()
+            }
             ObjectSafetyViolation::Method(name, MethodViolationCode::Generic, _) => {
                 format!("method `{}` has generic type parameters", name).into()
             }
             ObjectSafetyViolation::Method(name, MethodViolationCode::UndispatchableReceiver, _) => {
                 format!("method `{}`'s `self` parameter cannot be dispatched on", name).into()
             }
+            ObjectSafetyViolation::AssocConst(_, DUMMY_SP) => {
+                "it cannot contain associated consts".into()
+            }
             ObjectSafetyViolation::AssocConst(name, _) => {
-                format!("the trait cannot contain associated consts like `{}`", name).into()
+                format!("it cannot contain associated consts like `{}`", name).into()
             }
         }
     }
 
+    pub fn solution(&self) -> Option<String> {
+        Some(match *self {
+            ObjectSafetyViolation::SizedSelf(_) | ObjectSafetyViolation::SupertraitSelf => {
+                return None;
+            }
+            ObjectSafetyViolation::Method(name, MethodViolationCode::StaticMethod, _) => format!(
+                "consider turning `{}` into a method by giving it a `&self` argument or \
+                 constraining it with `where Self: Sized`",
+                name
+            ),
+            ObjectSafetyViolation::Method(name, MethodViolationCode::UndispatchableReceiver, _) => {
+                format!("consider changing method `{}`'s `self` parameter to be `&self`", name)
+                    .into()
+            }
+            ObjectSafetyViolation::AssocConst(name, _)
+            | ObjectSafetyViolation::Method(name, ..) => {
+                format!("consider moving `{}` to another trait", name)
+            }
+        })
+    }
+
     pub fn spans(&self) -> SmallVec<[Span; 1]> {
         // When `span` comes from a separate crate, it'll be `DUMMY_SP`. Treat it as `None` so
         // diagnostics use a `note` instead of a `span_label`.
@@ -190,7 +213,21 @@ fn object_safety_violations_for_trait(
                         tcx.def_path_str(trait_def_id)
                     ),
                 );
-                err.span_label(*span, violation.error_msg());
+                let node = tcx.hir().get_if_local(trait_def_id);
+                let msg = if let Some(hir::Node::Item(item)) = node {
+                    err.span_label(item.ident.span, "this trait cannot be made into an object...");
+                    format!("...because {}", violation.error_msg())
+                } else {
+                    format!(
+                        "the trait cannot be made into an object because {}",
+                        violation.error_msg()
+                    )
+                };
+                err.span_label(*span, &msg);
+                if let (Some(_), Some(note)) = (node, violation.solution()) {
+                    // Only provide the help if its a local trait, otherwise it's not actionable.
+                    err.help(&note);
+                }
                 err.emit();
                 false
             } else {
index a5d7fc5b7024685e0d7d9b677bb7a6853f3f8934..b9101c86d218a8128a685782f3468b43cc56313a 100644 (file)
@@ -1,11 +1,15 @@
 error[E0038]: the trait `Trait` cannot be made into an object
   --> $DIR/associated-const-in-trait.rs:9:6
    |
+LL | trait Trait {
+   |       ----- this trait cannot be made into an object...
 LL |     const N: usize;
-   |           - the trait cannot contain associated consts like `N`
+   |           - ...because it cannot contain associated consts like `N`
 ...
 LL | impl dyn Trait {
    |      ^^^^^^^^^ the trait `Trait` cannot be made into an object
+   |
+   = help: consider moving `N` to another trait
 
 error: aborting due to previous error
 
index ddabd552897a8e79eb25480f014522732e2ead71..e8442c6c9ac149d0da4ba61423c0753b84ec3132 100644 (file)
@@ -1,11 +1,15 @@
 error[E0038]: the trait `Bar` cannot be made into an object
   --> $DIR/issue-48027.rs:6:6
    |
+LL | trait Bar {
+   |       --- this trait cannot be made into an object...
 LL |     const X: usize;
-   |           - the trait cannot contain associated consts like `X`
+   |           - ...because it cannot contain associated consts like `X`
 ...
 LL | impl dyn Bar {}
    |      ^^^^^^^ the trait `Bar` cannot be made into an object
+   |
+   = help: consider moving `X` to another trait
 
 error[E0283]: type annotations needed
   --> $DIR/issue-48027.rs:3:32
index ed6be60de460cb14f7531bf10d9f955e9fa5678e..c999cabcc14132815618fa4a196d87945b6a1b2f 100644 (file)
@@ -2,9 +2,13 @@ error[E0038]: the trait `NotObjectSafe` cannot be made into an object
   --> $DIR/coherence-impl-trait-for-trait-object-safe.rs:7:6
    |
 LL | trait NotObjectSafe { fn eq(&self, other: Self); }
-   |                          -- method `eq` references the `Self` type in its parameters or return type
+   |       -------------      -- ...because method `eq` references the `Self` type in its parameters or return type
+   |       |
+   |       this trait cannot be made into an object...
 LL | impl NotObjectSafe for dyn NotObjectSafe { }
    |      ^^^^^^^^^^^^^ the trait `NotObjectSafe` cannot be made into an object
+   |
+   = help: consider moving `eq` to another trait
 
 error: aborting due to previous error
 
index 070917f2db98a6d28f2c265b05b32c1f009d760c..333754891c16457cdfcdb1b41164f175b6b79e76 100644 (file)
@@ -16,7 +16,7 @@ error[E0038]: the trait `std::marker::Copy` cannot be made into an object
 LL |     let _: &Copy + 'static;
    |            ^^^^^ the trait `std::marker::Copy` cannot be made into an object
    |
-   = note: traits that require `Self: Sized` cannot be made into an object
+   = note: the trait cannot be made into an object because it requires `Self: Sized`
 
 error: aborting due to 3 previous errors
 
index 80f3d4441bd9faf6acfd0bc1350aa7b79a8cedc4..050ea63aa4fa8a8ab9b7bcfd2c66e9054b387775 100644 (file)
@@ -7,11 +7,15 @@ 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 | trait SomeTrait {
+   |       --------- this trait cannot be made into an object...
 LL |     fn foo();
-   |        --- associated function `foo` has no `self` parameter
+   |        --- ...because associated function `foo` has no `self` parameter
 ...
 LL |     let trait_obj: &dyn SomeTrait = SomeTrait;
    |                    ^^^^^^^^^^^^^^ the trait `SomeTrait` cannot be made into an object
+   |
+   = help: consider turning `foo` into a method by giving it a `&self` argument or constraining it with `where Self: Sized`
 
 error[E0033]: type `&dyn SomeTrait` cannot be dereferenced
   --> $DIR/E0033-teach.rs:12:9
index c2843796cc851b82c578555ab57ccfbf1ce9dc66..c736fbcf92a8eb96805ea3ed80d021f2a3ef0774 100644 (file)
@@ -7,11 +7,15 @@ LL |     let trait_obj: &dyn SomeTrait = SomeTrait;
 error[E0038]: the trait `SomeTrait` cannot be made into an object
   --> $DIR/E0033.rs:6:20
    |
+LL | trait SomeTrait {
+   |       --------- this trait cannot be made into an object...
 LL |     fn foo();
-   |        --- associated function `foo` has no `self` parameter
+   |        --- ...because associated function `foo` has no `self` parameter
 ...
 LL |     let trait_obj: &dyn SomeTrait = SomeTrait;
    |                    ^^^^^^^^^^^^^^ the trait `SomeTrait` cannot be made into an object
+   |
+   = help: consider turning `foo` into a method by giving it a `&self` argument or constraining it with `where Self: Sized`
 
 error[E0033]: type `&dyn SomeTrait` cannot be dereferenced
   --> $DIR/E0033.rs:10:9
index 6eaf6e4a8aad13df61c05ecdb3c222f8eca5429f..62b6f4cf246922dafd9d44986578be4d43b1b21e 100644 (file)
@@ -1,11 +1,15 @@
 error[E0038]: the trait `Trait` cannot be made into an object
   --> $DIR/E0038.rs:5:16
    |
+LL | trait Trait {
+   |       ----- this trait cannot be made into an object...
 LL |     fn foo(&self) -> Self;
-   |        --- method `foo` references the `Self` type in its parameters or return type
+   |        --- ...because method `foo` references the `Self` type in its parameters or return type
 ...
 LL | fn call_foo(x: Box<dyn Trait>) {
    |                ^^^^^^^^^^^^^^ the trait `Trait` cannot be made into an object
+   |
+   = help: consider moving `foo` to another trait
 
 error: aborting due to previous error
 
index ce9830694051264c9de0643c38e2c55505fae9c3..290598806689822fe6e442ab4156f1ed1cffa929 100644 (file)
@@ -2,7 +2,9 @@ error[E0038]: the trait `NonObjectSafe1` cannot be made into an object
   --> $DIR/feature-gate-object_safe_for_dispatch.rs:18:38
    |
 LL | trait NonObjectSafe1: Sized {}
-   |                       ----- traits that require `Self: Sized` cannot be made into an object
+   |       --------------  ----- ...because it requires `Self: Sized`
+   |       |
+   |       this trait cannot be made into an object...
 ...
 LL | fn takes_non_object_safe_ref<T>(obj: &dyn NonObjectSafe1) {
    |                                      ^^^^^^^^^^^^^^^^^^^ the trait `NonObjectSafe1` cannot be made into an object
@@ -10,35 +12,49 @@ LL | fn takes_non_object_safe_ref<T>(obj: &dyn NonObjectSafe1) {
 error[E0038]: the trait `NonObjectSafe2` cannot be made into an object
   --> $DIR/feature-gate-object_safe_for_dispatch.rs:22:36
    |
+LL | trait NonObjectSafe2 {
+   |       -------------- this trait cannot be made into an object...
 LL |     fn static_fn() {}
-   |        --------- associated function `static_fn` has no `self` parameter
+   |        --------- ...because associated function `static_fn` has no `self` parameter
 ...
 LL | fn return_non_object_safe_ref() -> &'static dyn NonObjectSafe2 {
    |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NonObjectSafe2` cannot be made into an object
+   |
+   = help: consider turning `static_fn` into a method by giving it a `&self` argument or constraining it with `where Self: Sized`
 
 error[E0038]: the trait `NonObjectSafe3` cannot be made into an object
   --> $DIR/feature-gate-object_safe_for_dispatch.rs:27:35
    |
+LL | trait NonObjectSafe3 {
+   |       -------------- this trait cannot be made into an object...
 LL |     fn foo<T>(&self);
-   |        --- method `foo` has generic type parameters
+   |        --- ...because method `foo` has generic type parameters
 ...
 LL | fn takes_non_object_safe_box(obj: Box<dyn NonObjectSafe3>) {
    |                                   ^^^^^^^^^^^^^^^^^^^^^^^ the trait `NonObjectSafe3` cannot be made into an object
+   |
+   = help: consider moving `foo` to another trait
 
 error[E0038]: the trait `NonObjectSafe4` cannot be made into an object
   --> $DIR/feature-gate-object_safe_for_dispatch.rs:31:35
    |
+LL | trait NonObjectSafe4 {
+   |       -------------- this trait cannot be made into an object...
 LL |     fn foo(&self, &Self);
-   |        --- method `foo` references the `Self` type in its parameters or return type
+   |        --- ...because method `foo` references the `Self` type in its parameters or return type
 ...
 LL | fn return_non_object_safe_rc() -> std::rc::Rc<dyn NonObjectSafe4> {
    |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NonObjectSafe4` cannot be made into an object
+   |
+   = help: consider moving `foo` to another trait
 
 error[E0038]: the trait `NonObjectSafe1` cannot be made into an object
   --> $DIR/feature-gate-object_safe_for_dispatch.rs:38:6
    |
 LL | trait NonObjectSafe1: Sized {}
-   |                       ----- traits that require `Self: Sized` cannot be made into an object
+   |       --------------  ----- ...because it requires `Self: Sized`
+   |       |
+   |       this trait cannot be made into an object...
 ...
 LL | impl Trait for dyn NonObjectSafe1 {}
    |      ^^^^^ the trait `NonObjectSafe1` cannot be made into an object
index ff4bfc30a4a62f3937665fb8ff8c92572813ccb3..1443be0b30ebe06178d3d632c1ae200a543df43b 100644 (file)
@@ -1,20 +1,28 @@
 error[E0038]: the trait `NotObjectSafe` cannot be made into an object
   --> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:21:13
    |
+LL | trait NotObjectSafe {
+   |       ------------- this trait cannot be made into an object...
 LL |     fn foo() -> Self;
-   |        --- associated function `foo` has no `self` parameter
+   |        --- ...because associated function `foo` has no `self` parameter
 ...
 LL | fn car() -> dyn NotObjectSafe {
    |             ^^^^^^^^^^^^^^^^^ the trait `NotObjectSafe` cannot be made into an object
+   |
+   = help: consider turning `foo` into a method by giving it a `&self` argument or constraining it with `where Self: Sized`
 
 error[E0038]: the trait `NotObjectSafe` cannot be made into an object
   --> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:28:13
    |
+LL | trait NotObjectSafe {
+   |       ------------- this trait cannot be made into an object...
 LL |     fn foo() -> Self;
-   |        --- associated function `foo` has no `self` parameter
+   |        --- ...because associated function `foo` has no `self` parameter
 ...
 LL | fn cat() -> Box<dyn NotObjectSafe> {
    |             ^^^^^^^^^^^^^^^^^^^^^^ the trait `NotObjectSafe` cannot be made into an object
+   |
+   = help: consider turning `foo` into a method by giving it a `&self` argument or constraining it with `where Self: Sized`
 
 error: aborting due to 2 previous errors
 
index 0c59486b416b8e4fd2d317d3e549544ae2c5f3d8..b3ba7aecad0dbd7b175cdcf0205d92d5cfbb5ad3 100644 (file)
@@ -2,10 +2,14 @@ error[E0038]: the trait `Bar` cannot be made into an object
   --> $DIR/issue-18959.rs:11:11
    |
 LL | pub trait Foo { fn foo<T>(&self, ext_thing: &T); }
-   |                    --- method `foo` has generic type parameters
+   |                    --- ...because method `foo` has generic type parameters
+LL | pub trait Bar: Foo { }
+   |           --- this trait cannot be made into an object...
 ...
 LL | fn foo(b: &dyn Bar) {
    |           ^^^^^^^^ the trait `Bar` cannot be made into an object
+   |
+   = help: consider moving `foo` to another trait
 
 error: aborting due to previous error
 
index 92bfdf1f26e93828b4eb0796d05086b17dc7826d..22e744f88417137dff805c7be97fe807374951d4 100644 (file)
@@ -1,11 +1,15 @@
 error[E0038]: the trait `Qiz` cannot be made into an object
   --> $DIR/issue-19380.rs:11:3
    |
+LL | trait Qiz {
+   |       --- this trait cannot be made into an object...
 LL |   fn qiz();
-   |      --- associated function `qiz` has no `self` parameter
+   |      --- ...because associated function `qiz` has no `self` parameter
 ...
 LL |   foos: &'static [&'static (dyn Qiz + 'static)]
    |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Qiz` cannot be made into an object
+   |
+   = help: consider turning `qiz` into a method by giving it a `&self` argument or constraining it with `where Self: Sized`
 
 error: aborting due to previous error
 
index 83c03b514ddcc8dd919d23ad82002acb46676d4a..b6033e47b1a44d88edd1503e77631317083e60a9 100644 (file)
@@ -2,20 +2,29 @@ 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
+   |        --- ...because method `foo` has generic type parameters
+...
+LL | trait Bar: Foo { }
+   |       --- this trait cannot be made into an object...
 ...
 LL |     let test: &mut dyn Bar = &mut thing;
    |               ^^^^^^^^^^^^ the trait `Bar` cannot be made into an object
+   |
+   = help: consider moving `foo` to another trait
 
 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
+   |        --- ...because method `foo` has generic type parameters
+...
+LL | trait Bar: Foo { }
+   |       --- this trait cannot be made into an object...
 ...
 LL |     let test: &mut dyn Bar = &mut thing;
    |                              ^^^^^^^^^^ the trait `Bar` cannot be made into an object
    |
+   = help: consider moving `foo` to another trait
    = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<&mut dyn Bar>` for `&mut Thing`
    = note: required by cast to type `&mut dyn Bar`
 
index 552b65b36209470b339c25dddf787728759155d5..ca2611e0f9eb5daa13b191c61591eaf247f261cc 100644 (file)
@@ -2,9 +2,10 @@ error[E0038]: the trait `Array` cannot be made into an object
   --> $DIR/issue-20692.rs:7:5
    |
 LL | trait Array: Sized + Copy {}
-   |              -----   ---- traits that require `Self: Sized` cannot be made into an object
-   |              |
-   |              traits that require `Self: Sized` cannot be made into an object
+   |       -----  -----   ---- ...because it requires `Self: Sized`
+   |       |      |
+   |       |      ...because it requires `Self: Sized`
+   |       this trait cannot be made into an object...
 ...
 LL |     &dyn Array;
    |     ^^^^^^^^^^ the trait `Array` cannot be made into an object
@@ -13,9 +14,10 @@ error[E0038]: the trait `Array` cannot be made into an object
   --> $DIR/issue-20692.rs:4:13
    |
 LL | trait Array: Sized + Copy {}
-   |              -----   ---- traits that require `Self: Sized` cannot be made into an object
-   |              |
-   |              traits that require `Self: Sized` cannot be made into an object
+   |       -----  -----   ---- ...because it requires `Self: Sized`
+   |       |      |
+   |       |      ...because it requires `Self: Sized`
+   |       this trait cannot be made into an object...
 ...
 LL |     let _ = x
    |             ^ the trait `Array` cannot be made into an object
index 9c4cf0b18acfe2eccc7302de74d5b14f03fce6b7..2744fb91d6fe1c4278c2a18ef180ad3d65f2a064 100644 (file)
@@ -4,7 +4,7 @@ error[E0038]: the trait `Map` cannot be made into an object
 LL |         as &dyn Map<Key=u32,MapValue=u32>;
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Map` cannot be made into an object
    |
-   = note: the trait cannot use `Self` as a type parameter in the supertraits or where-clauses
+   = note: the trait cannot be made into an object because it cannot use `Self` as a type parameter in the supertraits or `where`-clauses
 
 error: aborting due to previous error
 
index 3249d76e69b57d36c6d468d611e46a7851b1e6ce..5bed9a77d1891adf10441307b4bdfad88194d471 100644 (file)
@@ -5,7 +5,7 @@ LL | /            dyn Bar
 LL | |               <Assoc=()>
    | |________________________^ the trait `Bar` cannot be made into an object
    |
-   = note: the trait cannot use `Self` as a type parameter in the supertraits or where-clauses
+   = note: the trait cannot be made into an object because it cannot use `Self` as a type parameter in the supertraits or `where`-clauses
 
 error: aborting due to previous error
 
index d18a26b3a76382ca55fc0eb58590dc62404a3e18..613888758cab44dd61bf6982782c2b6d0e0de05f 100644 (file)
@@ -4,7 +4,7 @@ error[E0038]: the trait `B` cannot be made into an object
 LL | trait C<T>: A<dyn B<T, Output=usize>> {}
    |               ^^^^^^^^^^^^^^^^^^^^^^ the trait `B` cannot be made into an object
    |
-   = note: the trait cannot use `Self` as a type parameter in the supertraits or where-clauses
+   = note: the trait cannot be made into an object because it cannot use `Self` as a type parameter in the supertraits or `where`-clauses
 
 error: aborting due to previous error
 
index 8b923a2c6b23f45c1cba0739eb1dfe4bb51866e8..b3ad71e174a977ad2b3b1a049562b3cd6ca54533 100644 (file)
@@ -4,7 +4,7 @@ error[E0038]: the trait `Foo` cannot be made into an object
 LL |     let _f: Box<dyn Foo> =
    |             ^^^^^^^^^^^^ the trait `Foo` cannot be made into an object
    |
-   = note: the trait cannot use `Self` as a type parameter in the supertraits or where-clauses
+   = note: the trait cannot be made into an object because it cannot use `Self` as a type parameter in the supertraits or `where`-clauses
 
 error[E0038]: the trait `Foo` cannot be made into an object
   --> $DIR/issue-38604.rs:15:9
@@ -12,7 +12,7 @@ error[E0038]: the trait `Foo` cannot be made into an object
 LL |         Box::new(());
    |         ^^^^^^^^^^^^ the trait `Foo` cannot be made into an object
    |
-   = note: the trait cannot use `Self` as a type parameter in the supertraits or where-clauses
+   = note: the trait cannot be made into an object because it cannot use `Self` as a type parameter in the supertraits or `where`-clauses
    = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<std::boxed::Box<dyn Foo>>` for `std::boxed::Box<()>`
    = note: required by cast to type `std::boxed::Box<dyn Foo>`
 
index c161e9efd1261330955af821da3d69d11af5a5cd..03e3a7f227a23713a8942e0963c0c2e0eaef53cb 100644 (file)
@@ -1,8 +1,10 @@
 error: the trait `X` cannot be made into an object
   --> $DIR/issue-50781.rs:6:8
    |
+LL | trait X {
+   |       - this trait cannot be made into an object...
 LL |     fn foo(&self) where Self: Trait;
-   |        ^^^ method `foo` references the `Self` type in where clauses
+   |        ^^^ ...because method `foo` references the `Self` type in its `where` clause
    |
 note: the lint level is defined here
   --> $DIR/issue-50781.rs:1:9
@@ -11,6 +13,7 @@ LL | #![deny(where_clauses_object_safety)]
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #51443 <https://github.com/rust-lang/rust/issues/51443>
+   = help: consider moving `foo` to another trait
 
 error: aborting due to previous error
 
index 728a5ea6faa9ff9b13d44e70c104326710efd475..2a9fd13be5f01a4ffd49e5b08c71a380121531e6 100644 (file)
@@ -13,7 +13,9 @@ error[E0038]: the trait `Foo` cannot be made into an object
   --> $DIR/kindck-inherited-copy-bound.rs:28:19
    |
 LL | trait Foo : Copy {
-   |             ---- traits that require `Self: Sized` cannot be made into an object
+   |       ---   ---- ...because it requires `Self: Sized`
+   |       |
+   |       this trait cannot be made into an object...
 ...
 LL |     let z = &x as &dyn Foo;
    |                   ^^^^^^^^ the trait `Foo` cannot be made into an object
@@ -22,7 +24,9 @@ error[E0038]: the trait `Foo` cannot be made into an object
   --> $DIR/kindck-inherited-copy-bound.rs:28:13
    |
 LL | trait Foo : Copy {
-   |             ---- traits that require `Self: Sized` cannot be made into an object
+   |       ---   ---- ...because it requires `Self: Sized`
+   |       |
+   |       this trait cannot be made into an object...
 ...
 LL |     let z = &x as &dyn Foo;
    |             ^^ the trait `Foo` cannot be made into an object
index b4fba9706bc0db0cb6dbaae12b3e4d328012842e..6227ada4dc9384cfa4303a0d910517d773dada98 100644 (file)
@@ -13,7 +13,9 @@ error[E0038]: the trait `Foo` cannot be made into an object
   --> $DIR/kindck-inherited-copy-bound.rs:28:13
    |
 LL | trait Foo : Copy {
-   |             ---- traits that require `Self: Sized` cannot be made into an object
+   |       ---   ---- ...because it requires `Self: Sized`
+   |       |
+   |       this trait cannot be made into an object...
 ...
 LL |     let z = &x as &dyn Foo;
    |             ^^ the trait `Foo` cannot be made into an object
index b67b0e4f40e8cf18347cf9594fe554ecc383ec8b..e0e0344af75919bd03851d8b6cb1b6d9353c318c 100644 (file)
@@ -1,11 +1,15 @@
 error[E0038]: the trait `Bar` cannot be made into an object
   --> $DIR/object-safety-associated-consts.rs:12:30
    |
+LL | trait Bar {
+   |       --- this trait cannot be made into an object...
 LL |     const X: usize;
-   |           - the trait cannot contain associated consts like `X`
+   |           - ...because it 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
+   |
+   = help: consider moving `X` to another trait
 
 error: aborting due to previous error
 
index 20993a680ba48d52768bd64590ea7ce84b676b61..ff0bd17dccce52e419e5e1b70f97f5639f4e0999 100644 (file)
@@ -1,12 +1,15 @@
 error[E0038]: the trait `Bar` cannot be made into an object
   --> $DIR/object-safety-associated-consts.rs:14:5
    |
+LL | trait Bar {
+   |       --- this trait cannot be made into an object...
 LL |     const X: usize;
-   |           - the trait cannot contain associated consts like `X`
+   |           - ...because it cannot contain associated consts like `X`
 ...
 LL |     t
    |     ^ the trait `Bar` cannot be made into an object
    |
+   = help: consider moving `X` to another trait
    = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<&dyn Bar>` for `&T`
    = note: required by cast to type `&dyn Bar`
 
index 2469467f084a3869169074fae7c19ba92bf44790..9e70abbd32fc6551fcac230dd0a1603c1fd0de1e 100644 (file)
@@ -1,20 +1,28 @@
 error[E0038]: the trait `Bar` cannot be made into an object
   --> $DIR/object-safety-generics.rs:18:30
    |
+LL | trait Bar {
+   |       --- this trait cannot be made into an object...
 LL |     fn bar<T>(&self, t: T);
-   |        --- method `bar` has generic type parameters
+   |        --- ...because 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
+   |
+   = help: consider moving `bar` to another trait
 
 error[E0038]: the trait `Bar` cannot be made into an object
   --> $DIR/object-safety-generics.rs:24:39
    |
+LL | trait Bar {
+   |       --- this trait cannot be made into an object...
 LL |     fn bar<T>(&self, t: T);
-   |        --- method `bar` has generic type parameters
+   |        --- ...because 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
+   |
+   = help: consider moving `bar` to another trait
 
 error: aborting due to 2 previous errors
 
index d3d8d36888836bb11ace8fa71d387115d98123af..7443d38470c030e9c680e14baa18dc4e0b216d3f 100644 (file)
@@ -1,24 +1,30 @@
 error[E0038]: the trait `Bar` cannot be made into an object
   --> $DIR/object-safety-generics.rs:20:5
    |
+LL | trait Bar {
+   |       --- this trait cannot be made into an object...
 LL |     fn bar<T>(&self, t: T);
-   |        --- method `bar` has generic type parameters
+   |        --- ...because method `bar` has generic type parameters
 ...
 LL |     t
    |     ^ the trait `Bar` cannot be made into an object
    |
+   = help: consider moving `bar` to another trait
    = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<&dyn Bar>` for `&T`
    = note: required by cast to type `&dyn Bar`
 
 error[E0038]: the trait `Bar` cannot be made into an object
   --> $DIR/object-safety-generics.rs:26:5
    |
+LL | trait Bar {
+   |       --- this trait cannot be made into an object...
 LL |     fn bar<T>(&self, t: T);
-   |        --- method `bar` has generic type parameters
+   |        --- ...because method `bar` has generic type parameters
 ...
 LL |     t as &dyn Bar
    |     ^ the trait `Bar` cannot be made into an object
    |
+   = help: consider moving `bar` to another trait
    = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<&dyn Bar>` for `&T`
    = note: required by cast to type `&dyn Bar`
 
index 1f5c472ddc25a8870c973ade873f3fafc557ec82..55baf69401b0aa9d96c756ee3d5fbb8fc80d0b93 100644 (file)
@@ -4,7 +4,7 @@ error[E0038]: the trait `Expr` cannot be made into an object
 LL |     elements: Vec<Box<dyn Expr + 'x>>,
    |                       ^^^^^^^^^^^^^ the trait `Expr` cannot be made into an object
    |
-   = note: the trait cannot use `Self` as a type parameter in the supertraits or where-clauses
+   = note: the trait cannot be made into an object because it cannot use `Self` as a type parameter in the supertraits or `where`-clauses
 
 error: aborting due to previous error
 
index 2123e306b16a4c44f8617134aefc8d302d619252..e90f9b6d0a0cc228b48b297e15160960d6e6e667 100644 (file)
@@ -1,20 +1,28 @@
 error[E0038]: the trait `Bar` cannot be made into an object
   --> $DIR/object-safety-mentions-Self.rs:22:30
    |
+LL | trait Bar {
+   |       --- this trait cannot be made into an object...
 LL |     fn bar(&self, x: &Self);
-   |        --- method `bar` references the `Self` type in its parameters or return type
+   |        --- ...because method `bar` references the `Self` type in its parameters or return type
 ...
 LL | fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
    |                              ^^^^^^^^ the trait `Bar` cannot be made into an object
+   |
+   = help: consider moving `bar` to another trait
 
 error[E0038]: the trait `Baz` cannot be made into an object
   --> $DIR/object-safety-mentions-Self.rs:28:30
    |
+LL | trait Baz {
+   |       --- this trait cannot be made into an object...
 LL |     fn baz(&self) -> Self;
-   |        --- method `baz` references the `Self` type in its parameters or return type
+   |        --- ...because method `baz` references the `Self` type in its parameters or return type
 ...
 LL | fn make_baz<T:Baz>(t: &T) -> &dyn Baz {
    |                              ^^^^^^^^ the trait `Baz` cannot be made into an object
+   |
+   = help: consider moving `baz` to another trait
 
 error: aborting due to 2 previous errors
 
index 03b2b8da07533b8b30738f2d7d3544d4eb505235..4a23fb56e91a9cc6c98a1b2ea4ab6121cd463a0b 100644 (file)
@@ -1,24 +1,30 @@
 error[E0038]: the trait `Bar` cannot be made into an object
   --> $DIR/object-safety-mentions-Self.rs:24:5
    |
+LL | trait Bar {
+   |       --- this trait cannot be made into an object...
 LL |     fn bar(&self, x: &Self);
-   |        --- method `bar` references the `Self` type in its parameters or return type
+   |        --- ...because method `bar` references the `Self` type in its parameters or return type
 ...
 LL |     t
    |     ^ the trait `Bar` cannot be made into an object
    |
+   = help: consider moving `bar` to another trait
    = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<&dyn Bar>` for `&T`
    = note: required by cast to type `&dyn Bar`
 
 error[E0038]: the trait `Baz` cannot be made into an object
   --> $DIR/object-safety-mentions-Self.rs:30:5
    |
+LL | trait Baz {
+   |       --- this trait cannot be made into an object...
 LL |     fn baz(&self) -> Self;
-   |        --- method `baz` references the `Self` type in its parameters or return type
+   |        --- ...because method `baz` references the `Self` type in its parameters or return type
 ...
 LL |     t
    |     ^ the trait `Baz` cannot be made into an object
    |
+   = help: consider moving `baz` to another trait
    = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<&dyn Baz>` for `&T`
    = note: required by cast to type `&dyn Baz`
 
index 099876c562aec12d5f1b17eecf72665498962beb..2f79d53d1c12469752186829c35ffd5a32c53957 100644 (file)
@@ -1,11 +1,15 @@
 error[E0038]: the trait `Foo` cannot be made into an object
   --> $DIR/object-safety-no-static.rs:12:18
    |
+LL | trait Foo {
+   |       --- this trait cannot be made into an object...
 LL |     fn foo() {}
-   |        --- associated function `foo` has no `self` parameter
+   |        --- ...because associated function `foo` has no `self` parameter
 ...
 LL | fn diverges() -> Box<dyn Foo> {
    |                  ^^^^^^^^^^^^ the trait `Foo` cannot be made into an object
+   |
+   = help: consider turning `foo` into a method by giving it a `&self` argument or constraining it with `where Self: Sized`
 
 error: aborting due to previous error
 
index 91a9285b63cccf01cad52bd05e4245b300429764..bed6757fc68037ac92491a56cb4fc1e18d99d91f 100644 (file)
@@ -1,12 +1,15 @@
 error[E0038]: the trait `Foo` cannot be made into an object
   --> $DIR/object-safety-no-static.rs:22:27
    |
+LL | trait Foo {
+   |       --- this trait cannot be made into an object...
 LL |     fn foo() {}
-   |        --- associated function `foo` has no `self` parameter
+   |        --- ...because associated function `foo` has no `self` parameter
 ...
 LL |     let b: Box<dyn Foo> = Box::new(Bar);
    |                           ^^^^^^^^^^^^^ the trait `Foo` cannot be made into an object
    |
+   = help: consider turning `foo` into a method by giving it a `&self` argument or constraining it with `where Self: Sized`
    = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<std::boxed::Box<dyn Foo>>` for `std::boxed::Box<Bar>`
    = note: required by cast to type `std::boxed::Box<dyn Foo>`
 
index 49f98e008508254355339a37648e6f9bb62b3213..2f605d8e904c5dfbfbd737a8a949376c738d478c 100644 (file)
@@ -1,8 +1,10 @@
 error[E0038]: the trait `Bar` cannot be made into an object
   --> $DIR/object-safety-sized-2.rs:14:30
    |
+LL | trait Bar
+   |       --- this trait cannot be made into an object...
 LL |     where Self : Sized
-   |                  ----- traits that require `Self: Sized` cannot be made into an object
+   |                  ----- ...because it requires `Self: Sized`
 ...
 LL | fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
    |                              ^^^^^^^^ the trait `Bar` cannot be made into an object
index 9b189c48f9301f63f0408ceeeabe7a29cf6a9de7..2f1f06f4cf5fa395e767fd62f98e18e785b4d721 100644 (file)
@@ -1,8 +1,10 @@
 error[E0038]: the trait `Bar` cannot be made into an object
   --> $DIR/object-safety-sized-2.rs:16:5
    |
+LL | trait Bar
+   |       --- this trait cannot be made into an object...
 LL |     where Self : Sized
-   |                  ----- traits that require `Self: Sized` cannot be made into an object
+   |                  ----- ...because it requires `Self: Sized`
 ...
 LL |     t
    |     ^ the trait `Bar` cannot be made into an object
index 3b588034e3322099a53f5c35458d6fa60228d992..54f65c43d9cdef0f9e346b5d8ba4e58ca43a8005 100644 (file)
@@ -2,7 +2,9 @@ error[E0038]: the trait `Bar` cannot be made into an object
   --> $DIR/object-safety-sized.rs:12:30
    |
 LL | trait Bar : Sized {
-   |             ----- traits that require `Self: Sized` cannot be made into an object
+   |       ---   ----- ...because it requires `Self: Sized`
+   |       |
+   |       this trait cannot be made into an object...
 ...
 LL | fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
    |                              ^^^^^^^^ the trait `Bar` cannot be made into an object
index 6b60eef30d3d31cbd9b095f9cfaeaa1295e3385d..58c2b7721474fafc1f1102ca267ff61679b6ec18 100644 (file)
@@ -2,7 +2,9 @@ error[E0038]: the trait `Bar` cannot be made into an object
   --> $DIR/object-safety-sized.rs:14:5
    |
 LL | trait Bar : Sized {
-   |             ----- traits that require `Self: Sized` cannot be made into an object
+   |       ---   ----- ...because it requires `Self: Sized`
+   |       |
+   |       this trait cannot be made into an object...
 ...
 LL |     t
    |     ^ the trait `Bar` cannot be made into an object
index 8ae89832703d1d9e3f6c6e509403fe93b7770503..04f630d5dacb73f653bef5b16116ebdcca0e8fb3 100644 (file)
@@ -4,7 +4,7 @@ error[E0038]: the trait `Baz` cannot be made into an object
 LL | fn make_baz<T:Baz>(t: &T) -> &dyn Baz {
    |                               ^^^^^^^ the trait `Baz` cannot be made into an object
    |
-   = note: the trait cannot use `Self` as a type parameter in the supertraits or where-clauses
+   = note: the trait cannot be made into an object because it cannot use `Self` as a type parameter in the supertraits or `where`-clauses
 
 error: aborting due to previous error
 
index 1d6b378b9c8a7365776baa2ec208ac37774fc519..d0c278d12d70aea93bf88c5c12fcc5f3ce7affb2 100644 (file)
@@ -4,7 +4,7 @@ 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
+   = note: the trait cannot be made into an object because associated function `bar` has no `self` parameter
 
 error: aborting due to previous error
 
index 653ccb9db949aceed4a80d236a12d2bc75d6986e..c06538fae3b4ed0c3b7a85bd0449b9beb3463f82 100644 (file)
@@ -1,21 +1,28 @@
 error[E0038]: the trait `Foo` cannot be made into an object
   --> $DIR/arbitrary-self-types-not-object-safe.rs:33:32
    |
+LL | trait Foo {
+   |       --- this trait cannot be made into an object...
 LL |     fn foo(self: &Rc<Self>) -> usize;
-   |        --- method `foo`'s `self` parameter cannot be dispatched on
+   |        --- ...because method `foo`'s `self` parameter cannot be dispatched on
 ...
 LL |     let x = Rc::new(5usize) as Rc<dyn Foo>;
    |                                ^^^^^^^^^^^ the trait `Foo` cannot be made into an object
+   |
+   = help: consider changing method `foo`'s `self` parameter to be `&self`
 
 error[E0038]: the trait `Foo` cannot be made into an object
   --> $DIR/arbitrary-self-types-not-object-safe.rs:33:13
    |
+LL | trait Foo {
+   |       --- this trait cannot be made into an object...
 LL |     fn foo(self: &Rc<Self>) -> usize;
-   |        --- method `foo`'s `self` parameter cannot be dispatched on
+   |        --- ...because method `foo`'s `self` parameter cannot be dispatched on
 ...
 LL |     let x = Rc::new(5usize) as Rc<dyn Foo>;
    |             ^^^^^^^^^^^^^^^ the trait `Foo` cannot be made into an object
    |
+   = help: consider changing method `foo`'s `self` parameter to be `&self`
    = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<std::rc::Rc<dyn Foo>>` for `std::rc::Rc<usize>`
    = note: required by cast to type `std::rc::Rc<dyn Foo>`
 
index 33f1fa2e51be3545b548706a2c0f627c352075eb..bebd5cbcf780c8a048dffbb3e4c26b0bada9ad8c 100644 (file)
@@ -1,12 +1,15 @@
 error[E0038]: the trait `Foo` cannot be made into an object
   --> $DIR/arbitrary-self-types-not-object-safe.rs:33:13
    |
+LL | trait Foo {
+   |       --- this trait cannot be made into an object...
 LL |     fn foo(self: &Rc<Self>) -> usize;
-   |        --- method `foo`'s `self` parameter cannot be dispatched on
+   |        --- ...because method `foo`'s `self` parameter cannot be dispatched on
 ...
 LL |     let x = Rc::new(5usize) as Rc<dyn Foo>;
    |             ^^^^^^^^^^^^^^^ the trait `Foo` cannot be made into an object
    |
+   = help: consider changing method `foo`'s `self` parameter to be `&self`
    = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<std::rc::Rc<dyn Foo>>` for `std::rc::Rc<usize>`
    = note: required by cast to type `std::rc::Rc<dyn Foo>`
 
index 4a9242b1f4fac5140343592f8f249a5981cdb664..55185a2c8cdd179e0e98bd75e9dbe4c912d100e7 100644 (file)
@@ -15,7 +15,9 @@ error[E0038]: the trait `A` cannot be made into an object
   --> $DIR/object-unsafe-trait-should-use-self.rs:3:13
    |
 LL | trait A: Sized {
-   |          ----- traits that require `Self: Sized` cannot be made into an object
+   |       -  ----- ...because it requires `Self: Sized`
+   |       |
+   |       this trait cannot be made into an object...
 LL |     fn f(a: A) -> A;
    |             ^ the trait `A` cannot be made into an object
 
@@ -35,10 +37,14 @@ LL |     fn f(a: Self) -> Self;
 error[E0038]: the trait `B` cannot be made into an object
   --> $DIR/object-unsafe-trait-should-use-self.rs:8:13
    |
+LL | trait B {
+   |       - this trait cannot be made into an object...
 LL |     fn f(a: B) -> B;
    |        -    ^ the trait `B` cannot be made into an object
    |        |
-   |        associated function `f` has no `self` parameter
+   |        ...because associated function `f` has no `self` parameter
+   |
+   = help: consider turning `f` into a method by giving it a `&self` argument or constraining it with `where Self: Sized`
 
 error: aborting due to 4 previous errors
 
index 5551b1303b927e35f07912b563ed6c0544e1244a..1f9ffb6a4cfbf0b69cc61f432ed95bb7e096a075 100644 (file)
@@ -4,7 +4,7 @@ error[E0038]: the trait `std::cmp::Eq` cannot be made into an object
 LL |     let _: &dyn EqAlias = &123;
    |             ^^^^^^^^^^^ the trait `std::cmp::Eq` cannot be made into an object
    |
-   = note: the trait cannot use `Self` as a type parameter in the supertraits or where-clauses
+   = note: the trait cannot be made into an object because it cannot use `Self` as a type parameter in the supertraits or `where`-clauses
 
 error[E0191]: the value of the associated type `Item` (from trait `std::iter::Iterator`) must be specified
   --> $DIR/trait-alias-object-fail.rs:9:17
index 4df8845de279ae2042639aeede55455783ab14fa..e050d6940abc354d77d5b669e9f0b57252d6d92d 100644 (file)
@@ -111,16 +111,22 @@ 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`
+   |               - ...because it cannot contain associated consts like `A`
 ...
 LL |         const B: u8 = 0;
-   |               - the trait cannot contain associated consts like `B`
+   |               - ...because it cannot contain associated consts like `B`
 ...
+LL |     pub trait C: A + B {
+   |               - this trait cannot be made into an object...
 LL |         const C: u8 = 0;
-   |               - the trait cannot contain associated consts like `C`
+   |               - ...because it cannot contain associated consts like `C`
 ...
 LL |     C::A;
    |     ^^^^ the trait `assoc_const::C` cannot be made into an object
+   |
+   = help: consider moving `C` to another trait
+   = help: consider moving `B` to another trait
+   = help: consider moving `A` to another trait
 
 error[E0223]: ambiguous associated type
   --> $DIR/trait-item-privacy.rs:115:12
index f41ebf4166d06f2071ea7d45a756d62cb27b5077..a8511f63c16a5ac9d1e88519cc2b397a926b6eac 100644 (file)
@@ -10,7 +10,7 @@ error[E0038]: the trait `std::marker::Copy` cannot be made into an object
 LL |     m!(dyn Copy + Send + 'static);
    |        ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` cannot be made into an object
    |
-   = note: traits that require `Self: Sized` cannot be made into an object
+   = note: the trait cannot be made into an object because it requires `Self: Sized`
 
 error: aborting due to 2 previous errors
 
index 028e9eedd641a227cd11e60ee2bf952c260d8aa0..5eb8cd0d80636542b7c6954e91d31e428f49c618 100644 (file)
@@ -1,23 +1,30 @@
 error[E0038]: the trait `Tr` cannot be made into an object
   --> $DIR/trait-object-safety.rs:15:22
    |
+LL | trait Tr {
+   |       -- this trait cannot be made into an object...
 LL |     fn foo();
-   |        --- associated function `foo` has no `self` parameter
+   |        --- ...because associated function `foo` has no `self` parameter
 ...
 LL |     let _: &dyn Tr = &St;
    |                      ^^^ the trait `Tr` cannot be made into an object
    |
+   = help: consider turning `foo` into a method by giving it a `&self` argument or constraining it with `where Self: Sized`
    = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<&dyn Tr>` for `&St`
    = note: required by cast to type `&dyn Tr`
 
 error[E0038]: the trait `Tr` cannot be made into an object
   --> $DIR/trait-object-safety.rs:15:12
    |
+LL | trait Tr {
+   |       -- this trait cannot be made into an object...
 LL |     fn foo();
-   |        --- associated function `foo` has no `self` parameter
+   |        --- ...because associated function `foo` has no `self` parameter
 ...
 LL |     let _: &dyn Tr = &St;
    |            ^^^^^^^ the trait `Tr` cannot be made into an object
+   |
+   = help: consider turning `foo` into a method by giving it a `&self` argument or constraining it with `where Self: Sized`
 
 error: aborting due to 2 previous errors
 
index 9b750d382ec962b227c4b4735ef48b1932ca9632..5b2b7b51f3dae299ce33ef931948f447e48c34c3 100644 (file)
@@ -14,24 +14,31 @@ 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 parameters or return type
+   |       ---      ---                    ---- ...because method `blah` has generic type parameters
+   |       |        |
+   |       |        ...because method `dup` references the `Self` type in its parameters or return type
+   |       this trait cannot be made into an object...
 ...
 LL |     (box 10 as Box<dyn bar>).dup();
    |                ^^^^^^^^^^^^ the trait `bar` cannot be made into an object
+   |
+   = help: consider moving `dup` to another trait
+   = help: consider moving `blah` to another trait
 
 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 parameters or return type
+   |       ---      ---                    ---- ...because method `blah` has generic type parameters
+   |       |        |
+   |       |        ...because method `dup` references the `Self` type in its parameters or return type
+   |       this trait cannot be made into an object...
 ...
 LL |     (box 10 as Box<dyn bar>).dup();
    |      ^^^^^^ the trait `bar` cannot be made into an object
    |
+   = help: consider moving `dup` to another trait
+   = help: consider moving `blah` to another trait
    = note: required because of the requirements on the impl of `std::ops::CoerceUnsized<std::boxed::Box<dyn bar>>` for `std::boxed::Box<{integer}>`
    = note: required by cast to type `std::boxed::Box<dyn bar>`
 
index b315fe9df8afd349073f6fed2855a5b635ebcab3..fa6c5a92fb437bc8cc5c588ec535d0e20aeb1358 100644 (file)
@@ -14,10 +14,14 @@ 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 parameters or return type
+   |       -----                --- ...because method `add` references the `Self` type in its parameters or return type
+   |       |
+   |       this trait cannot be made into an object...
 ...
 LL |     let y = x as dyn MyAdd<i32>;
    |                  ^^^^^^^^^^^^^^ the trait `MyAdd` cannot be made into an object
+   |
+   = help: consider moving `add` to another trait
 
 error: aborting due to 2 previous errors
 
index 7e055d746f67671f651b696beadd8ad1c6b3beb9..eefb450155cdbb9f4c4f3e0b226211e4ee60c126 100644 (file)
@@ -2,7 +2,9 @@ error[E0038]: the trait `Trait` cannot be made into an object
   --> $DIR/wf-convert-unsafe-trait-obj-box.rs:16:33
    |
 LL | trait Trait: Sized {}
-   |              ----- traits that require `Self: Sized` cannot be made into an object
+   |       -----  ----- ...because it requires `Self: Sized`
+   |       |
+   |       this trait cannot be made into an object...
 ...
 LL |     let t_box: Box<dyn Trait> = Box::new(S);
    |                                 ^^^^^^^^^^^ the trait `Trait` cannot be made into an object
@@ -14,7 +16,9 @@ error[E0038]: the trait `Trait` cannot be made into an object
   --> $DIR/wf-convert-unsafe-trait-obj-box.rs:17:15
    |
 LL | trait Trait: Sized {}
-   |              ----- traits that require `Self: Sized` cannot be made into an object
+   |       -----  ----- ...because it requires `Self: Sized`
+   |       |
+   |       this trait cannot be made into an object...
 ...
 LL |     takes_box(Box::new(S));
    |               ^^^^^^^^^^^ the trait `Trait` cannot be made into an object
@@ -26,7 +30,9 @@ error[E0038]: the trait `Trait` cannot be made into an object
   --> $DIR/wf-convert-unsafe-trait-obj-box.rs:15:5
    |
 LL | trait Trait: Sized {}
-   |              ----- traits that require `Self: Sized` cannot be made into an object
+   |       -----  ----- ...because it requires `Self: Sized`
+   |       |
+   |       this trait cannot be made into an object...
 ...
 LL |     Box::new(S) as Box<dyn Trait>;
    |     ^^^^^^^^^^^ the trait `Trait` cannot be made into an object
index 9e7fe7f3e1dfc02f87e733d8cb3884da5a3b0815..5e645382d1b21414e7e9eaad2ed7b9898a97f4f3 100644 (file)
@@ -2,7 +2,9 @@ error[E0038]: the trait `Trait` cannot be made into an object
   --> $DIR/wf-convert-unsafe-trait-obj.rs:16:25
    |
 LL | trait Trait: Sized {}
-   |              ----- traits that require `Self: Sized` cannot be made into an object
+   |       -----  ----- ...because it requires `Self: Sized`
+   |       |
+   |       this trait cannot be made into an object...
 ...
 LL |     let t: &dyn Trait = &S;
    |                         ^^ the trait `Trait` cannot be made into an object
@@ -14,7 +16,9 @@ error[E0038]: the trait `Trait` cannot be made into an object
   --> $DIR/wf-convert-unsafe-trait-obj.rs:17:17
    |
 LL | trait Trait: Sized {}
-   |              ----- traits that require `Self: Sized` cannot be made into an object
+   |       -----  ----- ...because it requires `Self: Sized`
+   |       |
+   |       this trait cannot be made into an object...
 ...
 LL |     takes_trait(&S);
    |                 ^^ the trait `Trait` cannot be made into an object
@@ -26,7 +30,9 @@ error[E0038]: the trait `Trait` cannot be made into an object
   --> $DIR/wf-convert-unsafe-trait-obj.rs:15:5
    |
 LL | trait Trait: Sized {}
-   |              ----- traits that require `Self: Sized` cannot be made into an object
+   |       -----  ----- ...because it requires `Self: Sized`
+   |       |
+   |       this trait cannot be made into an object...
 ...
 LL |     &S as &dyn Trait;
    |     ^^ the trait `Trait` cannot be made into an object
index f17391520a32cc80cb174af391dc9b0d3f66ea16..1c530ece29580731ad0a413ad04804f71768624e 100644 (file)
@@ -25,7 +25,7 @@ error[E0038]: the trait `std::marker::Copy` cannot be made into an object
 LL | fn bar() where Vec<dyn Copy>:, {}
    |                ^^^^^^^^^^^^^ the trait `std::marker::Copy` cannot be made into an object
    |
-   = note: traits that require `Self: Sized` cannot be made into an object
+   = note: the trait cannot be made into an object because it requires `Self: Sized`
 
 error: aborting due to 3 previous errors
 
index 0d8441f87e7e776618a5d3979208478dbcb91f7e..2ff6383bc80eb6330f34c8b63b1400ecad31b65b 100644 (file)
@@ -1,11 +1,15 @@
 error[E0038]: the trait `A` cannot be made into an object
   --> $DIR/wf-object-safe.rs:9:13
    |
+LL | trait A {
+   |       - this trait cannot be made into an object...
 LL |     fn foo(&self, _x: &Self);
-   |        --- method `foo` references the `Self` type in its parameters or return type
+   |        --- ...because method `foo` references the `Self` type in its parameters or return type
 ...
 LL |     let _x: &dyn A;
    |             ^^^^^^ the trait `A` cannot be made into an object
+   |
+   = help: consider moving `foo` to another trait
 
 error: aborting due to previous error
 
index 452a2a5e58b7fbad87414f09f2e0c0a7191f9acd..9319e3382c2d4f1e6c857ef55c5e24a489ce86e4 100644 (file)
@@ -16,7 +16,9 @@ error[E0038]: the trait `Trait` cannot be made into an object
   --> $DIR/wf-unsafe-trait-obj-match.rs:26:21
    |
 LL | trait Trait: Sized {}
-   |              ----- traits that require `Self: Sized` cannot be made into an object
+   |       -----  ----- ...because it requires `Self: Sized`
+   |       |
+   |       this trait cannot be made into an object...
 ...
 LL |         Some(()) => &S,
    |                     ^^ the trait `Trait` cannot be made into an object
@@ -28,7 +30,9 @@ error[E0038]: the trait `Trait` cannot be made into an object
   --> $DIR/wf-unsafe-trait-obj-match.rs:25:25
    |
 LL | trait Trait: Sized {}
-   |              ----- traits that require `Self: Sized` cannot be made into an object
+   |       -----  ----- ...because it requires `Self: Sized`
+   |       |
+   |       this trait cannot be made into an object...
 ...
 LL |     let t: &dyn Trait = match opt() {
    |                         ^^^^^^^^^^^ the trait `Trait` cannot be made into an object