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]
pub fn data(self) -> ScopeData[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?
pub fn Node(id: ItemLocalId) -> Self[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?
pub fn CallSite(id: ItemLocalId) -> Self[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?
pub fn Arguments(id: ItemLocalId) -> Self[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?
pub fn Destruction(id: ItemLocalId) -> Self[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?
pub fn Remainder(r: BlockRemainder) -> Self[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]
pub fn item_local_id(&self) -> ItemLocalId[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.
pub fn node_id(&self, tcx: TyCtxt, scope_tree: &ScopeTree) -> NodeId[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?
pub fn span(&self, tcx: TyCtxt, scope_tree: &ScopeTree) -> Span[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]
fn hash_stable<W: StableHasherResult>(
&self,
__ctx: &mut StableHashingContext<'tcx>,
__hasher: &mut StableHasher<W>
)[src]
&self,
__ctx: &mut StableHashingContext<'tcx>,
__hasher: &mut StableHasher<W>
)
🔬 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]
type KeyType = Scope
🔬 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?
fn to_stable_hash_key(&self, _: &StableHashingContext<'gcx>) -> 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?
impl Clone for Scope[src]
fn clone(&self) -> Scope[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
Performs copy-assignment from source. Read more
impl PartialEq for Scope[src]
fn eq(&self, __arg_0: &Scope) -> bool[src]
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, __arg_0: &Scope) -> bool[src]
This method tests for !=.
impl PartialOrd for Scope[src]
fn partial_cmp(&self, __arg_0: &Scope) -> Option<Ordering>[src]
This method returns an ordering between self and other values if one exists. Read more
fn lt(&self, __arg_0: &Scope) -> bool[src]
This method tests less than (for self and other) and is used by the < operator. Read more
fn le(&self, __arg_0: &Scope) -> bool[src]
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
fn gt(&self, __arg_0: &Scope) -> bool[src]
This method tests greater than (for self and other) and is used by the > operator. Read more
fn ge(&self, __arg_0: &Scope) -> bool[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]
fn cmp(&self, __arg_0: &Scope) -> Ordering[src]
This method returns an Ordering between self and other. Read more
fn max(self, other: Self) -> Self1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self1.21.0[src]
Compares and returns the minimum of two values. Read more
impl Hash for Scope[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)[src]
Feeds this value into the given [Hasher]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, 1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher]. Read more
impl Copy for Scope[src]
impl Encodable for Scope[src]
fn encode<__S: Encoder>(&self, __arg_0: &mut __S) -> Result<(), __S::Error>[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]
fn decode<__D: Decoder>(__arg_0: &mut __D) -> Result<Scope, __D::Error>[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?