[][src]Struct c2rust_refactor::transform::statics::Localize

pub struct Localize;

static_to_local_ref Command

Usage: static_to_local_ref

Marks: target, user

For each function marked user, replace uses of statics marked target with uses of newly-introduced reference arguments. Afterward, no user function directly accesses any target static. At call sites of user functions, a reference to the original static is passed in for each new argument if the caller is not itself a user function; otherwise, the caller's own reference argument is passed through. Note this sometimes results in functions gaining arguments corresponding to statics that the function itself does not use, but that its callees do.

Example:

static mut FOO: i32 = 100;  // FOO: target

unsafe fn f() -> i32 {  // f: user
    FOO
}

unsafe fn g() -> i32 {  // g: user
    f()
}

unsafe fn h() -> i32 {
    g()
}

After running static_to_local_ref:

static mut FOO: i32 = 100;

// `f` is a `user` that references `FOO`, so it
// gains a new argument `FOO_`.
unsafe fn f(FOO_: &mut i32) -> i32 {
    // References to `FOO` are replaced with `*FOO_`
    *FOO_
}

// `g` is a `user` that references `FOO` indirectly,
// via fellow `user` `f`.
unsafe fn g(FOO_: &mut i32) -> i32 {
    // `g` passes through its own `FOO_` reference
    // when calling `f`.
    f(FOO_)
}

// `h` is not a `user`, so its signature is unchanged.
unsafe fn h() -> i32 {
    // `h` passes in a reference to the original
    // static `FOO`.
    g(&mut FOO)
}

Trait Implementations

impl Transform for Localize[src]

fn min_phase(&self) -> Phase[src]

Return the minimum phase at which this transform can operate. See the Phase docs for details. The default is Phase2. Read more

Auto Trait Implementations

impl Send for Localize

impl Sync for Localize

Blanket Implementations

impl<T> Lone for T[src]

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<E> SpecializationError for E[src]

impl<T> Erased for T[src]

impl<T> Send for T where
    T: ?Sized
[src]

impl<T> Sync for T where
    T: ?Sized
[src]

impl<T> Same for T

type Output = T

Should always be Self

impl<T> MaybeResult for T[src]

impl<'a, T> Captures for T where
    T: ?Sized
[src]

impl<T> Erased for T

impl<T> Make for T[src]

impl<T> Slottable for T[src]