#Warn

#Warn("message") before a declaration makes the compiler report a warning at every call of it, or at every use of a type or constant. The declaration stays usable and the build carries on; the warning points at the call, not at the declaration. It is the way to deprecate a function: callers see the message, with the replacement named, every time they build.

warn-attribute = "#Warn" "(" string-literal ")"
import Io::PrintLine;

#Warn("Average rounds toward zero; call AverageRounded instead")
func Average(total: int, count: int) -> int {
    return total / count;
}

func Main() -> int {
    PrintLine("{}", Average(7, 2));
    return 0;
}
Src/Main.rux:9:21: warning: Average rounds toward zero; call AverageRounded instead

The message must be a string literal (expected a message string in '#Warn' otherwise). As an attribute, #Warn needs no import.

What it applies to

#Warn fires at calls of a function, a method in an extend block, a constructor and an extern func, and at a function named as a value, let f = Average;. On a struct, a constant, a type alias or an enum it fires at every use of the name, once per use: with #Warn("Point is deprecated; use Vector") on struct Point, both Point { x: 1 } and let q: Point = p; report warning: Point is deprecated; use Vector. Uses inside the declaration's own fields and extend blocks are not reported.

The directive form

Written as a statement in a body, or as a when arm, #Warn("…") is a directive that warns where it stands instead — see Build diagnostics.

See also