Skip to content

std::error::Error::source documentation example uses deprecated description method #70278

Description

@olehmisar

https://doc.rust-lang.org/std/error/trait.Error.html#method.source.

The documentation example contains the deprecated std::error::Error::description method in the main function:

fn main() {
    match get_super_error() {
        Err(e) => {
            println!("Error: {}", e.description());  // <----------- HERE IT IS
            println!("Caused by: {}", e.source().unwrap());
        }
        _ => println!("No error"),
    }
}

This is probably a mistake as get_super_error returns a struct that implements the std::fmt::Display trait which should be used instead of the deprecated std::error::Error::description method. So, this:

println!("Error: {}", e.description());

...should be written like this:

println!("Error: {}", e);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions