rustc_middle/ty/
rvalue_scopes.rs1use rustc_hir as hir;
2use rustc_hir::ItemLocalMap;
3use rustc_macros::{HashStable, TyDecodable, TyEncodable};
4use tracing::debug;
5
6use crate::middle::region::{Scope, ScopeData, ScopeTree};
7
8#[derive(TyEncodable, TyDecodable, Clone, Debug, Default, Eq, PartialEq, HashStable)]
11pub struct RvalueScopes {
12 map: ItemLocalMap<Option<Scope>>,
13}
14
15impl RvalueScopes {
16 pub fn new() -> Self {
17 Self { map: <_>::default() }
18 }
19
20 pub fn temporary_scope(
24 &self,
25 region_scope_tree: &ScopeTree,
26 expr_id: hir::ItemLocalId,
27 ) -> (Option<Scope>, Option<Scope>) {
28 if let Some(&s) = self.map.get(&expr_id) {
30 debug!("temporary_scope({expr_id:?}) = {s:?} [custom]");
31 return (s, None);
32 }
33
34 let (scope, backward_incompatible) = region_scope_tree
36 .default_temporary_scope(Scope { local_id: expr_id, data: ScopeData::Node });
37 (Some(scope), backward_incompatible)
38 }
39
40 pub fn record_rvalue_scope(&mut self, var: hir::ItemLocalId, lifetime: Option<Scope>) {
42 debug!("record_rvalue_scope(var={var:?}, lifetime={lifetime:?})");
43 if let Some(lifetime) = lifetime {
44 assert!(var != lifetime.local_id);
45 }
46 self.map.insert(var, lifetime);
47 }
48}