Skip to main content

Function

Struct Function 

Source
pub struct Function {
Show 20 fields pub name: String, pub sig: Signature, pub params: Vec<ObjectId>, pub param_names: Vec<Option<String>>, pub is_static: bool, pub is_inline: bool, pub noreturn: bool, pub inline_hint: Option<InlineHint>, pub cold: bool, pub deprecated: Option<Option<String>>, pub section: Option<String>, pub asm_label: Option<String>, pub init_kind: Option<InitKind>, pub safe: Option<SourceRange>, pub uses_alloca: bool, pub locals: Vec<ObjectId>, pub body: Option<Body>, pub item_name: Option<String>, pub env: Vec<EnvParam>, pub range: SourceRange,
}
Expand description

A function declared or defined in the translation unit.

Fields§

§name: String

The name as written in C.

§sig: Signature

The signature every declaration of it must agree on.

§params: Vec<ObjectId>

The parameter objects. Empty until the definition is seen.

§param_names: Vec<Option<String>>

The parameter names as first declared, for the generated extern block.

§is_static: bool

Whether the function was declared static, i.e. is private to the unit.

§is_inline: bool

Whether the function was declared inline.

§noreturn: bool

Whether the function was declared _Noreturn (or [[noreturn]]), so that a call to it ends the statement it is in.

§inline_hint: Option<InlineHint>

What always_inline / noinline asked for.

§cold: bool

Whether __attribute__((cold)) marked it unlikely.

§deprecated: Option<Option<String>>

The message __attribute__((deprecated)) gave, if it was there at all.

§section: Option<String>

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

§asm_label: Option<String>

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

§init_kind: Option<InitKind>

Whether __attribute__((constructor)) asked for it to run before main, or destructor for after it.

§safe: Option<SourceRange>

Where the function was asked to be safe, if it was: [[cinrs::safe]], __attribute__((cinrs_safe)) or #pragma cinrs safe.

A safe function is generated as extern "C" fn rather than unsafe extern "C" fn, and its body is not wrapped in an unsafe block, so rustc checks it. The range is where the request was written, which is what the diagnostics about it point at.

§uses_alloca: bool

Whether the body calls alloca, in which case the generated item opens with the arena the emulation allocates out of.

alloca’s memory lives until the function returns — not until the end of the block it was called in — so the arena is per function and is dropped by the return, which is exactly that lifetime.

§locals: Vec<ObjectId>

Every automatic object the body declared, in declaration order.

Code generation needs the whole list — not only the ones a let statement is visible for — because a local declared inside a statement expression is a binding too and may need renaming apart.

§body: Option<Body>

The body, present once a definition has been type checked.

§item_name: Option<String>

The Rust item name, when it is not the C name.

Only a lifted GNU nested function has one: it becomes a file-scope item, so it needs a name that cannot collide with the C function of the same name at file scope, while Function::name stays what the program called it — which is what diagnostics and __func__ say.

§env: Vec<EnvParam>

The hidden environment parameters a lifted GNU nested function takes in front of its declared ones, in the order they are passed.

Empty for every ordinary function, and for a nested one that captures nothing — which is why such a nested function’s address may still be taken: the generated item has exactly the signature C gave it.

§range: SourceRange

Where the function’s name was written, at its definition if there is one and at its first declaration otherwise.

Implementations§

Source§

impl Function

Source

pub fn is_extern(&self) -> bool

Whether this function is only declared here and linked from elsewhere.

Source

pub fn item_name(&self) -> &str

The name the generated Rust item has.

Source

pub fn is_nested(&self) -> bool

Whether this is a lifted GNU nested function.

Source

pub fn is_safe(&self) -> bool

Whether the function is generated without unsafe; see Function::safe.

Trait Implementations§

Source§

impl Clone for Function

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 Function

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.