Skip to content

Commit 87c7663

Browse files
committed
Track label_res_map per-owner
1 parent 74ad9d3 commit 87c7663

5 files changed

Lines changed: 10 additions & 12 deletions

File tree

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
15491549
fn lower_loop_destination(&mut self, destination: Option<(NodeId, Label)>) -> hir::Destination {
15501550
let target_id = match destination {
15511551
Some((id, _)) => {
1552-
if let Some(loop_id) = self.resolver.get_label_res(id) {
1552+
if let Some(loop_id) = self.owner.get_label_res(id) {
15531553
let local_id = self.ident_and_label_to_local_id[&loop_id];
15541554
let loop_hir_id = HirId { owner: self.current_hir_id_owner, local_id };
15551555
Ok(loop_hir_id)

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,6 @@ impl<'tcx> ResolverAstLowering<'tcx> {
293293
self.import_res_map.get(&id).copied().unwrap_or_default()
294294
}
295295

296-
/// Obtains resolution for a label with the given `NodeId`.
297-
fn get_label_res(&self, id: NodeId) -> Option<NodeId> {
298-
self.label_res_map.get(&id).copied()
299-
}
300-
301296
/// Obtains resolution for a lifetime with the given `NodeId`.
302297
fn get_lifetime_res(&self, id: NodeId) -> Option<LifetimeRes> {
303298
self.lifetimes_res_map.get(&id).copied()

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ pub struct PerOwnerResolverData {
209209
pub node_id_to_def_id: NodeMap<LocalDefId> = Default::default(),
210210
/// Whether lifetime elision was successful.
211211
pub lifetime_elision_allowed: bool = false,
212+
/// Resolutions for labels.
213+
/// Maps from NodeId of the break/continue expression to the NodeId of their corresponding blocks or loops.
214+
pub label_res_map: NodeMap<ast::NodeId> = Default::default(),
212215

213216
/// The id of the owner
214217
pub id: ast::NodeId,
@@ -220,6 +223,11 @@ impl PerOwnerResolverData {
220223
pub fn new(id: ast::NodeId, def_id: LocalDefId) -> PerOwnerResolverData {
221224
PerOwnerResolverData { id, def_id, .. }
222225
}
226+
227+
/// Obtains resolution for a label with the given `NodeId`.
228+
pub fn get_label_res(&self, id: ast::NodeId) -> Option<ast::NodeId> {
229+
self.label_res_map.get(&id).copied()
230+
}
223231
}
224232

225233
/// Resolutions that should only be used for lowering.
@@ -230,8 +238,6 @@ pub struct ResolverAstLowering<'tcx> {
230238
pub partial_res_map: NodeMap<hir::def::PartialRes>,
231239
/// Resolutions for import nodes, which have multiple resolutions in different namespaces.
232240
pub import_res_map: NodeMap<hir::def::PerNS<Option<Res<ast::NodeId>>>>,
233-
/// Resolutions for labels (node IDs of their corresponding blocks or loops).
234-
pub label_res_map: NodeMap<ast::NodeId>,
235241
/// Resolutions for lifetimes.
236242
pub lifetimes_res_map: NodeMap<LifetimeRes>,
237243
/// Lifetime parameters that lowering will have to introduce.

compiler/rustc_resolve/src/late.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5214,7 +5214,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
52145214
match self.resolve_label(label.ident) {
52155215
Ok((node_id, _)) => {
52165216
// Since this res is a label, it is never read.
5217-
self.r.label_res_map.insert(expr.id, node_id);
5217+
self.r.current_owner.label_res_map.insert(expr.id, node_id);
52185218
self.diag_metadata.unused_labels.swap_remove(&node_id);
52195219
}
52205220
Err(error) => {

compiler/rustc_resolve/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,8 +1380,6 @@ pub struct Resolver<'ra, 'tcx> {
13801380
import_res_map: NodeMap<PerNS<Option<Res>>> = Default::default(),
13811381
/// An import will be inserted into this map if it has been used.
13821382
import_use_map: FxHashMap<Import<'ra>, Used> = default::fx_hash_map(),
1383-
/// Resolutions for labels (node IDs of their corresponding blocks or loops).
1384-
label_res_map: NodeMap<NodeId> = Default::default(),
13851383
/// Resolutions for lifetimes.
13861384
lifetimes_res_map: NodeMap<LifetimeRes> = Default::default(),
13871385
/// Lifetime parameters that lowering will have to introduce.
@@ -2015,7 +2013,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
20152013
let ast_lowering = ty::ResolverAstLowering {
20162014
partial_res_map: self.partial_res_map,
20172015
import_res_map: self.import_res_map,
2018-
label_res_map: self.label_res_map,
20192016
lifetimes_res_map: self.lifetimes_res_map,
20202017
extra_lifetime_params_map: self.extra_lifetime_params_map,
20212018
next_node_id: self.next_node_id,

0 commit comments

Comments
 (0)