Skip to content

Commit c4d7c2b

Browse files
committed
Fix miscounting fields when from and backtrace are same field
1 parent 8602ca3 commit c4d7c2b

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

impl/src/valid.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,11 @@ fn check_field_attrs(fields: &[Field]) -> Result<()> {
180180
}
181181
}
182182
if let Some(from_field) = from_field {
183-
if fields.len() > 1 + has_backtrace as usize {
183+
let max_expected_fields = match backtrace_field {
184+
Some(backtrace_field) => 1 + !same_member(from_field, backtrace_field) as usize,
185+
None => 1 + has_backtrace as usize,
186+
};
187+
if fields.len() > max_expected_fields {
184188
return Err(Error::new_spanned(
185189
from_field.attrs.from,
186190
"deriving From requires no fields other than source and backtrace",
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
error[E0063]: missing field `1` in initializer of `Error`
2-
--> tests/ui/from-backtrace-backtrace.rs:10:12
1+
error: deriving From requires no fields other than source and backtrace
2+
--> tests/ui/from-backtrace-backtrace.rs:10:18
33
|
44
10 | pub struct Error(#[from] #[backtrace] std::io::Error, Backtrace);
5-
| ^^^^^ missing `1`
5+
| ^^^^^^^

0 commit comments

Comments
 (0)