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

pub struct Scope {
    pub id: ItemLocalId,
    pub data: ScopeData,

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 { 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.


id: ItemLocalIddata: ScopeData


impl Scope[src]

pub fn item_local_id(&self) -> ItemLocalId[src]

Returns a item-local ID associated with this scope.

N.B., likely to be replaced as API is refined; e.g., pnkfelix anticipates fn entry_node_id and fn each_exit_node_id.

pub fn hir_id(&self, scope_tree: &ScopeTree) -> Option<HirId>[src]

pub fn span(&self, tcx: TyCtxt<'_>, scope_tree: &ScopeTree) -> Span[src]

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

Trait Implementations

impl Clone for Scope[src]

impl Copy for Scope[src]

impl Debug for Scope[src]

impl<'tcx, __D: TyDecoder<'tcx>> Decodable<__D> for Scope[src]

impl<'tcx, __E: TyEncoder<'tcx>> Encodable<__E> for Scope[src]

impl Eq for Scope[src]

impl Hash for Scope[src]

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

impl<'tcx> Lift<'tcx> for Scope[src]

type Lifted = Self

impl Ord for Scope[src]

impl PartialEq<Scope> for Scope[src]

impl PartialOrd<Scope> for Scope[src]

impl StructuralEq for Scope[src]

impl StructuralPartialEq for Scope[src]

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

impl<'tcx> TypeFoldable<'tcx> for Scope[src]

Auto Trait Implementations

impl RefUnwindSafe for Scope

impl Send for Scope

impl Sync for Scope

impl Unpin for Scope

impl UnwindSafe for Scope

Blanket Implementations

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

impl<'tcx, T> ArenaAllocatable<'tcx, ()> for T where
    T: Copy

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

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

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

impl<T> From<T> for T[src]

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

impl<T> MaybeResult<T> for T[src]

type Error = !

impl<'tcx, T> Subst<'tcx> for T where
    T: TypeFoldable<'tcx>, 

impl<T> ToOwned for T where
    T: Clone

type Owned = T

The resulting type after obtaining ownership.

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.

impl<T> WithConstness for T[src]