| 107 | } |
| 108 | |
| 109 | fn check_non_field_attrs(attrs: &Attrs) -> Result<()> { |
| 110 | if let Some(from) = &attrs.from { |
| 111 | return Err(Error::new_spanned( |
| 112 | from.original, |
| 113 | "not expected here; the #[from] attribute belongs on a specific field", |
| 114 | )); |
| 115 | } |
| 116 | if let Some(source) = &attrs.source { |
| 117 | return Err(Error::new_spanned( |
| 118 | source.original, |
| 119 | "not expected here; the #[source] attribute belongs on a specific field", |
| 120 | )); |
| 121 | } |
| 122 | if let Some(backtrace) = &attrs.backtrace { |
| 123 | return Err(Error::new_spanned( |
| 124 | backtrace, |
| 125 | "not expected here; the #[backtrace] attribute belongs on a specific field", |
| 126 | )); |
| 127 | } |
| 128 | if attrs.transparent.is_some() { |
| 129 | if let Some(display) = &attrs.display { |
| 130 | return Err(Error::new_spanned( |
| 131 | display.original, |
| 132 | "cannot have both #[error(transparent)] and a display attribute", |
| 133 | )); |
| 134 | } |
| 135 | if let Some(fmt) = &attrs.fmt { |
| 136 | return Err(Error::new_spanned( |
| 137 | fmt.original, |
| 138 | "cannot have both #[error(transparent)] and #[error(fmt = ...)]", |
| 139 | )); |
| 140 | } |
| 141 | } else if let (Some(display), Some(_)) = (&attrs.display, &attrs.fmt) { |
| 142 | return Err(Error::new_spanned( |
| 143 | display.original, |
| 144 | "cannot have both #[error(fmt = ...)] and a format arguments attribute", |
| 145 | )); |
| 146 | } |
| 147 | |
| 148 | Ok(()) |
| 149 | } |
| 150 | |
| 151 | fn check_field_attrs(fields: &[Field]) -> Result<()> { |
| 152 | let mut from_field = None; |