Ruta graveolens  ·  notes from a language experiment  ·  cultivated since 2025

Items

Items

This chapter describes items in Rue.

Items are top-level definitions in a program. Unlike statements, items are visible throughout the module.

Type Name Uniqueness

User-defined type names (structs and enums) MUST be unique within a program. Defining multiple types with the same name produces a compile-time error.

User-defined types MUST NOT use names reserved for built-in types. Currently, the only reserved type name is String.

// Error: cannot define type with reserved name
struct String { data: i32 }  // compile error

User-defined functions MUST NOT use names reserved for runtime and code-generation helpers. The reserved function names are exactly: any name beginning with __rue_, and the program entry point _start. Every compiler- and runtime-emitted symbol — including built-in type methods and associated functions (__rue_String_len, __rue_String_new) — lives under the __rue_ prefix, so the reserved set does not grow as built-in types are added. Defining a function with a reserved name produces a compile-time error.

// Error: cannot define function with reserved name
fn __rue_alloc() -> i32 { 0 }  // compile error: `__rue_` prefix is reserved

// OK: `String__len` is an ordinary identifier, distinct from the built-in
// `String::len` method (whose runtime symbol is `__rue_String_len`).
fn String__len() -> i32 { 0 }  // allowed

In this section