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

Unhelpful diagnostic on variant containing #[from] #[backtrace] Error, Backtrace #163

Closed
dtolnay opened this issue Dec 18, 2021 · 0 comments · Fixed by #164
Closed

Unhelpful diagnostic on variant containing #[from] #[backtrace] Error, Backtrace #163

dtolnay opened this issue Dec 18, 2021 · 0 comments · Fixed by #164

Comments

@dtolnay
Copy link
Owner

dtolnay commented Dec 18, 2021

#![feature(backtrace)]

use std::backtrace::Backtrace;
use thiserror::Error;

#[derive(Error, Debug)]
#[error("...")]
pub struct Error(#[from] #[backtrace] std::io::Error, Backtrace);
error[E0063]: missing field `1` in initializer of `Error`
 --> src/main.rs:8:12
  |
8 | pub struct Error(#[from] #[backtrace] std::io::Error, Backtrace);
  |            ^^^^^ missing `1`

With the following change it compiles successfully, which is expected:

- pub struct Error(#[from] #[backtrace] std::io::Error, Backtrace);
+ pub struct Error(#[from] std::io::Error, Backtrace);

and with the following change it produces a helpful diagnostic similar to what I think we should expect in the original case:

- pub struct Error(#[from] std::io::Error, Backtrace);
+ pub struct Error(#[from] std::io::Error, String);
error: deriving From requires no fields other than source and backtrace
 --> src/main.rs:8:18
  |
8 | pub struct Error(#[from] std::io::Error, String);
  |                  ^^^^^^^
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.

1 participant