Merge pull request #164 from dtolnay/frombacktrace
Fix miscounting fields when from and backtrace are same field
This commit is contained in:
commit
320d70f691
|
@ -180,7 +180,11 @@ fn check_field_attrs(fields: &[Field]) -> Result<()> {
|
|||
}
|
||||
}
|
||||
if let Some(from_field) = from_field {
|
||||
if fields.len() > 1 + has_backtrace as usize {
|
||||
let max_expected_fields = match backtrace_field {
|
||||
Some(backtrace_field) => 1 + !same_member(from_field, backtrace_field) as usize,
|
||||
None => 1 + has_backtrace as usize,
|
||||
};
|
||||
if fields.len() > max_expected_fields {
|
||||
return Err(Error::new_spanned(
|
||||
from_field.attrs.from,
|
||||
"deriving From requires no fields other than source and backtrace",
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
// https://github.com/dtolnay/thiserror/issues/163
|
||||
|
||||
#![feature(backtrace)]
|
||||
|
||||
use std::backtrace::Backtrace;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
#[error("...")]
|
||||
pub struct Error(#[from] #[backtrace] std::io::Error, Backtrace);
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,5 @@
|
|||
error: deriving From requires no fields other than source and backtrace
|
||||
--> tests/ui/from-backtrace-backtrace.rs:10:18
|
||||
|
|
||||
10 | pub struct Error(#[from] #[backtrace] std::io::Error, Backtrace);
|
||||
| ^^^^^^^
|
Loading…
Reference in New Issue