docs / Getting Started / Attributes

Attributes

An attribute is written @name above a declaration, optionally with a string argument. Attributes are a closed set: the compiler knows every one it accepts and rejects anything else with an error. A misspelled attribute can therefore never be silently ignored, which is the failure mode that makes attributes untrustworthy in other languages — @tset is a compile error, not a test that quietly never runs.

use system.io

// @non_exhaustive: this enum may gain variants later, so a match on it
// outside the defining module must carry a default arm.
@non_exhaustive
public enum ConnectionError
    Refused(String)
    TimedOut(int)

// @must_use: the value may not be silently discarded at a call site.
@must_use
public enum Receipt
    Written(int)

// @deprecated carries the replacement, and callers get a warning.
@deprecated("acquire a Clock and use clock.now()")
fn legacy_timestamp() int
    0

fn main()
    println("attributes are a closed set — an unknown one is a compile error")
AttributeApplies toArgumentEffect
@non_exhaustiveEnumThe enum may gain variants, so a match on it outside the defining module needs a default arm.
@must_useEnumThe value may not be silently discarded at a call site.
@deprecatedFunction, class, enumRequiredCallers get a warning carrying the message — normally the replacement to use.
@testFunctionMarks the function for discovery by miri test.
@ignoreFunctionRequiredSkips the test and reports the reason. Requires @test.
@xfailFunctionRequiredThe test is expected to fail. Requires @test.

Applying an attribute to the wrong kind of declaration, omitting a required argument, or passing one where none is accepted are all errors as well — as is using @ignore or @xfail without the @test they depend on.