about summary refs log tree commit diff
path: root/tests/ui/statics
diff options
context:
space:
mode:
authorTaylor Cramer <cramertj@google.com>2024-11-20 14:19:36 -0800
committerTaylor Cramer <cramertj@google.com>2025-01-22 09:20:57 -0800
commitd00d4dfe0daba29036aab1f2b35a8c6ccb023f3e (patch)
treed2aa54a8a05297e887429b0d984f626c1b94d4ac /tests/ui/statics
parentb2728d5426bab1d8c39709768c7e22b7f66dde5d (diff)
downloadrust-d00d4dfe0daba29036aab1f2b35a8c6ccb023f3e.tar.gz
rust-d00d4dfe0daba29036aab1f2b35a8c6ccb023f3e.zip
Refactor dyn-compatibility error and suggestions
This CL makes a number of small changes to dyn compatibility errors:
- "object safety" has been renamed to "dyn-compatibility" throughout
- "Convert to enum" suggestions are no longer generated when there
  exists a type-generic impl of the trait or an impl for `dyn OtherTrait`
- Several error messages are reorganized for user readability

Additionally, the dyn compatibility error creation code has been
split out into functions.

cc #132713
cc #133267
Diffstat (limited to 'tests/ui/statics')
-rw-r--r--tests/ui/statics/unsizing-wfcheck-issue-127299.rs6
-rw-r--r--tests/ui/statics/unsizing-wfcheck-issue-127299.stderr27
2 files changed, 18 insertions, 15 deletions
diff --git a/tests/ui/statics/unsizing-wfcheck-issue-127299.rs b/tests/ui/statics/unsizing-wfcheck-issue-127299.rs
index cd15be54ec7..fd07937d90f 100644
--- a/tests/ui/statics/unsizing-wfcheck-issue-127299.rs
+++ b/tests/ui/statics/unsizing-wfcheck-issue-127299.rs
@@ -6,12 +6,12 @@ trait Qux {
 
 pub struct Lint {
     pub desc: &'static dyn Qux,
-    //~^ ERROR cannot be made into an object
+    //~^ ERROR is not dyn compatible
 }
 
 static FOO: &Lint = &Lint { desc: "desc" };
 //~^ ERROR cannot be shared between threads safely
-//~| ERROR cannot be made into an object
-//~| ERROR cannot be made into an object
+//~| ERROR is not dyn compatible
+//~| ERROR is not dyn compatible
 
 fn main() {}
diff --git a/tests/ui/statics/unsizing-wfcheck-issue-127299.stderr b/tests/ui/statics/unsizing-wfcheck-issue-127299.stderr
index 35dd570e91f..08c744979f5 100644
--- a/tests/ui/statics/unsizing-wfcheck-issue-127299.stderr
+++ b/tests/ui/statics/unsizing-wfcheck-issue-127299.stderr
@@ -1,14 +1,15 @@
-error[E0038]: the trait `Qux` cannot be made into an object
+error[E0038]: the trait `Qux` is not dyn compatible
   --> $DIR/unsizing-wfcheck-issue-127299.rs:8:24
    |
 LL |     pub desc: &'static dyn Qux,
-   |                        ^^^^^^^ `Qux` cannot be made into an object
+   |                        ^^^^^^^ `Qux` is not dyn compatible
    |
-note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
+note: for a trait to be dyn compatible it needs to allow building a vtable
+      for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
   --> $DIR/unsizing-wfcheck-issue-127299.rs:4:8
    |
 LL | trait Qux {
-   |       --- this trait cannot be made into an object...
+   |       --- this trait is not dyn compatible...
 LL |     fn bar() -> i32;
    |        ^^^ ...because associated function `bar` has no `self` parameter
 help: consider turning `bar` into a method by giving it a `&self` argument
@@ -36,17 +37,18 @@ LL | pub struct Lint {
    = note: required because it appears within the type `&'static Lint`
    = note: shared static variables must have a type that implements `Sync`
 
-error[E0038]: the trait `Qux` cannot be made into an object
+error[E0038]: the trait `Qux` is not dyn compatible
   --> $DIR/unsizing-wfcheck-issue-127299.rs:12:35
    |
 LL | static FOO: &Lint = &Lint { desc: "desc" };
-   |                                   ^^^^^^ `Qux` cannot be made into an object
+   |                                   ^^^^^^ `Qux` is not dyn compatible
    |
-note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
+note: for a trait to be dyn compatible it needs to allow building a vtable
+      for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
   --> $DIR/unsizing-wfcheck-issue-127299.rs:4:8
    |
 LL | trait Qux {
-   |       --- this trait cannot be made into an object...
+   |       --- this trait is not dyn compatible...
 LL |     fn bar() -> i32;
    |        ^^^ ...because associated function `bar` has no `self` parameter
    = note: required for the cast from `&'static str` to `&'static (dyn Qux + 'static)`
@@ -59,17 +61,18 @@ help: alternatively, consider constraining `bar` so it does not apply to trait o
 LL |     fn bar() -> i32 where Self: Sized;
    |                     +++++++++++++++++
 
-error[E0038]: the trait `Qux` cannot be made into an object
+error[E0038]: the trait `Qux` is not dyn compatible
   --> $DIR/unsizing-wfcheck-issue-127299.rs:12:35
    |
 LL | static FOO: &Lint = &Lint { desc: "desc" };
-   |                                   ^^^^^^ `Qux` cannot be made into an object
+   |                                   ^^^^^^ `Qux` is not dyn compatible
    |
-note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
+note: for a trait to be dyn compatible it needs to allow building a vtable
+      for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
   --> $DIR/unsizing-wfcheck-issue-127299.rs:4:8
    |
 LL | trait Qux {
-   |       --- this trait cannot be made into an object...
+   |       --- this trait is not dyn compatible...
 LL |     fn bar() -> i32;
    |        ^^^ ...because associated function `bar` has no `self` parameter
 help: consider turning `bar` into a method by giving it a `&self` argument