sun::borrow_checker::Lifetime
class · Source (opens in a new tab)
class sun::borrow_checker::LifetimeRepresents the lifetime of a reference - how long it remains valid.
Lifetimes form a partial order based on scope containment.
Key invariants:
- Static lifetime outlives everything
- Param lifetimes outlive the function body (caller's scope)
- Local lifetimes are bounded by their declaring scope
- A reference's lifetime must not exceed its target's lifetime
Functions
Lifetime
Lifetime()
public · function · Source (opens in a new tab)
sun::borrow_checker::Lifetime::Lifetime()Default constructor creates an anonymous lifetime.
Lifetime(Kind k, uint32_t id, std::string name, size_t depth)
private · function · Source (opens in a new tab)
sun::borrow_checker::Lifetime::Lifetime(Kind k, uint32_t id, std::string name, size_t depth)Creates a lifetime identity with its scope depth and optional name.
Related: Kind
Public Functions
- anonymous
- equals
- getId
- getKind
- getName
- getScopeDepth
- isAnonymous
- isLocal
- isParam
- isStatic
- local
- outlives
- param
- static_
- toString
anonymous
public · function · static · Source (opens in a new tab)
static Lifetime sun::borrow_checker::Lifetime::anonymous(uint32_t id)Create an anonymous lifetime with unique ID.
param
id: Unique identifier for this lifetime
Related: Lifetime
equals
public · function · Source (opens in a new tab)
bool sun::borrow_checker::Lifetime::equals(const Lifetime &other) constCheck if two lifetimes are equivalent (mutually outlive).
Related: Lifetime
getId
public · function · Source (opens in a new tab)
uint32_t sun::borrow_checker::Lifetime::getId() constReturns the object identifier.
getKind
public · function · Source (opens in a new tab)
Kind sun::borrow_checker::Lifetime::getKind() constReturns the type category used for semantic checks and dispatch.
Related: Kind
getName
public · function · Source (opens in a new tab)
const std::string & sun::borrow_checker::Lifetime::getName() constReturns the declared name used to identify this object.
getScopeDepth
public · function · Source (opens in a new tab)
size_t sun::borrow_checker::Lifetime::getScopeDepth() constReturns the scope depth stored by this object.
isAnonymous
public · function · Source (opens in a new tab)
bool sun::borrow_checker::Lifetime::isAnonymous() constCheck if this is an anonymous lifetime.
isLocal
public · function · Source (opens in a new tab)
bool sun::borrow_checker::Lifetime::isLocal() constCheck if this is a local variable lifetime.
isParam
public · function · Source (opens in a new tab)
bool sun::borrow_checker::Lifetime::isParam() constCheck if this is a parameter lifetime.
isStatic
public · function · Source (opens in a new tab)
bool sun::borrow_checker::Lifetime::isStatic() constCheck if this is a static lifetime.
local
public · function · static · Source (opens in a new tab)
static Lifetime sun::borrow_checker::Lifetime::local(const std::string &varName, size_t scopeDepth)Create a lifetime bound to a local variable.
param
-
varName: The variable name (for error messages) -
scopeDepth: The scope nesting level where declared
Related: Lifetime
outlives
public · function · Source (opens in a new tab)
bool sun::borrow_checker::Lifetime::outlives(const Lifetime &other) constCheck if this lifetime outlives another.
Returns true if this is valid everywhere other is valid.
Outlives relationships:
- Static outlives everything
- Param outlives Local (param lives in caller's scope)
- Local at depth N outlives Local at depth M where N < M
- Same-kind lifetimes with same name/id are equal (outlive each other)
Related: Lifetime
param
public · function · static · Source (opens in a new tab)
static Lifetime sun::borrow_checker::Lifetime::param(const std::string ¶mName)Create a lifetime bound to a function parameter.
param
paramName: The parameter name (for error messages)
Related: Lifetime
static_
public · function · static · Source (opens in a new tab)
static Lifetime sun::borrow_checker::Lifetime::static_()Create a static lifetime (outlives everything).
Related: Lifetime
toString
public · function · Source (opens in a new tab)
std::string sun::borrow_checker::Lifetime::toString() constFormat lifetime for error messages.
Public Enums
Kind
public · enum · Source (opens in a new tab)
enum class sun::borrow_checker::Lifetime::KindThe kind of lifetime determines its scope behavior.
Static
Static
'static - lives for the entire program (e.g., string literals, globals)
Param
Param
Bound to a function parameter - outlives the function body since the caller owns the referenced data.
Local
Local
Bound to a local variable - dies when variable goes out of scope.
Anonymous
Anonymous
Anonymous/inferred lifetime - assigned during analysis.
Private Fields
id_
private · variable · Source (opens in a new tab)
uint32_t sun::borrow_checker::Lifetime::id_No documentation comment.
kind_
private · variable · Source (opens in a new tab)
Kind sun::borrow_checker::Lifetime::kind_No documentation comment.
Related: Kind
name_
private · variable · Source (opens in a new tab)
std::string sun::borrow_checker::Lifetime::name_No documentation comment.
scopeDepth_
private · variable · Source (opens in a new tab)
size_t sun::borrow_checker::Lifetime::scopeDepth_No documentation comment.