1use std::fmt;
10
11use rustc_data_structures::fx::FxIndexMap;
12use rustc_data_structures::unord::UnordMap;
13use rustc_hir as hir;
14use rustc_hir::{HirId, ItemLocalMap, Node};
15use rustc_macros::{StableHash, TyDecodable, TyEncodable};
16use rustc_span::{DUMMY_SP, Span};
17use tracing::debug;
18
19use crate::ty::{self, TyCtxt};
20
21#[derive(#[automatically_derived]
impl ::core::clone::Clone for Scope {
#[inline]
fn clone(&self) -> Scope {
let _: ::core::clone::AssertParamIsClone<hir::ItemLocalId>;
let _: ::core::clone::AssertParamIsClone<ScopeData>;
*self
}
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for Scope {
#[inline]
fn eq(&self, other: &Scope) -> bool {
self.local_id == other.local_id && self.data == other.data
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::PartialOrd for Scope {
#[inline]
fn partial_cmp(&self, other: &Scope)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Eq for Scope {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<hir::ItemLocalId>;
let _: ::core::cmp::AssertParamIsEq<ScopeData>;
}
}Eq, #[automatically_derived]
impl ::core::cmp::Ord for Scope {
#[inline]
fn cmp(&self, other: &Scope) -> ::core::cmp::Ordering {
match ::core::cmp::Ord::cmp(&self.local_id, &other.local_id) {
::core::cmp::Ordering::Equal =>
::core::cmp::Ord::cmp(&self.data, &other.data),
cmp => cmp,
}
}
}Ord, #[automatically_derived]
impl ::core::hash::Hash for Scope {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.local_id, state);
::core::hash::Hash::hash(&self.data, state)
}
}Hash, #[automatically_derived]
impl ::core::marker::Copy for Scope { }Copy, const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for Scope {
fn encode(&self, __encoder: &mut __E) {
match *self {
Scope { local_id: ref __binding_0, data: ref __binding_1 }
=> {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
}
}
}
};TyEncodable, const _: () =
{
impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
::rustc_serialize::Decodable<__D> for Scope {
fn decode(__decoder: &mut __D) -> Self {
Scope {
local_id: ::rustc_serialize::Decodable::decode(__decoder),
data: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};TyDecodable)]
84#[derive(const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for Scope {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
Scope { local_id: ref __binding_0, data: ref __binding_1 }
=> {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash)]
85pub struct Scope {
86 pub local_id: hir::ItemLocalId,
87 pub data: ScopeData,
88}
89
90impl fmt::Debug for Scope {
91 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
92 match self.data {
93 ScopeData::Node => fmt.write_fmt(format_args!("Node({0:?})", self.local_id))write!(fmt, "Node({:?})", self.local_id),
94 ScopeData::CallSite => fmt.write_fmt(format_args!("CallSite({0:?})", self.local_id))write!(fmt, "CallSite({:?})", self.local_id),
95 ScopeData::Arguments => fmt.write_fmt(format_args!("Arguments({0:?})", self.local_id))write!(fmt, "Arguments({:?})", self.local_id),
96 ScopeData::Destruction => fmt.write_fmt(format_args!("Destruction({0:?})", self.local_id))write!(fmt, "Destruction({:?})", self.local_id),
97 ScopeData::IfThen => fmt.write_fmt(format_args!("IfThen({0:?})", self.local_id))write!(fmt, "IfThen({:?})", self.local_id),
98 ScopeData::IfThenRescope => fmt.write_fmt(format_args!("IfThen[edition2024]({0:?})", self.local_id))write!(fmt, "IfThen[edition2024]({:?})", self.local_id),
99 ScopeData::MatchGuard => fmt.write_fmt(format_args!("MatchGuard({0:?})", self.local_id))write!(fmt, "MatchGuard({:?})", self.local_id),
100 ScopeData::Remainder(fsi) => fmt.write_fmt(format_args!("Remainder {{ block: {0:?}, first_statement_index: {1}}}",
self.local_id, fsi.as_u32()))write!(
101 fmt,
102 "Remainder {{ block: {:?}, first_statement_index: {}}}",
103 self.local_id,
104 fsi.as_u32(),
105 ),
106 }
107 }
108}
109
110#[derive(#[automatically_derived]
impl ::core::clone::Clone for ScopeData {
#[inline]
fn clone(&self) -> ScopeData {
let _: ::core::clone::AssertParamIsClone<FirstStatementIndex>;
*self
}
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for ScopeData {
#[inline]
fn eq(&self, other: &ScopeData) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(ScopeData::Remainder(__self_0),
ScopeData::Remainder(__arg1_0)) => __self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::PartialOrd for ScopeData {
#[inline]
fn partial_cmp(&self, other: &ScopeData)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Eq for ScopeData {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<FirstStatementIndex>;
}
}Eq, #[automatically_derived]
impl ::core::cmp::Ord for ScopeData {
#[inline]
fn cmp(&self, other: &ScopeData) -> ::core::cmp::Ordering {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
match ::core::cmp::Ord::cmp(&__self_discr, &__arg1_discr) {
::core::cmp::Ordering::Equal =>
match (self, other) {
(ScopeData::Remainder(__self_0),
ScopeData::Remainder(__arg1_0)) =>
::core::cmp::Ord::cmp(__self_0, __arg1_0),
_ => ::core::cmp::Ordering::Equal,
},
cmp => cmp,
}
}
}Ord, #[automatically_derived]
impl ::core::hash::Hash for ScopeData {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
let __self_discr = ::core::intrinsics::discriminant_value(self);
::core::hash::Hash::hash(&__self_discr, state);
match self {
ScopeData::Remainder(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
_ => {}
}
}
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for ScopeData {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
ScopeData::Node => ::core::fmt::Formatter::write_str(f, "Node"),
ScopeData::CallSite =>
::core::fmt::Formatter::write_str(f, "CallSite"),
ScopeData::Arguments =>
::core::fmt::Formatter::write_str(f, "Arguments"),
ScopeData::Destruction =>
::core::fmt::Formatter::write_str(f, "Destruction"),
ScopeData::IfThen =>
::core::fmt::Formatter::write_str(f, "IfThen"),
ScopeData::IfThenRescope =>
::core::fmt::Formatter::write_str(f, "IfThenRescope"),
ScopeData::MatchGuard =>
::core::fmt::Formatter::write_str(f, "MatchGuard"),
ScopeData::Remainder(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Remainder", &__self_0),
}
}
}Debug, #[automatically_derived]
impl ::core::marker::Copy for ScopeData { }Copy, const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for ScopeData {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
ScopeData::Node => { 0usize }
ScopeData::CallSite => { 1usize }
ScopeData::Arguments => { 2usize }
ScopeData::Destruction => { 3usize }
ScopeData::IfThen => { 4usize }
ScopeData::IfThenRescope => { 5usize }
ScopeData::MatchGuard => { 6usize }
ScopeData::Remainder(ref __binding_0) => { 7usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
ScopeData::Node => {}
ScopeData::CallSite => {}
ScopeData::Arguments => {}
ScopeData::Destruction => {}
ScopeData::IfThen => {}
ScopeData::IfThenRescope => {}
ScopeData::MatchGuard => {}
ScopeData::Remainder(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
}
}
};TyEncodable, const _: () =
{
impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
::rustc_serialize::Decodable<__D> for ScopeData {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => { ScopeData::Node }
1usize => { ScopeData::CallSite }
2usize => { ScopeData::Arguments }
3usize => { ScopeData::Destruction }
4usize => { ScopeData::IfThen }
5usize => { ScopeData::IfThenRescope }
6usize => { ScopeData::MatchGuard }
7usize => {
ScopeData::Remainder(::rustc_serialize::Decodable::decode(__decoder))
}
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `ScopeData`, expected 0..8, actual {0}",
n));
}
}
}
}
};TyDecodable)]
111#[derive(const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for ScopeData {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
match *self {
ScopeData::Node => {}
ScopeData::CallSite => {}
ScopeData::Arguments => {}
ScopeData::Destruction => {}
ScopeData::IfThen => {}
ScopeData::IfThenRescope => {}
ScopeData::MatchGuard => {}
ScopeData::Remainder(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash)]
112pub enum ScopeData {
113 Node,
114
115 CallSite,
118
119 Arguments,
122
123 Destruction,
125
126 IfThen,
129
130 IfThenRescope,
134
135 MatchGuard,
139
140 Remainder(FirstStatementIndex),
142}
143
144impl ::std::fmt::Debug for FirstStatementIndex {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
fmt.write_fmt(format_args!("{0}", self.as_u32()))
}
}rustc_index::newtype_index! {
145 #[stable_hash]
163 #[encodable]
164 #[orderable]
165 pub struct FirstStatementIndex {}
166}
167
168const _: [(); 4] = [(); ::std::mem::size_of::<ScopeData>()];rustc_data_structures::static_assert_size!(ScopeData, 4);
170
171impl Scope {
172 pub fn hir_id(&self, scope_tree: &ScopeTree) -> Option<HirId> {
173 scope_tree.root_body.map(|hir_id| HirId { owner: hir_id.owner, local_id: self.local_id })
174 }
175
176 pub fn span(&self, tcx: TyCtxt<'_>, scope_tree: &ScopeTree) -> Span {
180 let Some(hir_id) = self.hir_id(scope_tree) else {
181 return DUMMY_SP;
182 };
183 let span = tcx.hir_span(hir_id);
184 if let ScopeData::Remainder(first_statement_index) = self.data
185 && let Node::Block(blk) = tcx.hir_node(hir_id)
193 {
194 let stmt_span = blk.stmts[first_statement_index.index()].span;
195
196 if span.lo() <= stmt_span.lo() && stmt_span.lo() <= span.hi() {
199 return span.with_lo(stmt_span.lo());
200 }
201 }
202 span
203 }
204}
205
206#[derive(#[automatically_derived]
impl ::core::default::Default for ScopeTree {
#[inline]
fn default() -> ScopeTree {
ScopeTree {
root_body: ::core::default::Default::default(),
parent_map: ::core::default::Default::default(),
var_map: ::core::default::Default::default(),
extended_temp_scopes: ::core::default::Default::default(),
backwards_incompatible_scope: ::core::default::Default::default(),
}
}
}Default, #[automatically_derived]
impl ::core::fmt::Debug for ScopeTree {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field5_finish(f, "ScopeTree",
"root_body", &self.root_body, "parent_map", &self.parent_map,
"var_map", &self.var_map, "extended_temp_scopes",
&self.extended_temp_scopes, "backwards_incompatible_scope",
&&self.backwards_incompatible_scope)
}
}Debug, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for ScopeTree {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
ScopeTree {
root_body: ref __binding_0,
parent_map: ref __binding_1,
var_map: ref __binding_2,
extended_temp_scopes: ref __binding_3,
backwards_incompatible_scope: ref __binding_4 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
{ __binding_2.stable_hash(__hcx, __hasher); }
{ __binding_3.stable_hash(__hcx, __hasher); }
{ __binding_4.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash)]
208pub struct ScopeTree {
209 pub root_body: Option<HirId>,
211
212 pub parent_map: FxIndexMap<Scope, Scope>,
219
220 var_map: FxIndexMap<hir::ItemLocalId, Scope>,
223
224 extended_temp_scopes: ItemLocalMap<Option<Scope>>,
230
231 pub backwards_incompatible_scope: UnordMap<hir::ItemLocalId, Scope>,
235}
236
237#[derive(#[automatically_derived]
impl ::core::clone::Clone for TempLifetime {
#[inline]
fn clone(&self) -> TempLifetime {
let _: ::core::clone::AssertParamIsClone<Option<Scope>>;
let _: ::core::clone::AssertParamIsClone<Option<Scope>>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for TempLifetime { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for TempLifetime {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "TempLifetime",
"temp_lifetime", &self.temp_lifetime, "backwards_incompatible",
&&self.backwards_incompatible)
}
}Debug, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for TempLifetime
{
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
TempLifetime {
temp_lifetime: ref __binding_0,
backwards_incompatible: ref __binding_1 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash)]
239pub struct TempLifetime {
240 pub temp_lifetime: Option<Scope>,
243 pub backwards_incompatible: Option<Scope>,
246}
247
248impl ScopeTree {
249 pub fn record_scope_parent(&mut self, child: Scope, parent: Option<Scope>) {
250 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/middle/region.rs:250",
"rustc_middle::middle::region", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/middle/region.rs"),
::tracing_core::__macro_support::Option::Some(250u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::middle::region"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("{0:?}.parent = {1:?}",
child, parent) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("{:?}.parent = {:?}", child, parent);
251
252 if let Some(p) = parent {
253 let prev = self.parent_map.insert(child, p);
254 if !prev.is_none() {
::core::panicking::panic("assertion failed: prev.is_none()")
};assert!(prev.is_none());
255 }
256 }
257
258 pub fn record_var_scope(&mut self, var: hir::ItemLocalId, lifetime: Scope) {
259 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/middle/region.rs:259",
"rustc_middle::middle::region", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/middle/region.rs"),
::tracing_core::__macro_support::Option::Some(259u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::middle::region"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("record_var_scope(sub={0:?}, sup={1:?})",
var, lifetime) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("record_var_scope(sub={:?}, sup={:?})", var, lifetime);
260 if !(var != lifetime.local_id) {
::core::panicking::panic("assertion failed: var != lifetime.local_id")
};assert!(var != lifetime.local_id);
261 self.var_map.insert(var, lifetime);
262 }
263
264 pub fn record_extended_temp_scope(&mut self, var: hir::ItemLocalId, lifetime: Option<Scope>) {
266 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/middle/region.rs:266",
"rustc_middle::middle::region", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/middle/region.rs"),
::tracing_core::__macro_support::Option::Some(266u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::middle::region"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("var")
}> =
::tracing::__macro_support::FieldName::new("var");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("lifetime")
}> =
::tracing::__macro_support::FieldName::new("lifetime");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&var)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&lifetime)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?var, ?lifetime);
267 if let Some(lifetime) = lifetime {
268 if !(var != lifetime.local_id) {
::core::panicking::panic("assertion failed: var != lifetime.local_id")
};assert!(var != lifetime.local_id);
269 }
270 self.extended_temp_scopes.insert(var, lifetime);
271 }
272
273 pub fn opt_encl_scope(&self, id: Scope) -> Option<Scope> {
275 self.parent_map.get(&id).cloned()
276 }
277
278 pub fn var_scope(&self, var_id: hir::ItemLocalId) -> Option<Scope> {
280 self.var_map.get(&var_id).cloned()
281 }
282
283 pub fn is_subscope_of(&self, subscope: Scope, superscope: Scope) -> bool {
288 let mut s = subscope;
289 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/middle/region.rs:289",
"rustc_middle::middle::region", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/middle/region.rs"),
::tracing_core::__macro_support::Option::Some(289u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::middle::region"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("is_subscope_of({0:?}, {1:?})",
subscope, superscope) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("is_subscope_of({:?}, {:?})", subscope, superscope);
290 while superscope != s {
291 match self.opt_encl_scope(s) {
292 None => {
293 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/middle/region.rs:293",
"rustc_middle::middle::region", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/middle/region.rs"),
::tracing_core::__macro_support::Option::Some(293u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::middle::region"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("is_subscope_of({0:?}, {1:?}, s={2:?})=false",
subscope, superscope, s) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("is_subscope_of({:?}, {:?}, s={:?})=false", subscope, superscope, s);
294 return false;
295 }
296 Some(scope) => s = scope,
297 }
298 }
299
300 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/middle/region.rs:300",
"rustc_middle::middle::region", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/middle/region.rs"),
::tracing_core::__macro_support::Option::Some(300u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::middle::region"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("is_subscope_of({0:?}, {1:?})=true",
subscope, superscope) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("is_subscope_of({:?}, {:?})=true", subscope, superscope);
301
302 true
303 }
304
305 pub fn default_temporary_scope(&self, inner: Scope) -> (Scope, Option<Scope>) {
309 let mut id = inner;
310 let mut backwards_incompatible = None;
311
312 while let Some(&p) = self.parent_map.get(&id) {
313 match p.data {
314 ScopeData::Destruction => {
315 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/middle/region.rs:315",
"rustc_middle::middle::region", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/middle/region.rs"),
::tracing_core::__macro_support::Option::Some(315u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::middle::region"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("temporary_scope({0:?}) = {1:?} [enclosing]",
inner, id) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("temporary_scope({inner:?}) = {id:?} [enclosing]");
316 return (id, backwards_incompatible);
317 }
318 ScopeData::IfThenRescope | ScopeData::MatchGuard => {
319 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/middle/region.rs:319",
"rustc_middle::middle::region", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/middle/region.rs"),
::tracing_core::__macro_support::Option::Some(319u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::middle::region"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("temporary_scope({0:?}) = {1:?} [enclosing]",
inner, p) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("temporary_scope({inner:?}) = {p:?} [enclosing]");
320 return (p, backwards_incompatible);
321 }
322 ScopeData::Node
323 | ScopeData::CallSite
324 | ScopeData::Arguments
325 | ScopeData::IfThen
326 | ScopeData::Remainder(_) => {
327 if backwards_incompatible.is_none() {
332 backwards_incompatible =
333 self.backwards_incompatible_scope.get(&p.local_id).copied();
334 }
335 id = p
336 }
337 }
338 }
339
340 crate::util::bug::span_bug_fmt(ty::tls::with(|tcx| inner.span(tcx, self)),
format_args!("no enclosing temporary scope"))span_bug!(ty::tls::with(|tcx| inner.span(tcx, self)), "no enclosing temporary scope")
341 }
342
343 pub fn temporary_scope(&self, expr_id: hir::ItemLocalId) -> TempLifetime {
347 if let Some(&s) = self.extended_temp_scopes.get(&expr_id) {
349 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/middle/region.rs:349",
"rustc_middle::middle::region", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/middle/region.rs"),
::tracing_core::__macro_support::Option::Some(349u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::middle::region"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("temporary_scope({0:?}) = {1:?} [custom]",
expr_id, s) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("temporary_scope({expr_id:?}) = {s:?} [custom]");
350 return TempLifetime { temp_lifetime: s, backwards_incompatible: None };
351 }
352
353 let (scope, backwards_incompatible) =
355 self.default_temporary_scope(Scope { local_id: expr_id, data: ScopeData::Node });
356 TempLifetime { temp_lifetime: Some(scope), backwards_incompatible }
357 }
358}