Parse `#[zeroize(...)]` attribute metadata (e.g. `drop`)
(&mut self, meta: &Meta, variant: Option<&Variant>, binding: Option<&Field>)
| 231 | |
| 232 | /// Parse `#[zeroize(...)]` attribute metadata (e.g. `drop`) |
| 233 | fn parse_meta(&mut self, meta: &Meta, variant: Option<&Variant>, binding: Option<&Field>) { |
| 234 | if meta.path().is_ident("drop") { |
| 235 | assert!(!self.drop, "duplicate #[zeroize] drop flags"); |
| 236 | |
| 237 | match (variant, binding) { |
| 238 | (_variant, Some(_binding)) => { |
| 239 | // structs don't have a variant prefix, and only structs have bindings outside of a variant |
| 240 | let item_kind = match variant { |
| 241 | Some(_) => "enum", |
| 242 | None => "struct", |
| 243 | }; |
| 244 | panic!( |
| 245 | concat!( |
| 246 | "The #[zeroize(drop)] attribute is not allowed on {} fields. ", |
| 247 | "Use it on the containing {} instead.", |
| 248 | ), |
| 249 | item_kind, item_kind, |
| 250 | ) |
| 251 | } |
| 252 | (Some(_variant), None) => panic!(concat!( |
| 253 | "The #[zeroize(drop)] attribute is not allowed on enum variants. ", |
| 254 | "Use it on the containing enum instead.", |
| 255 | )), |
| 256 | (None, None) => (), |
| 257 | }; |
| 258 | |
| 259 | self.drop = true; |
| 260 | } else if meta.path().is_ident("bound") { |
| 261 | assert!(self.bound.is_none(), "duplicate #[zeroize] bound flags"); |
| 262 | |
| 263 | match (variant, binding) { |
| 264 | (_variant, Some(_binding)) => { |
| 265 | // structs don't have a variant prefix, and only structs have bindings outside of a variant |
| 266 | let item_kind = match variant { |
| 267 | Some(_) => "enum", |
| 268 | None => "struct", |
| 269 | }; |
| 270 | panic!( |
| 271 | concat!( |
| 272 | "The #[zeroize(bound)] attribute is not allowed on {} fields. ", |
| 273 | "Use it on the containing {} instead.", |
| 274 | ), |
| 275 | item_kind, item_kind, |
| 276 | ) |
| 277 | } |
| 278 | (Some(_variant), None) => panic!(concat!( |
| 279 | "The #[zeroize(bound)] attribute is not allowed on enum variants. ", |
| 280 | "Use it on the containing enum instead.", |
| 281 | )), |
| 282 | (None, None) => { |
| 283 | if let Meta::NameValue(meta_name_value) = meta { |
| 284 | if let Expr::Lit(ExprLit { |
| 285 | lit: Lit::Str(lit), .. |
| 286 | }) = &meta_name_value.value |
| 287 | { |
| 288 | if lit.value().is_empty() { |
| 289 | self.bound = Some(Bounds(Punctuated::new())); |
| 290 | } else { |
no test coverage detected