Struct rustc::middle::region::Scope [] [src]

pub struct Scope { /* fields omitted */ }
🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

Scope represents a statically-describable scope that can be used to bound the lifetime/region for values.

Node(node_id): Any AST node that has any scope at all has the Node(node_id) scope. Other variants represent special cases not immediately derivable from the abstract syntax tree structure.

DestructionScope(node_id) represents the scope of destructors implicitly-attached to node_id that run immediately after the expression for node_id itself. Not every AST node carries a DestructionScope, but those that are terminating_scopes do; see discussion with ScopeTree.

Remainder(BlockRemainder { block, statement_index }) represents the scope of user code running immediately after the initializer expression for the indexed statement, until the end of the block.

So: the following code can be broken down into the scopes beneath: let a = f().g( 'b: { let x = d(); let y = d(); x.h(y) } ) ;

+-+ (D12.)
                                                   +-+       (D11.)
                                         +---------+         (R10.)
                                         +-+                  (D9.)
                              +----------+                    (M8.)
                            +----------------------+          (R7.)
                            +-+                               (D6.)
                 +----------+                                 (M5.)
               +-----------------------------------+          (M4.)
    +--------------------------------------------------+      (M3.)
    +--+                                                      (M2.)

+-----------------------------------------------------------+ (M1.)

(M1.): Node scope of the whole let a = ...; statement. (M2.): Node scope of the f() expression. (M3.): Node scope of the f().g(..) expression. (M4.): Node scope of the block labeled 'b:. (M5.): Node scope of the let x = d(); statement (D6.): DestructionScope for temporaries created during M5. (R7.): Remainder scope for block 'b:, stmt 0 (let x = ...). (M8.): Node scope of the let y = d(); statement. (D9.): DestructionScope for temporaries created during M8. (R10.): Remainder scope for block 'b:, stmt 1 (let y = ...). (D11.): DestructionScope for temporaries and bindings from block 'b:. (D12.): DestructionScope for temporaries created during M1 (e.g. f()).

Note that while the above picture shows the destruction scopes as following their corresponding node scopes, in the internal data structures of the compiler the destruction scopes are represented as enclosing parents. This is sound because we use the enclosing parent relationship just to ensure that referenced values live long enough; phrased another way, the starting point of each range is not really the important thing in the above picture, but rather the ending point.

FIXME (pnkfelix): This currently derives PartialOrd and Ord to placate the same deriving in ty::FreeRegion, but we may want to actually attach a more meaningful ordering to scopes than the one generated via deriving here.

Scope is a bit-packed to save space - if code is SCOPE_DATA_REMAINDER_MAX or less, it is a ScopeData::Remainder, otherwise it is a type specified by the bitpacking.

Methods

impl Scope
[src]

[src]

🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

[src]

🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

[src]

🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

[src]

🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

[src]

🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

[src]

🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

impl Scope
[src]

[src]

🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

Returns a item-local id associated with this scope.

NB: likely to be replaced as API is refined; e.g. pnkfelix anticipates fn entry_node_id and fn each_exit_node_id.

[src]

🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

[src]

🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

Returns the span of this Scope. Note that in general the returned span may not correspond to the span of any node id in the AST.

Trait Implementations

impl<'tcx> HashStable<StableHashingContext<'tcx>> for Scope
[src]

[src]

🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

impl<'gcx> ToStableHashKey<StableHashingContext<'gcx>> for Scope
[src]

🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

[src]

🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

impl Clone for Scope
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl PartialEq for Scope
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl PartialOrd for Scope
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

[src]

This method tests less than (for self and other) and is used by the < operator. Read more

[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl Eq for Scope
[src]

impl Ord for Scope
[src]

[src]

This method returns an Ordering between self and other. Read more

1.21.0
[src]

Compares and returns the maximum of two values. Read more

1.21.0
[src]

Compares and returns the minimum of two values. Read more

impl Hash for Scope
[src]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl Copy for Scope
[src]

impl Encodable for Scope
[src]

[src]

🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

impl Decodable for Scope
[src]

[src]

🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

impl From<ScopeData> for Scope
[src]

[src]

Performs the conversion.

impl Debug for Scope
[src]

[src]

Formats the value using the given formatter. Read more