Skip to content

Commit

Permalink
hard panic when no #[fallback] is found
Browse files Browse the repository at this point in the history
If you're missing the `#[fallback]` variant, you will see an error like
this:

```
error: proc-macro derive panicked
  --> crates/oxide/src/extractor/string_machine.rs:71:45
   |
71 | #[derive(Debug, Clone, Copy, PartialEq, Eq, ClassifyBytes)]
   |                                             ^^^^^^^^^^^^^
   |
   = help: message: A variant marked with #[fallback] is missing
```
  • Loading branch information
RobinMalfait committed Mar 5, 2025
1 parent 17261db commit 5f22c13
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions crates/classification-macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use proc_macro::TokenStream;
use proc_macro2::Span;
use quote::quote;
use syn::{
parse_macro_input, punctuated::Punctuated, token::Comma, Attribute, Data, DataEnum,
Expand Down Expand Up @@ -84,7 +83,7 @@ pub fn classify_bytes_derive(input: TokenStream) -> TokenStream {
}

// If no fallback variant is found, default to "Other"
let fallback_ident = fallback_variant.unwrap_or_else(|| Ident::new("Other", Span::call_site()));
let fallback_ident = fallback_variant.expect("A variant marked with #[fallback] is missing");

// For each of the 256 byte values, fill the table
let fill = byte_map
Expand Down

0 comments on commit 5f22c13

Please sign in to comment.