Skip to content

Commit 4919251

Browse files
committed
use HirId in middle::mem_categorization::cmt_, and consequences of that
For the HirIdification initiative rust-lang#50928.
1 parent f847d37 commit 4919251

File tree

8 files changed

+71
-66
lines changed

8 files changed

+71
-66
lines changed

src/librustc/middle/expr_use_visitor.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
319319
let fn_body_scope_r =
320320
self.tcx().mk_region(ty::ReScope(region::Scope::Node(body.value.hir_id.local_id)));
321321
let arg_cmt = Rc::new(self.mc.cat_rvalue(
322-
arg.id,
322+
arg.hir_id,
323323
arg.pat.span,
324324
fn_body_scope_r, // Args live only as long as the fn body.
325325
arg_ty));
@@ -860,7 +860,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
860860
// Each match binding is effectively an assignment to the
861861
// binding being produced.
862862
let def = Def::Local(canonical_id);
863-
if let Ok(ref binding_cmt) = mc.cat_def(pat.id, pat.span, pat_ty, def) {
863+
if let Ok(ref binding_cmt) = mc.cat_def(pat.hir_id, pat.span, pat_ty, def) {
864864
delegate.mutate(pat.id, pat.span, binding_cmt, MutateMode::Init);
865865
}
866866

@@ -923,7 +923,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
923923
closure_expr_id: closure_def_id.to_local(),
924924
};
925925
let upvar_capture = self.mc.tables.upvar_capture(upvar_id);
926-
let cmt_var = return_if_err!(self.cat_captured_var(closure_expr.id,
926+
let cmt_var = return_if_err!(self.cat_captured_var(closure_expr.hir_id,
927927
fn_decl_span,
928928
freevar));
929929
match upvar_capture {
@@ -948,15 +948,15 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
948948
}
949949

950950
fn cat_captured_var(&mut self,
951-
closure_id: ast::NodeId,
951+
closure_hir_id: hir::HirId,
952952
closure_span: Span,
953953
upvar: &hir::Freevar)
954954
-> mc::McResult<mc::cmt_<'tcx>> {
955955
// Create the cmt for the variable being borrowed, from the
956956
// caller's perspective
957957
let var_hir_id = self.tcx().hir.node_to_hir_id(upvar.var_id());
958958
let var_ty = self.mc.node_ty(var_hir_id)?;
959-
self.mc.cat_def(closure_id, closure_span, var_ty, upvar.def)
959+
self.mc.cat_def(closure_hir_id, closure_span, var_ty, upvar.def)
960960
}
961961
}
962962

src/librustc/middle/mem_categorization.rs

+43-44
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ pub enum Note {
193193
// a consistent fashion. For more details, see the method `cat_pattern`
194194
#[derive(Clone, Debug, PartialEq)]
195195
pub struct cmt_<'tcx> {
196-
pub id: ast::NodeId, // id of expr/pat producing this value
196+
pub hir_id: hir::HirId, // HIR id of expr/pat producing this value
197197
pub span: Span, // span of same expr/pat
198198
pub cat: Categorization<'tcx>, // categorization of expr
199199
pub mutbl: MutabilityCategory, // mutability of expr as place
@@ -275,18 +275,18 @@ impl<'tcx> cmt_<'tcx> {
275275
}
276276
}
277277

278-
pub trait ast_node {
279-
fn id(&self) -> ast::NodeId;
278+
pub trait HirNode {
279+
fn hir_id(&self) -> hir::HirId;
280280
fn span(&self) -> Span;
281281
}
282282

283-
impl ast_node for hir::Expr {
284-
fn id(&self) -> ast::NodeId { self.id }
283+
impl HirNode for hir::Expr {
284+
fn hir_id(&self) -> hir::HirId { self.hir_id }
285285
fn span(&self) -> Span { self.span }
286286
}
287287

288-
impl ast_node for hir::Pat {
289-
fn id(&self) -> ast::NodeId { self.id }
288+
impl HirNode for hir::Pat {
289+
fn hir_id(&self) -> hir::HirId { self.hir_id }
290290
fn span(&self) -> Span { self.span }
291291
}
292292

@@ -614,7 +614,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
614614
ty: target,
615615
mutbl: deref.mutbl,
616616
});
617-
self.cat_rvalue_node(expr.id, expr.span, ref_ty)
617+
self.cat_rvalue_node(expr.hir_id, expr.span, ref_ty)
618618
} else {
619619
previous()?
620620
});
@@ -629,7 +629,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
629629
adjustment::Adjust::Borrow(_) |
630630
adjustment::Adjust::Unsize => {
631631
// Result is an rvalue.
632-
Ok(self.cat_rvalue_node(expr.id, expr.span, target))
632+
Ok(self.cat_rvalue_node(expr.hir_id, expr.span, target))
633633
}
634634
}
635635
}
@@ -673,8 +673,8 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
673673
}
674674

675675
hir::ExprPath(ref qpath) => {
676-
let def = self.tables.qpath_def(qpath, expr.hir_id);
677-
self.cat_def(expr.id, expr.span, expr_ty, def)
676+
let def = self.tables.qpath_def(qpath, expr.hir_id);
677+
self.cat_def(expr.hir_id, expr.span, expr_ty, def)
678678
}
679679

680680
hir::ExprType(ref e, _) => {
@@ -692,35 +692,35 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
692692
hir::ExprLit(..) | hir::ExprBreak(..) |
693693
hir::ExprContinue(..) | hir::ExprStruct(..) | hir::ExprRepeat(..) |
694694
hir::ExprInlineAsm(..) | hir::ExprBox(..) => {
695-
Ok(self.cat_rvalue_node(expr.id(), expr.span(), expr_ty))
695+
Ok(self.cat_rvalue_node(expr.hir_id, expr.span, expr_ty))
696696
}
697697
}
698698
}
699699

700700
pub fn cat_def(&self,
701-
id: ast::NodeId,
701+
hir_id: hir::HirId,
702702
span: Span,
703703
expr_ty: Ty<'tcx>,
704704
def: Def)
705705
-> McResult<cmt_<'tcx>> {
706-
debug!("cat_def: id={} expr={:?} def={:?}",
707-
id, expr_ty, def);
706+
debug!("cat_def: id={:?} expr={:?} def={:?}",
707+
hir_id, expr_ty, def);
708708

709709
match def {
710710
Def::StructCtor(..) | Def::VariantCtor(..) | Def::Const(..) |
711711
Def::AssociatedConst(..) | Def::Fn(..) | Def::Method(..) => {
712-
Ok(self.cat_rvalue_node(id, span, expr_ty))
712+
Ok(self.cat_rvalue_node(hir_id, span, expr_ty))
713713
}
714714

715715
Def::Static(def_id, mutbl) => {
716716
// `#[thread_local]` statics may not outlive the current function.
717717
for attr in &self.tcx.get_attrs(def_id)[..] {
718718
if attr.check_name("thread_local") {
719-
return Ok(self.cat_rvalue_node(id, span, expr_ty));
719+
return Ok(self.cat_rvalue_node(hir_id, span, expr_ty));
720720
}
721721
}
722722
Ok(cmt_ {
723-
id:id,
723+
hir_id,
724724
span:span,
725725
cat:Categorization::StaticItem,
726726
mutbl: if mutbl { McDeclared } else { McImmutable},
@@ -730,12 +730,12 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
730730
}
731731

732732
Def::Upvar(var_id, _, fn_node_id) => {
733-
self.cat_upvar(id, span, var_id, fn_node_id)
733+
self.cat_upvar(hir_id, span, var_id, fn_node_id)
734734
}
735735

736736
Def::Local(vid) => {
737737
Ok(cmt_ {
738-
id,
738+
hir_id,
739739
span,
740740
cat: Categorization::Local(vid),
741741
mutbl: MutabilityCategory::from_local(self.tcx, self.tables, vid),
@@ -751,7 +751,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
751751
// Categorize an upvar, complete with invisible derefs of closure
752752
// environment and upvar reference as appropriate.
753753
fn cat_upvar(&self,
754-
id: ast::NodeId,
754+
hir_id: hir::HirId,
755755
span: Span,
756756
var_id: ast::NodeId,
757757
fn_node_id: ast::NodeId)
@@ -818,7 +818,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
818818
// from the environment (perhaps we should eventually desugar
819819
// this field further, but it will do for now).
820820
let cmt_result = cmt_ {
821-
id,
821+
hir_id,
822822
span,
823823
cat: Categorization::Upvar(Upvar {id: upvar_id, kind: kind}),
824824
mutbl: var_mutbl,
@@ -834,10 +834,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
834834
cmt_result
835835
}
836836
ty::ClosureKind::FnMut => {
837-
self.env_deref(id, span, upvar_id, var_mutbl, ty::MutBorrow, cmt_result)
837+
self.env_deref(hir_id, span, upvar_id, var_mutbl, ty::MutBorrow, cmt_result)
838838
}
839839
ty::ClosureKind::Fn => {
840-
self.env_deref(id, span, upvar_id, var_mutbl, ty::ImmBorrow, cmt_result)
840+
self.env_deref(hir_id, span, upvar_id, var_mutbl, ty::ImmBorrow, cmt_result)
841841
}
842842
};
843843

@@ -852,7 +852,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
852852
ty::UpvarCapture::ByRef(upvar_borrow) => {
853853
let ptr = BorrowedPtr(upvar_borrow.kind, upvar_borrow.region);
854854
cmt_ {
855-
id,
855+
hir_id,
856856
span,
857857
cat: Categorization::Deref(Rc::new(cmt_result), ptr),
858858
mutbl: MutabilityCategory::from_borrow_kind(upvar_borrow.kind),
@@ -868,7 +868,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
868868
}
869869

870870
fn env_deref(&self,
871-
id: ast::NodeId,
871+
hir_id: hir::HirId,
872872
span: Span,
873873
upvar_id: ty::UpvarId,
874874
upvar_mutbl: MutabilityCategory,
@@ -912,7 +912,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
912912
}
913913

914914
let ret = cmt_ {
915-
id,
915+
hir_id,
916916
span,
917917
cat: Categorization::Deref(Rc::new(cmt_result), env_ptr),
918918
mutbl: deref_mutbl,
@@ -936,17 +936,16 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
936936
}
937937

938938
pub fn cat_rvalue_node(&self,
939-
id: ast::NodeId,
939+
hir_id: hir::HirId,
940940
span: Span,
941941
expr_ty: Ty<'tcx>)
942942
-> cmt_<'tcx> {
943943
debug!(
944944
"cat_rvalue_node(id={:?}, span={:?}, expr_ty={:?})",
945-
id,
945+
hir_id,
946946
span,
947947
expr_ty,
948948
);
949-
let hir_id = self.tcx.hir.node_to_hir_id(id);
950949
let promotable = self.rvalue_promotable_map.as_ref().map(|m| m.contains(&hir_id.local_id))
951950
.unwrap_or(false);
952951

@@ -974,18 +973,18 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
974973
} else {
975974
self.temporary_scope(hir_id.local_id)
976975
};
977-
let ret = self.cat_rvalue(id, span, re, expr_ty);
976+
let ret = self.cat_rvalue(hir_id, span, re, expr_ty);
978977
debug!("cat_rvalue_node ret {:?}", ret);
979978
ret
980979
}
981980

982981
pub fn cat_rvalue(&self,
983-
cmt_id: ast::NodeId,
982+
cmt_hir_id: hir::HirId,
984983
span: Span,
985984
temp_scope: ty::Region<'tcx>,
986985
expr_ty: Ty<'tcx>) -> cmt_<'tcx> {
987986
let ret = cmt_ {
988-
id:cmt_id,
987+
hir_id: cmt_hir_id,
989988
span:span,
990989
cat:Categorization::Rvalue(temp_scope),
991990
mutbl:McDeclared,
@@ -996,15 +995,15 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
996995
ret
997996
}
998997

999-
pub fn cat_field<N:ast_node>(&self,
998+
pub fn cat_field<N: HirNode>(&self,
1000999
node: &N,
10011000
base_cmt: cmt<'tcx>,
10021001
f_index: usize,
10031002
f_ident: ast::Ident,
10041003
f_ty: Ty<'tcx>)
10051004
-> cmt_<'tcx> {
10061005
let ret = cmt_ {
1007-
id: node.id(),
1006+
hir_id: node.hir_id(),
10081007
span: node.span(),
10091008
mutbl: base_cmt.mutbl.inherit(),
10101009
cat: Categorization::Interior(base_cmt,
@@ -1046,13 +1045,13 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
10461045
mutbl,
10471046
});
10481047

1049-
let base_cmt = Rc::new(self.cat_rvalue_node(expr.id, expr.span, ref_ty));
1048+
let base_cmt = Rc::new(self.cat_rvalue_node(expr.hir_id, expr.span, ref_ty));
10501049
self.cat_deref(expr, base_cmt, note)
10511050
}
10521051

10531052
pub fn cat_deref(
10541053
&self,
1055-
node: &impl ast_node,
1054+
node: &impl HirNode,
10561055
base_cmt: cmt<'tcx>,
10571056
note: Note,
10581057
) -> McResult<cmt_<'tcx>> {
@@ -1078,7 +1077,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
10781077
ref ty => bug!("unexpected type in cat_deref: {:?}", ty)
10791078
};
10801079
let ret = cmt_ {
1081-
id: node.id(),
1080+
hir_id: node.hir_id(),
10821081
span: node.span(),
10831082
// For unique ptrs, we inherit mutability from the owning reference.
10841083
mutbl: MutabilityCategory::from_pointer_kind(base_cmt.mutbl, ptr),
@@ -1090,7 +1089,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
10901089
Ok(ret)
10911090
}
10921091

1093-
fn cat_index<N:ast_node>(&self,
1092+
fn cat_index<N: HirNode>(&self,
10941093
elt: &N,
10951094
base_cmt: cmt<'tcx>,
10961095
element_ty: Ty<'tcx>,
@@ -1110,7 +1109,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
11101109
//! presuming that `base_cmt` is not of fixed-length type.
11111110
//!
11121111
//! # Parameters
1113-
//! - `elt`: the AST node being indexed
1112+
//! - `elt`: the HIR node being indexed
11141113
//! - `base_cmt`: the cmt of `elt`
11151114
11161115
let interior_elem = InteriorElement(context);
@@ -1119,14 +1118,14 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
11191118
return Ok(ret);
11201119
}
11211120

1122-
pub fn cat_imm_interior<N:ast_node>(&self,
1121+
pub fn cat_imm_interior<N:HirNode>(&self,
11231122
node: &N,
11241123
base_cmt: cmt<'tcx>,
11251124
interior_ty: Ty<'tcx>,
11261125
interior: InteriorKind)
11271126
-> cmt_<'tcx> {
11281127
let ret = cmt_ {
1129-
id: node.id(),
1128+
hir_id: node.hir_id(),
11301129
span: node.span(),
11311130
mutbl: base_cmt.mutbl.inherit(),
11321131
cat: Categorization::Interior(base_cmt, interior),
@@ -1137,7 +1136,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
11371136
ret
11381137
}
11391138

1140-
pub fn cat_downcast_if_needed<N:ast_node>(&self,
1139+
pub fn cat_downcast_if_needed<N:HirNode>(&self,
11411140
node: &N,
11421141
base_cmt: cmt<'tcx>,
11431142
variant_did: DefId)
@@ -1147,7 +1146,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
11471146
if self.tcx.adt_def(base_did).variants.len() != 1 {
11481147
let base_ty = base_cmt.ty;
11491148
let ret = Rc::new(cmt_ {
1150-
id: node.id(),
1149+
hir_id: node.hir_id(),
11511150
span: node.span(),
11521151
mutbl: base_cmt.mutbl.inherit(),
11531152
cat: Categorization::Downcast(base_cmt, variant_did),

0 commit comments

Comments
 (0)