Skip to content

error_handling/errorsn.rs uses deprecated Trait - related syntax #211

@sosnowski

Description

@sosnowski

Hi!

I've noticed, that the exercise:

/exercises/error_handling/errorsn.rs is using a deprecated syntax for traits related values.
It causes the compiler to display warning messages:

rustlings run exercises/error_handling/errorsn.rs
! Compiling of exercises/error_handling/errorsn.rs failed! Please try again. Here's the output:
warning: trait objects without an explicit `dyn` are deprecated
  --> exercises/error_handling/errorsn.rs:23:30
   |
23 | fn read_and_validate(b: &mut io::BufRead) -> Result<PositiveNonzeroInteger, Box<error::Error>> {
   |                              ^^^^^^^^^^^ help: use `dyn`: `dyn io::BufRead`
   |
   = note: #[warn(bare_trait_objects)] on by default

warning: trait objects without an explicit `dyn` are deprecated
  --> exercises/error_handling/errorsn.rs:23:81
   |
23 | fn read_and_validate(b: &mut io::BufRead) -> Result<PositiveNonzeroInteger, Box<error::Error>> {
   |                                                                                 ^^^^^^^^^^^^ help: use `dyn`: `dyn error::Error`

warning: trait objects without an explicit `dyn` are deprecated
  --> exercises/error_handling/errorsn.rs:32:65
   |
32 | fn test_with_str(s: &str) -> Result<PositiveNonzeroInteger, Box<error::Error>> {
   |                                                                 ^^^^^^^^^^^^ help: use `dyn`: `dyn error::Error`

warning: trait objects without an explicit `dyn` are deprecated
   --> exercises/error_handling/errorsn.rs:101:31
    |
101 |         f.write_str((self as &error::Error).description())
    |                               ^^^^^^^^^^^^ help: use `dyn`: `dyn error::Error`

Probably the solution is as simple as changing Box<Trait> to a recomended Box<dyn Trait> (or maybe impl Trait is better?

I will prepare a simple pull request with a fix.
I'm fairly new to Rust, so if what I'm saying does not make sense, just let me know ;)

rustc 1.37.0 (eae3437df 2019-08-13)
rustlings 1.4.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions