Struct AstVariableDeclaration

pub struct AstVariableDeclaration {
    pub node_id: AstNodeId,
    pub is_declaration_only: bool,
    pub is_file_scope: bool,
    pub declared_type: AstDeclaredType,
    pub ident: AstIdentifier,
    pub unique_name: AstUniqueName,
    pub initializer: Option<AstVariableInitializer>,
    pub init_constant_eval: Vec<AstStaticStorageInitializer>,
    pub linkage: AstLinkage,
    pub storage: AstStorageDuration,
}
Expand description

A variable declaration with optional definition.

The is_declaration_only field specifies whether the variable is a declaration only, or if it’s a declaration and definition. A variable can be defined even if there is no init_expr, e.g. in file scope or a static variable declaration in block scope. In both of those cases, the variable is a definition but has no initializer, and will get a default value of zero.

If is_declaration_only is true, then the declaration only introduces the variable’s name and type, and does not allocate any storage for it. For example, extern int i; or struct Foo;.

Note that extern int i = 3; is a definition and the extern is ignored (and a warning is emitted).

If the initializer expression can be evaluated at compile-time (i.e. it’s a constant expression) then the result of its evaluation is stored in init_constant_eval. The sema stage is responsible for this evaluation. The evaluation is a Vec because a static storage variable of array type may have more than one initializer value. Scalar types will only have one value.

Fields§

§node_id: AstNodeId§is_declaration_only: bool§is_file_scope: bool§declared_type: AstDeclaredType§ident: AstIdentifier§unique_name: AstUniqueName§initializer: Option<AstVariableInitializer>§init_constant_eval: Vec<AstStaticStorageInitializer>§linkage: AstLinkage§storage: AstStorageDuration

Trait Implementations§

§

impl Debug for AstVariableDeclaration

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.