bevyengine/bevy · error · syn::Error

Consts are not currently supported in this position

Error message

Consts are not currently supported in this position

What it means

When a BSN entry is parsed as a plain path, PathType::new classifies it. A bare const path (PathType::Const — a lone identifier resolving to a constant, not associated with a type) is rejected in entry position with this compile-time syn::Error. Only types, enum variants, associated consts (Type::CONST, PathType::TypeConst) and functions are accepted there.

Source

Thrown at crates/bevy_scene/macros/src/bsn/parse.rs:150

                            enum_variant,
                            fields,
                        };
                        if is_template {
                            BsnEntry::TemplatePatch(bsn_type)
                        } else {
                            BsnEntry::FromTemplatePatch(bsn_type)
                        }
                    }
                }
                PathType::TypeConst => {
                    let const_ident = take_last_path_ident(&mut path).unwrap();
                    BsnEntry::TemplateConst {
                        type_path: path,
                        const_ident,
                    }
                }
                PathType::Const => {
                    return Err(syn::Error::new(
                        path.span(),
                        "Consts are not currently supported in this position",
                    ))
                }
                PathType::TypeFunction => {
                    let function = take_last_path_ident(&mut path).unwrap();
                    let args = input.parse::<BsnFnArgs>()?;
                    let bsn_constructor = BsnConstructor {
                        type_path: path,
                        function,
                        args,
                    };
                    if is_template {
                        BsnEntry::TemplateConstructor(bsn_constructor)
                    } else {
                        BsnEntry::FromTemplateConstructor(bsn_constructor)
                    }
                }

View on GitHub (pinned to 396ca72708)

Solutions

  1. Use an associated const on a type: bsn!(MyType::MY_CONST) — PathType::TypeConst is supported as a template const
  2. Or wrap the value in a component/scene-component form the macro supports (e.g. @MySceneComponent or a function call constructor MyType::new(args))

Example fix

// before
const PLAYER_SPAWN: Spawn = ...;
bsn!(PLAYER_SPAWN); // PathType::Const -> error

// after
impl Player { const SPAWN: Spawn = ...; }
bsn!(Player::SPAWN); // PathType::TypeConst -> template const
Defensive patterns

Strategy: type-guard

Validate before calling

// Before using a const in BSN, make it an associated const:
// impl MyType { pub const VALUE: MyType = ...; }
// then reference MyType::VALUE, which parses as PathType::TypeConst.

Type guard

fn is_associated_const(path: &str) -> bool {
    path.split("::").count() >= 2
}

Prevention

When it happens

Trigger: Writing bsn!(MY_CONST) or bsn!(MY_PATH::CONST) where the last segment is a free-standing const (e.g. a crate-level constant), instead of an associated const on a type.

Common situations: Trying to reference pre-made component values as consts in BSN; confusing a module-level const with a type's associated const; name collisions where an uppercase identifier is actually a const.

Related errors


AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20). Data as JSON: /api/errors/99c2ad21f00f148a. Report an issue: GitHub.