Advertisement
vincenzopalazzo

96076.rs

Apr 22nd, 2022
1,476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.67 KB | None | 0 0
  1. use std::fmt;
  2.  
  3. trait MyTrait { }
  4.  
  5. /// warning: trait objects without an explicit `dyn` are deprecated
  6. /// --> traits.rs:5:23
  7. ///    |
  8. /// 5 | impl fmt::Display for MyTrait {
  9. ///    |                       ^^^^^^^
  10. ///        |
  11. ///    = note: `#[warn(bare_trait_objects)]` on by default
  12. ///        = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
  13. ///        = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
  14. ///    help: use `dyn`
  15. ///        |
  16. ///    5 - impl fmt::Display for MyTrait {
  17. ///        5 + impl fmt::Display for dyn MyTrait {
  18. ///            |
  19. ///
  20. ///            warning: 1 warning emitted
  21. /*impl fmt::Display for MyTrait {
  22.     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
  23.         write!(f, "Hello here")
  24.     }
  25. }*/
  26.  
  27.  
  28. /// error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
  29. ///    --> traits.rs:27:6
  30. ///    |
  31. /// 27 | impl<T: MyTrait> fmt::Display for T {
  32. ///    |      ^ type parameter `T` must be used as the type parameter for some local type
  33. ///        |
  34. ///    = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local
  35. ///        = note: only traits defined in the current crate can be implemented for a type parameter
  36. ///
  37. ///        error: aborting due to previous error
  38. ///        For more information about this error, try `rustc --explain E0210`.
  39. impl<T: MyTrait> fmt::Display for T {
  40.     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
  41.        todo!();
  42.    }
  43. }
  44.  
  45. fn main() { }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement