Skip to main content

Object

Struct Object 

Source
pub struct Object {
    pub name: String,
    pub ty: Ty,
    pub storage: Storage,
    pub is_const: bool,
    pub is_register: bool,
    pub vla_storage: bool,
    pub align: Option<u64>,
    pub flexible_len: Option<u64>,
    pub asm_label: Option<String>,
    pub section: Option<String>,
    pub range: SourceRange,
}
Expand description

A named object.

Fields§

§name: String

The name as written in C.

§ty: Ty

The object’s type.

§storage: Storage

How the object is stored.

§is_const: bool

Whether the object’s type is const-qualified.

§is_register: bool

Whether the declaration said register.

The specifier is a hint about speed that this crate has nothing to do with — Rust decides where a local lives — but it has one rule with teeth: C11 6.7.1p6 says the address of such an object “cannot be computed, either explicitly (by use of the unary & operator as discussed in 6.5.3.2) or implicitly (by converting an array name to a pointer as discussed in 6.3.2.1)”, so sizeof is the only operator an array declared register can be the operand of. WG14 DR116 is that rule; drs/dr1xx.c is where it is checked.

§vla_storage: bool

Set when this is the hidden frame of a variable length array: the mark of the function’s bump arena taken just before the elements were allocated, in which case Object::ty is the element type and the generated binding is the arena’s frame guard (a slot of the function’s array of marks in CFG mode).

It is not an object of the C program at all; it exists so that the arena moves back down to the mark when the block ends, which is the lifetime C gives the array.

§align: Option<u64>

The alignment _Alignas(N) or __attribute__((aligned(N))) asked for, when it is stricter than the one the type already has.

Rust has no way to over-align a binding, so the object is generated inside a one-field wrapper that carries the alignment — #[repr(C, align(N))] struct __cinrs_align_N<T>(pub T); — and every access to it goes through the field. The C object’s type is unchanged: sizeof is the type’s size and the wrapper is invisible to everything but the generated binding. See codegen.

None is the ordinary case, and also what a request no stricter than the natural alignment leaves behind — there is nothing for a wrapper to say.

§flexible_len: Option<u64>

How many elements the object’s storage gives the record’s flexible array member, when an initialiser filled it in.

GNU C lets an object with static storage duration initialise the member (static struct W w = { 3, { 1, 2, 3 } };), which makes the object larger than its own type — something Rust has no way to say about a value of type W. The item is therefore given a companion type with the same leading layout and a tail of this length, __cinrs_W_3, and every use of the object is a place reached through (*(&raw mut w).cast::<W>()). sizeof w is still sizeof(struct W), which is what GCC says too. See codegen.

§asm_label: Option<String>

The symbol __asm__("name") renamed the object to.

§section: Option<String>

The section __attribute__((section("…"))) asked for.

§range: SourceRange

Where the declarator was written.

Trait Implementations§

Source§

impl Clone for Object

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Object

Source§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.