Skip to content

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

@dtolnay

Description

@dtolnay
#![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);
  |                  ^^^^^^^

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions