GraphiteEditor/Graphite · error · syn::Error

Tried to derive AsMessage for non-enum

Error message

Tried to derive AsMessage for non-enum

What it means

The AsMessage derive (proc-macros/src/as_message.rs) only generates code for enums — it builds per-variant globs and #[child]-aware handling. Applying the derive to a struct or union falls through the Data::Enum match and yields this compile-time error at the call site.

Source

Thrown at proc-macros/src/as_message.rs:9

use proc_macro2::{Span, TokenStream};
use syn::{Data, DeriveInput};

pub fn derive_as_message_impl(input_item: TokenStream) -> syn::Result<TokenStream> {
	let input = syn::parse2::<DeriveInput>(input_item).unwrap();

	let data = match input.data {
		Data::Enum(data) => data,
		_ => return Err(syn::Error::new(Span::call_site(), "Tried to derive AsMessage for non-enum")),
	};

	let input_type = input.ident;

	let (globs, names) = data
		.variants
		.iter()
		.map(|var| {
			let var_name = &var.ident;
			let var_name_s = var.ident.to_string();
			if var.attrs.iter().any(|a| a.path().is_ident("child")) {
				(
					quote::quote! {
						#input_type::#var_name(child)
					},
					quote::quote! {
						format!("{}.{}", #var_name_s, child.local_name())
					},

View on GitHub (pinned to c507b35645)

Solutions

  1. Remove the AsMessage derive from the struct or union
  2. Convert the type to an enum if it must participate in the message hierarchy (variants may carry #[child])
  3. Hand-implement the trait if the struct genuinely must remain a struct

Example fix

// before
#[derive(AsMessage)]
struct MyMessage { field: u32 }

// after
#[derive(AsMessage)]
enum MyMessage {
	#[child]
	VariantOne(u32),
	VariantTwo,
}
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: #[derive(AsMessage)] (or a derive chain that includes it) placed on a struct or union instead of an enum.

Common situations: Refactoring an enum message type into a struct during cleanup while the derive stays attached; adding the derive via IDE quick-fix on the wrong item.

Related errors


AI-assisted analysis of GraphiteEditor/Graphite@c507b35645 (2026-08-16). Data as JSON: /api/errors/a6b3bc69d8dee1cc. Report an issue: GitHub.