1
Fork 0

Rollup merge of #134491 - compiler-errors:dtor-tweaks, r=lqd

Some destructor/drop related tweaks

Two random tweaks I got from investigating some stuff around drops in edition 2024:
1. Use the `TypingEnv` of the mir builder, rather than making it over again.
2. Rename the `id` field from `Scope` to `local_id`, to reflect that it's a local id, and remove the `item_local_id()` accessor which just returned the id field.
This commit is contained in:
许杰友 Jieyou Xu (Joe) 2024-12-19 16:48:11 +08:00 committed by GitHub
commit e2bc71866e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 46 additions and 53 deletions

View file

@ -84,23 +84,23 @@ use crate::ty::TyCtxt;
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Copy, TyEncodable, TyDecodable)]
#[derive(HashStable)]
pub struct Scope {
pub id: hir::ItemLocalId,
pub local_id: hir::ItemLocalId,
pub data: ScopeData,
}
impl fmt::Debug for Scope {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.data {
ScopeData::Node => write!(fmt, "Node({:?})", self.id),
ScopeData::CallSite => write!(fmt, "CallSite({:?})", self.id),
ScopeData::Arguments => write!(fmt, "Arguments({:?})", self.id),
ScopeData::Destruction => write!(fmt, "Destruction({:?})", self.id),
ScopeData::IfThen => write!(fmt, "IfThen({:?})", self.id),
ScopeData::IfThenRescope => write!(fmt, "IfThen[edition2024]({:?})", self.id),
ScopeData::Node => write!(fmt, "Node({:?})", self.local_id),
ScopeData::CallSite => write!(fmt, "CallSite({:?})", self.local_id),
ScopeData::Arguments => write!(fmt, "Arguments({:?})", self.local_id),
ScopeData::Destruction => write!(fmt, "Destruction({:?})", self.local_id),
ScopeData::IfThen => write!(fmt, "IfThen({:?})", self.local_id),
ScopeData::IfThenRescope => write!(fmt, "IfThen[edition2024]({:?})", self.local_id),
ScopeData::Remainder(fsi) => write!(
fmt,
"Remainder {{ block: {:?}, first_statement_index: {}}}",
self.id,
self.local_id,
fsi.as_u32(),
),
}
@ -164,18 +164,8 @@ rustc_index::newtype_index! {
rustc_data_structures::static_assert_size!(ScopeData, 4);
impl Scope {
/// Returns an 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 item_local_id(&self) -> hir::ItemLocalId {
self.id
}
pub fn hir_id(&self, scope_tree: &ScopeTree) -> Option<HirId> {
scope_tree
.root_body
.map(|hir_id| HirId { owner: hir_id.owner, local_id: self.item_local_id() })
scope_tree.root_body.map(|hir_id| HirId { owner: hir_id.owner, local_id: self.local_id })
}
/// Returns the span of this `Scope`. Note that in general the
@ -350,7 +340,7 @@ impl ScopeTree {
pub fn record_var_scope(&mut self, var: hir::ItemLocalId, lifetime: Scope) {
debug!("record_var_scope(sub={:?}, sup={:?})", var, lifetime);
assert!(var != lifetime.item_local_id());
assert!(var != lifetime.local_id);
self.var_map.insert(var, lifetime);
}
@ -359,7 +349,7 @@ impl ScopeTree {
match &candidate_type {
RvalueCandidateType::Borrow { lifetime: Some(lifetime), .. }
| RvalueCandidateType::Pattern { lifetime: Some(lifetime), .. } => {
assert!(var.local_id != lifetime.item_local_id())
assert!(var.local_id != lifetime.local_id)
}
_ => {}
}

View file

@ -35,7 +35,7 @@ impl RvalueScopes {
// if there's one. Static items, for instance, won't
// have an enclosing scope, hence no scope will be
// returned.
let mut id = Scope { id: expr_id, data: ScopeData::Node };
let mut id = Scope { local_id: expr_id, data: ScopeData::Node };
let mut backwards_incompatible = None;
while let Some(&(p, _)) = region_scope_tree.parent_map.get(&id) {
@ -60,7 +60,7 @@ impl RvalueScopes {
if backwards_incompatible.is_none() {
backwards_incompatible = region_scope_tree
.backwards_incompatible_scope
.get(&p.item_local_id())
.get(&p.local_id)
.copied();
}
id = p
@ -76,7 +76,7 @@ impl RvalueScopes {
pub fn record_rvalue_scope(&mut self, var: hir::ItemLocalId, lifetime: Option<Scope>) {
debug!("record_rvalue_scope(var={var:?}, lifetime={lifetime:?})");
if let Some(lifetime) = lifetime {
assert!(var != lifetime.item_local_id());
assert!(var != lifetime.local_id);
}
self.map.insert(var, lifetime);
}