mirror of
https://github.com/dtolnay/thiserror.git
synced 2025-04-06 06:17:39 +03:00
Fix miscounting fields when from and backtrace are same field
This commit is contained in:
parent
8602ca3dd2
commit
c4d7c2b135
2 changed files with 8 additions and 4 deletions
|
@ -180,7 +180,11 @@ fn check_field_attrs(fields: &[Field]) -> Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(from_field) = from_field {
|
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(
|
return Err(Error::new_spanned(
|
||||||
from_field.attrs.from,
|
from_field.attrs.from,
|
||||||
"deriving From requires no fields other than source and backtrace",
|
"deriving From requires no fields other than source and backtrace",
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error[E0063]: missing field `1` in initializer of `Error`
|
error: deriving From requires no fields other than source and backtrace
|
||||||
--> tests/ui/from-backtrace-backtrace.rs:10:12
|
--> tests/ui/from-backtrace-backtrace.rs:10:18
|
||||||
|
|
|
|
||||||
10 | pub struct Error(#[from] #[backtrace] std::io::Error, Backtrace);
|
10 | pub struct Error(#[from] #[backtrace] std::io::Error, Backtrace);
|
||||||
| ^^^^^ missing `1`
|
| ^^^^^^^
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue