Module util

Source

Structsยง

ExprToSpannedString ๐Ÿ”’

Functionsยง

check_builtin_macro_attribute ๐Ÿ”’
check_zero_tts ๐Ÿ”’
Non-fatally assert that tts is empty. Note that this function returns even when tts is non-empty, macros that need to stop compilation should call cx.diagnostic().abort_if_errors() (this should be done as rarely as possible).
expr_to_spanned_string ๐Ÿ”’
Extracts a string literal from the macro expanded version of expr, returning a diagnostic error of err_msg if expr is not a string literal. The returned bool indicates whether an applicable suggestion has already been added to the diagnostic to avoid emitting multiple suggestions. Err(Err(ErrorGuaranteed)) indicates that an ast error was encountered.
expr_to_string ๐Ÿ”’
Extracts a string literal from the macro expanded version of expr, emitting err_msg if expr is not a string literal. This does not stop compilation on error, merely emits a non-fatal error and returns Err.
get_exprs_from_tts ๐Ÿ”’
Extracts comma-separated expressions from tts. On error, emit it, and return Err.
get_single_expr_from_tts ๐Ÿ”’
Interpreting tts as a comma-separated sequence of expressions, expect exactly one expression, or emit an error and return Err.
get_single_str_from_tts ๐Ÿ”’
Interpreting tts as a comma-separated sequence of expressions, expect exactly one string literal, or emit an error and return Err.
get_single_str_spanned_from_tts ๐Ÿ”’
parse_expr ๐Ÿ”’
Parse an expression. On error, emit it, advancing to Eof, and return Err.
warn_on_duplicate_attribute ๐Ÿ”’
Emit a warning if the item is annotated with the given attribute. This is used to diagnose when an attribute may have been mistakenly duplicated.

Type Aliasesยง

ExprToSpannedStringResult ๐Ÿ”’
Ok represents successfully retrieving the string literal at the correct position, e.g., println("abc").
UnexpectedExprKind ๐Ÿ”’
Ok is returned when the conversion to a string literal is unsuccessful, but another type of expression is obtained instead.Err is returned when the conversion process fails.