Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Option<SourceError> and Option<Backtrace> #1

Closed
mathstuf opened this issue Oct 9, 2019 · 2 comments · Fixed by #29
Closed

Support Option<SourceError> and Option<Backtrace> #1

mathstuf opened this issue Oct 9, 2019 · 2 comments · Fixed by #29

Comments

@mathstuf
Copy link
Contributor

mathstuf commented Oct 9, 2019

This should be possible:

enum MyErr {
    OptSource {
        #[source]
        source: Option<io::Error>,
    },
}
@dtolnay
Copy link
Owner

dtolnay commented Oct 9, 2019

Thanks, I agree. I will get to this in the next few days if someone doesn't beat me with a PR.

We'd probably want Option<Backtrace> too.

@mathstuf
Copy link
Contributor Author

mathstuf commented Oct 9, 2019

I took a quick look. It seems that it is done on the first entry found using the #[source] macro (meaning that duplicate #[source] entries are silently ignored). I don't know if it's better to add a new #[opt_source] attribute or try and divine the Option out from the literal type given. A new attribute seems more likely to be implementable.

There should probably also be a #[backtrace] attribute in case some type aliasing shenanigans is going on (it seems that it just wants the last path component to be the literal Backtrace at the moment). This probably means that #[opt_backtrace] would be the way to go there.

@dtolnay dtolnay changed the title Support #[source] on Option<SourceError> Support on Option<SourceError> and Option<Backtrace> Oct 10, 2019
@dtolnay dtolnay changed the title Support on Option<SourceError> and Option<Backtrace> Support Option<SourceError> and Option<Backtrace> Oct 10, 2019
dtolnay added a commit that referenced this issue Sep 13, 2022
Currently fails with:

    error[E0034]: multiple applicable items in scope
       --> tests/test_backtrace.rs:165:13
        |
    165 |             x: std::io::Error,
        |             ^ multiple `provide` found
        |
        = note: candidate #1 is defined in an impl of the trait `Provider` for the type `E`
        = note: candidate #2 is defined in an impl of the trait `std::error::Error` for the type `std::io::Error`
    help: disambiguate the associated function for candidate #1
        |
    165 |             Provider::provide(&x, Error): std::io::Error,
        |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    help: disambiguate the associated function for candidate #2
        |
    165 |             std::error::Error::provide(&x, Error): std::io::Error,
        |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dtolnay added a commit that referenced this issue Nov 4, 2024
    error[E0599]: `test_no_bound_on_named_fmt::Error<DebugOnly>` doesn't implement `std::fmt::Display`
       --> tests/test_generics.rs:173:22
        |
    168 |     struct Error<T> {
        |     --------------- method `to_string` not found for this struct because it doesn't satisfy `_: Display` or `_: ToString`
    ...
    173 |     assert_eq!(error.to_string(), "...");
        |                      ^^^^^^^^^ `test_no_bound_on_named_fmt::Error<DebugOnly>` cannot be formatted with the default formatter
        |
        = note: the following trait bounds were not satisfied:
                `test_no_bound_on_named_fmt::Error<DebugOnly>: std::fmt::Display`
                which is required by `test_no_bound_on_named_fmt::Error<DebugOnly>: ToString`
        = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
    note: the trait `std::fmt::Display` must be implemented
       --> $RUSTUP_HOME/toolchains/nightly-aarch64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:727:1
        |
    727 | pub trait Display {
        | ^^^^^^^^^^^^^^^^^
        = help: items from traits can only be used if the trait is implemented and in scope
        = note: the following trait defines an item `to_string`, perhaps you need to implement it:
                candidate #1: `ToString`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants