about summary refs log tree commit diff
path: root/src/test/ui/suggestions
diff options
context:
space:
mode:
authorVincenzo Palazzo <vincenzopalazzodev@gmail.com>2022-06-22 23:06:34 +0100
committerVincenzo Palazzo <vincenzopalazzodev@gmail.com>2022-06-30 01:13:24 +0100
commit86c1a734f5b915685560baeebac9b773d7108ccf (patch)
treef5d07e42ccd98b32b72eb985bfeb6b7e9bad2f9f /src/test/ui/suggestions
parent81abfe3913fa3aac1d052b93d26f6a8f642d0ac0 (diff)
downloadrust-86c1a734f5b915685560baeebac9b773d7108ccf.tar.gz
rust-86c1a734f5b915685560baeebac9b773d7108ccf.zip
ui test: add test of blanklet implementation
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
Diffstat (limited to 'src/test/ui/suggestions')
-rw-r--r--src/test/ui/suggestions/suggest-blanket-impl-local-trait.rs44
-rw-r--r--src/test/ui/suggestions/suggest-blanket-impl-local-trait.stderr99
2 files changed, 143 insertions, 0 deletions
diff --git a/src/test/ui/suggestions/suggest-blanket-impl-local-trait.rs b/src/test/ui/suggestions/suggest-blanket-impl-local-trait.rs
new file mode 100644
index 00000000000..61798c61cd0
--- /dev/null
+++ b/src/test/ui/suggestions/suggest-blanket-impl-local-trait.rs
@@ -0,0 +1,44 @@
+// Ensure that the compiler include the blanklet implementation suggestion
+// when inside a `impl` statment are used two local traits.
+//
+// edition:2021
+use std::fmt;
+
+trait LocalTraitOne { }
+
+trait LocalTraitTwo { }
+
+trait GenericTrait<T> {}
+
+impl LocalTraitTwo for LocalTraitOne {}
+//~^ ERROR trait objects must include the `dyn` keyword
+
+impl fmt::Display for LocalTraitOne {
+//~^ ERROR trait objects must include the `dyn` keyword
+    fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        todo!();
+    }
+}
+
+impl fmt::Display for LocalTraitTwo + Send {
+//~^ ERROR trait objects must include the `dyn` keyword
+    fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        todo!();
+    }
+}
+
+impl LocalTraitOne for fmt::Display {}
+//~^ ERROR trait objects must include the `dyn` keyword
+
+impl LocalTraitOne for fmt::Display + Send {}
+//~^ ERROR trait objects must include the `dyn` keyword
+
+impl<E> GenericTrait<E> for LocalTraitOne {}
+//~^ ERROR trait objects must include the `dyn` keyword
+
+trait GenericTraitTwo<T> {}
+
+impl<T, E> GenericTraitTwo<E> for GenericTrait<T> {}
+//~^ ERROR trait objects must include the `dyn` keyword
+
+fn main() {}
diff --git a/src/test/ui/suggestions/suggest-blanket-impl-local-trait.stderr b/src/test/ui/suggestions/suggest-blanket-impl-local-trait.stderr
new file mode 100644
index 00000000000..014d9dd2232
--- /dev/null
+++ b/src/test/ui/suggestions/suggest-blanket-impl-local-trait.stderr
@@ -0,0 +1,99 @@
+error[E0782]: trait objects must include the `dyn` keyword
+  --> $DIR/suggest-blanket-impl-local-trait.rs:13:24
+   |
+LL | impl LocalTraitTwo for LocalTraitOne {}
+   |                        ^^^^^^^^^^^^^
+   |
+help: add `dyn` keyword before this trait
+   |
+LL - impl LocalTraitTwo for LocalTraitOne {}
+LL + impl LocalTraitTwo for dyn LocalTraitOne {}
+   | 
+help: alternatively use a blanket implementation to implement `LocalTraitTwo` for all types that also implement `LocalTraitOne`
+   |
+LL | impl<T: LocalTraitOne> LocalTraitTwo for T {}
+   |     ++++++++++++++++++                   ~
+
+error[E0782]: trait objects must include the `dyn` keyword
+  --> $DIR/suggest-blanket-impl-local-trait.rs:16:23
+   |
+LL | impl fmt::Display for LocalTraitOne {
+   |                       ^^^^^^^^^^^^^
+   |
+help: add `dyn` keyword before this trait
+   |
+LL - impl fmt::Display for LocalTraitOne {
+LL + impl fmt::Display for dyn LocalTraitOne {
+   | 
+
+error[E0782]: trait objects must include the `dyn` keyword
+  --> $DIR/suggest-blanket-impl-local-trait.rs:23:23
+   |
+LL | impl fmt::Display for LocalTraitTwo + Send {
+   |                       ^^^^^^^^^^^^^^^^^^^^
+   |
+help: add `dyn` keyword before this trait
+   |
+LL - impl fmt::Display for LocalTraitTwo + Send {
+LL + impl fmt::Display for dyn LocalTraitTwo + Send {
+   | 
+
+error[E0782]: trait objects must include the `dyn` keyword
+  --> $DIR/suggest-blanket-impl-local-trait.rs:30:24
+   |
+LL | impl LocalTraitOne for fmt::Display {}
+   |                        ^^^^^^^^^^^^
+   |
+help: add `dyn` keyword before this trait
+   |
+LL - impl LocalTraitOne for fmt::Display {}
+LL + impl LocalTraitOne for dyn fmt::Display {}
+   | 
+
+error[E0782]: trait objects must include the `dyn` keyword
+  --> $DIR/suggest-blanket-impl-local-trait.rs:33:24
+   |
+LL | impl LocalTraitOne for fmt::Display + Send {}
+   |                        ^^^^^^^^^^^^^^^^^^^
+   |
+help: add `dyn` keyword before this trait
+   |
+LL - impl LocalTraitOne for fmt::Display + Send {}
+LL + impl LocalTraitOne for dyn fmt::Display + Send {}
+   | 
+
+error[E0782]: trait objects must include the `dyn` keyword
+  --> $DIR/suggest-blanket-impl-local-trait.rs:36:29
+   |
+LL | impl<E> GenericTrait<E> for LocalTraitOne {}
+   |                             ^^^^^^^^^^^^^
+   |
+help: add `dyn` keyword before this trait
+   |
+LL - impl<E> GenericTrait<E> for LocalTraitOne {}
+LL + impl<E> GenericTrait<E> for dyn LocalTraitOne {}
+   | 
+help: alternatively use a blanket implementation to implement `GenericTrait<E>` for all types that also implement `LocalTraitOne`
+   |
+LL | impl<E, L: LocalTraitOne> GenericTrait<E> for T {}
+   |       ++++++++++++++++++                      ~
+
+error[E0782]: trait objects must include the `dyn` keyword
+  --> $DIR/suggest-blanket-impl-local-trait.rs:41:35
+   |
+LL | impl<T, E> GenericTraitTwo<E> for GenericTrait<T> {}
+   |                                   ^^^^^^^^^^^^^^^
+   |
+help: add `dyn` keyword before this trait
+   |
+LL - impl<T, E> GenericTraitTwo<E> for GenericTrait<T> {}
+LL + impl<T, E> GenericTraitTwo<E> for dyn GenericTrait<T> {}
+   | 
+help: alternatively use a blanket implementation to implement `GenericTraitTwo<E>` for all types that also implement `GenericTrait<T>`
+   |
+LL | impl<T, E, G: GenericTrait<T>> GenericTraitTwo<E> for U {}
+   |          ++++++++++++++++++++                         ~
+
+error: aborting due to 7 previous errors
+
+For more information about this error, try `rustc --explain E0782`.