Skip to content

Commit e5e0387

Browse files
Rename Scope.id to Scope.local_id, remove trivial accessor
1 parent 1f352ac commit e5e0387

File tree

8 files changed

+45
-49
lines changed

8 files changed

+45
-49
lines changed

compiler/rustc_hir_analysis/src/check/region.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ fn resolve_block<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, blk: &'tcx h
129129
let mut prev_cx = visitor.cx;
130130

131131
visitor.enter_scope(Scope {
132-
id: blk.hir_id.local_id,
132+
local_id: blk.hir_id.local_id,
133133
data: ScopeData::Remainder(FirstStatementIndex::new(i)),
134134
});
135135
visitor.cx.var_parent = visitor.cx.parent;
@@ -154,7 +154,7 @@ fn resolve_block<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, blk: &'tcx h
154154
// the first such subscope, which has the block itself as a
155155
// parent.
156156
visitor.enter_scope(Scope {
157-
id: blk.hir_id.local_id,
157+
local_id: blk.hir_id.local_id,
158158
data: ScopeData::Remainder(FirstStatementIndex::new(i)),
159159
});
160160
visitor.cx.var_parent = visitor.cx.parent;
@@ -184,7 +184,7 @@ fn resolve_block<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, blk: &'tcx h
184184
visitor
185185
.scope_tree
186186
.backwards_incompatible_scope
187-
.insert(local_id, Scope { id: local_id, data: ScopeData::Node });
187+
.insert(local_id, Scope { local_id, data: ScopeData::Node });
188188
}
189189
visitor.visit_expr(tail_expr);
190190
}
@@ -221,7 +221,7 @@ fn resolve_arm<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, arm: &'tcx hir
221221
}
222222

223223
fn resolve_pat<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, pat: &'tcx hir::Pat<'tcx>) {
224-
visitor.record_child_scope(Scope { id: pat.hir_id.local_id, data: ScopeData::Node });
224+
visitor.record_child_scope(Scope { local_id: pat.hir_id.local_id, data: ScopeData::Node });
225225

226226
// If this is a binding then record the lifetime of that binding.
227227
if let PatKind::Binding(..) = pat.kind {
@@ -485,7 +485,7 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
485485
} else {
486486
ScopeData::IfThen
487487
};
488-
visitor.enter_scope(Scope { id: then.hir_id.local_id, data });
488+
visitor.enter_scope(Scope { local_id: then.hir_id.local_id, data });
489489
visitor.cx.var_parent = visitor.cx.parent;
490490
visitor.visit_expr(cond);
491491
visitor.visit_expr(then);
@@ -500,7 +500,7 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
500500
} else {
501501
ScopeData::IfThen
502502
};
503-
visitor.enter_scope(Scope { id: then.hir_id.local_id, data });
503+
visitor.enter_scope(Scope { local_id: then.hir_id.local_id, data });
504504
visitor.cx.var_parent = visitor.cx.parent;
505505
visitor.visit_expr(cond);
506506
visitor.visit_expr(then);
@@ -516,7 +516,7 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
516516

517517
if let hir::ExprKind::Yield(_, source) = &expr.kind {
518518
// Mark this expr's scope and all parent scopes as containing `yield`.
519-
let mut scope = Scope { id: expr.hir_id.local_id, data: ScopeData::Node };
519+
let mut scope = Scope { local_id: expr.hir_id.local_id, data: ScopeData::Node };
520520
loop {
521521
let span = match expr.kind {
522522
hir::ExprKind::Yield(expr, hir::YieldSource::Await { .. }) => {
@@ -803,9 +803,9 @@ impl<'tcx> RegionResolutionVisitor<'tcx> {
803803
// account for the destruction scope representing the scope of
804804
// the destructors that run immediately after it completes.
805805
if self.terminating_scopes.contains(&id) {
806-
self.enter_scope(Scope { id, data: ScopeData::Destruction });
806+
self.enter_scope(Scope { local_id: id, data: ScopeData::Destruction });
807807
}
808-
self.enter_scope(Scope { id, data: ScopeData::Node });
808+
self.enter_scope(Scope { local_id: id, data: ScopeData::Node });
809809
}
810810

811811
fn enter_body(&mut self, hir_id: hir::HirId, f: impl FnOnce(&mut Self)) {
@@ -822,8 +822,8 @@ impl<'tcx> RegionResolutionVisitor<'tcx> {
822822
let outer_pessimistic_yield = mem::replace(&mut self.pessimistic_yield, false);
823823
self.terminating_scopes.insert(hir_id.local_id);
824824

825-
self.enter_scope(Scope { id: hir_id.local_id, data: ScopeData::CallSite });
826-
self.enter_scope(Scope { id: hir_id.local_id, data: ScopeData::Arguments });
825+
self.enter_scope(Scope { local_id: hir_id.local_id, data: ScopeData::CallSite });
826+
self.enter_scope(Scope { local_id: hir_id.local_id, data: ScopeData::Arguments });
827827

828828
f(self);
829829

compiler/rustc_middle/src/middle/region.rs

+11-21
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,23 @@ use crate::ty::TyCtxt;
8484
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Copy, TyEncodable, TyDecodable)]
8585
#[derive(HashStable)]
8686
pub struct Scope {
87-
pub id: hir::ItemLocalId,
87+
pub local_id: hir::ItemLocalId,
8888
pub data: ScopeData,
8989
}
9090

9191
impl fmt::Debug for Scope {
9292
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
9393
match self.data {
94-
ScopeData::Node => write!(fmt, "Node({:?})", self.id),
95-
ScopeData::CallSite => write!(fmt, "CallSite({:?})", self.id),
96-
ScopeData::Arguments => write!(fmt, "Arguments({:?})", self.id),
97-
ScopeData::Destruction => write!(fmt, "Destruction({:?})", self.id),
98-
ScopeData::IfThen => write!(fmt, "IfThen({:?})", self.id),
99-
ScopeData::IfThenRescope => write!(fmt, "IfThen[edition2024]({:?})", self.id),
94+
ScopeData::Node => write!(fmt, "Node({:?})", self.local_id),
95+
ScopeData::CallSite => write!(fmt, "CallSite({:?})", self.local_id),
96+
ScopeData::Arguments => write!(fmt, "Arguments({:?})", self.local_id),
97+
ScopeData::Destruction => write!(fmt, "Destruction({:?})", self.local_id),
98+
ScopeData::IfThen => write!(fmt, "IfThen({:?})", self.local_id),
99+
ScopeData::IfThenRescope => write!(fmt, "IfThen[edition2024]({:?})", self.local_id),
100100
ScopeData::Remainder(fsi) => write!(
101101
fmt,
102102
"Remainder {{ block: {:?}, first_statement_index: {}}}",
103-
self.id,
103+
self.local_id,
104104
fsi.as_u32(),
105105
),
106106
}
@@ -164,18 +164,8 @@ rustc_index::newtype_index! {
164164
rustc_data_structures::static_assert_size!(ScopeData, 4);
165165

166166
impl Scope {
167-
/// Returns an item-local ID associated with this scope.
168-
///
169-
/// N.B., likely to be replaced as API is refined; e.g., pnkfelix
170-
/// anticipates `fn entry_node_id` and `fn each_exit_node_id`.
171-
pub fn item_local_id(&self) -> hir::ItemLocalId {
172-
self.id
173-
}
174-
175167
pub fn hir_id(&self, scope_tree: &ScopeTree) -> Option<HirId> {
176-
scope_tree
177-
.root_body
178-
.map(|hir_id| HirId { owner: hir_id.owner, local_id: self.item_local_id() })
168+
scope_tree.root_body.map(|hir_id| HirId { owner: hir_id.owner, local_id: self.local_id })
179169
}
180170

181171
/// Returns the span of this `Scope`. Note that in general the
@@ -350,7 +340,7 @@ impl ScopeTree {
350340

351341
pub fn record_var_scope(&mut self, var: hir::ItemLocalId, lifetime: Scope) {
352342
debug!("record_var_scope(sub={:?}, sup={:?})", var, lifetime);
353-
assert!(var != lifetime.item_local_id());
343+
assert!(var != lifetime.local_id);
354344
self.var_map.insert(var, lifetime);
355345
}
356346

@@ -359,7 +349,7 @@ impl ScopeTree {
359349
match &candidate_type {
360350
RvalueCandidateType::Borrow { lifetime: Some(lifetime), .. }
361351
| RvalueCandidateType::Pattern { lifetime: Some(lifetime), .. } => {
362-
assert!(var.local_id != lifetime.item_local_id())
352+
assert!(var.local_id != lifetime.local_id)
363353
}
364354
_ => {}
365355
}

compiler/rustc_middle/src/ty/rvalue_scopes.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl RvalueScopes {
3535
// if there's one. Static items, for instance, won't
3636
// have an enclosing scope, hence no scope will be
3737
// returned.
38-
let mut id = Scope { id: expr_id, data: ScopeData::Node };
38+
let mut id = Scope { local_id: expr_id, data: ScopeData::Node };
3939
let mut backwards_incompatible = None;
4040

4141
while let Some(&(p, _)) = region_scope_tree.parent_map.get(&id) {
@@ -60,7 +60,7 @@ impl RvalueScopes {
6060
if backwards_incompatible.is_none() {
6161
backwards_incompatible = region_scope_tree
6262
.backwards_incompatible_scope
63-
.get(&p.item_local_id())
63+
.get(&p.local_id)
6464
.copied();
6565
}
6666
id = p
@@ -76,7 +76,7 @@ impl RvalueScopes {
7676
pub fn record_rvalue_scope(&mut self, var: hir::ItemLocalId, lifetime: Option<Scope>) {
7777
debug!("record_rvalue_scope(var={var:?}, lifetime={lifetime:?})");
7878
if let Some(lifetime) = lifetime {
79-
assert!(var != lifetime.item_local_id());
79+
assert!(var != lifetime.local_id);
8080
}
8181
self.map.insert(var, lifetime);
8282
}

compiler/rustc_mir_build/src/builder/expr/as_temp.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
7575
LocalInfo::BlockTailTemp(tail_info)
7676
}
7777

78-
_ if let Some(Scope { data: ScopeData::IfThenRescope, id }) =
78+
_ if let Some(Scope { data: ScopeData::IfThenRescope, local_id }) =
7979
temp_lifetime.temp_lifetime =>
8080
{
8181
LocalInfo::IfThenRescopeTemp {
82-
if_then: HirId { owner: this.hir_id.owner, local_id: id },
82+
if_then: HirId { owner: this.hir_id.owner, local_id },
8383
}
8484
}
8585

compiler/rustc_mir_build/src/builder/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,9 @@ fn construct_fn<'tcx>(
531531
);
532532

533533
let call_site_scope =
534-
region::Scope { id: body.id().hir_id.local_id, data: region::ScopeData::CallSite };
534+
region::Scope { local_id: body.id().hir_id.local_id, data: region::ScopeData::CallSite };
535535
let arg_scope =
536-
region::Scope { id: body.id().hir_id.local_id, data: region::ScopeData::Arguments };
536+
region::Scope { local_id: body.id().hir_id.local_id, data: region::ScopeData::Arguments };
537537
let source_info = builder.source_info(span);
538538
let call_site_s = (call_site_scope, source_info);
539539
let _: BlockAnd<()> = builder.in_scope(call_site_s, LintLevel::Inherited, |builder| {

compiler/rustc_mir_build/src/builder/scope.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ use rustc_index::{IndexSlice, IndexVec};
8989
use rustc_middle::middle::region;
9090
use rustc_middle::mir::*;
9191
use rustc_middle::thir::{ExprId, LintLevel};
92-
use rustc_middle::{bug, span_bug, ty};
92+
use rustc_middle::{bug, span_bug};
9393
use rustc_session::lint::Level;
9494
use rustc_span::source_map::Spanned;
9595
use rustc_span::{DUMMY_SP, Span};

compiler/rustc_mir_build/src/thir/cx/block.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl<'tcx> Cx<'tcx> {
1616
let block = Block {
1717
targeted_by_break: block.targeted_by_break,
1818
region_scope: region::Scope {
19-
id: block.hir_id.local_id,
19+
local_id: block.hir_id.local_id,
2020
data: region::ScopeData::Node,
2121
},
2222
span: block.span,
@@ -51,7 +51,7 @@ impl<'tcx> Cx<'tcx> {
5151
let stmt = Stmt {
5252
kind: StmtKind::Expr {
5353
scope: region::Scope {
54-
id: hir_id.local_id,
54+
local_id: hir_id.local_id,
5555
data: region::ScopeData::Node,
5656
},
5757
expr: self.mirror_expr(expr),
@@ -65,7 +65,7 @@ impl<'tcx> Cx<'tcx> {
6565
}
6666
hir::StmtKind::Let(local) => {
6767
let remainder_scope = region::Scope {
68-
id: block_id,
68+
local_id: block_id,
6969
data: region::ScopeData::Remainder(region::FirstStatementIndex::new(
7070
index,
7171
)),
@@ -108,7 +108,7 @@ impl<'tcx> Cx<'tcx> {
108108
kind: StmtKind::Let {
109109
remainder_scope,
110110
init_scope: region::Scope {
111-
id: hir_id.local_id,
111+
local_id: hir_id.local_id,
112112
data: region::ScopeData::Node,
113113
},
114114
pattern,

compiler/rustc_mir_build/src/thir/cx/expr.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<'tcx> Cx<'tcx> {
4545
#[instrument(level = "trace", skip(self, hir_expr))]
4646
pub(super) fn mirror_expr_inner(&mut self, hir_expr: &'tcx hir::Expr<'tcx>) -> ExprId {
4747
let expr_scope =
48-
region::Scope { id: hir_expr.hir_id.local_id, data: region::ScopeData::Node };
48+
region::Scope { local_id: hir_expr.hir_id.local_id, data: region::ScopeData::Node };
4949

5050
trace!(?hir_expr.hir_id, ?hir_expr.span);
5151

@@ -814,14 +814,20 @@ impl<'tcx> Cx<'tcx> {
814814
hir::ExprKind::Become(call) => ExprKind::Become { value: self.mirror_expr(call) },
815815
hir::ExprKind::Break(dest, ref value) => match dest.target_id {
816816
Ok(target_id) => ExprKind::Break {
817-
label: region::Scope { id: target_id.local_id, data: region::ScopeData::Node },
817+
label: region::Scope {
818+
local_id: target_id.local_id,
819+
data: region::ScopeData::Node,
820+
},
818821
value: value.map(|value| self.mirror_expr(value)),
819822
},
820823
Err(err) => bug!("invalid loop id for break: {}", err),
821824
},
822825
hir::ExprKind::Continue(dest) => match dest.target_id {
823826
Ok(loop_id) => ExprKind::Continue {
824-
label: region::Scope { id: loop_id.local_id, data: region::ScopeData::Node },
827+
label: region::Scope {
828+
local_id: loop_id.local_id,
829+
data: region::ScopeData::Node,
830+
},
825831
},
826832
Err(err) => bug!("invalid loop id for continue: {}", err),
827833
},
@@ -831,7 +837,7 @@ impl<'tcx> Cx<'tcx> {
831837
},
832838
hir::ExprKind::If(cond, then, else_opt) => ExprKind::If {
833839
if_then_scope: region::Scope {
834-
id: then.hir_id.local_id,
840+
local_id: then.hir_id.local_id,
835841
data: {
836842
if expr.span.at_least_rust_2024() {
837843
region::ScopeData::IfThenRescope
@@ -1021,7 +1027,7 @@ impl<'tcx> Cx<'tcx> {
10211027
guard: arm.guard.as_ref().map(|g| self.mirror_expr(g)),
10221028
body: self.mirror_expr(arm.body),
10231029
lint_level: LintLevel::Explicit(arm.hir_id),
1024-
scope: region::Scope { id: arm.hir_id.local_id, data: region::ScopeData::Node },
1030+
scope: region::Scope { local_id: arm.hir_id.local_id, data: region::ScopeData::Node },
10251031
span: arm.span,
10261032
};
10271033
self.thir.arms.push(arm)

0 commit comments

Comments
 (0)