@@ -179,17 +179,21 @@ pub enum Note {
179
179
// and how it is located, as well as the mutability of the memory in
180
180
// which the value is stored.
181
181
//
182
- // *WARNING* The field `cmt.ty` is NOT necessarily the same as the
183
- // result of `node_id_to_type(cmt.id)`. This is because the `id` is
184
- // always the `id` of the node producing the type; in an expression
185
- // like `*x`, the type of this deref node is the deref'd type (`T`),
186
- // but in a pattern like `@x`, the `@x` pattern is again a
187
- // dereference, but its type is the type *before* the dereference
188
- // (`@T`). So use `cmt.ty` to find the type of the value in a consistent
189
- // fashion. For more details, see the method `cat_pattern`
182
+ // *WARNING* The field `cmt.type` is NOT necessarily the same as the
183
+ // result of `node_id_to_type(cmt.id)`.
184
+ //
185
+ // (FIXME: rewrite the following comment given that `@x` managed
186
+ // pointers have been obsolete for quite some time.)
187
+ //
188
+ // This is because the `id` is always the `id` of the node producing the
189
+ // type; in an expression like `*x`, the type of this deref node is the
190
+ // deref'd type (`T`), but in a pattern like `@x`, the `@x` pattern is
191
+ // again a dereference, but its type is the type *before* the
192
+ // dereference (`@T`). So use `cmt.ty` to find the type of the value in
193
+ // a consistent fashion. For more details, see the method `cat_pattern`
190
194
#[ derive( Clone , Debug , PartialEq ) ]
191
195
pub struct cmt_ < ' tcx > {
192
- 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
193
197
pub span : Span , // span of same expr/pat
194
198
pub cat : Categorization < ' tcx > , // categorization of expr
195
199
pub mutbl : MutabilityCategory , // mutability of expr as place
@@ -271,18 +275,18 @@ impl<'tcx> cmt_<'tcx> {
271
275
}
272
276
}
273
277
274
- pub trait ast_node {
275
- fn id ( & self ) -> ast :: NodeId ;
278
+ pub trait HirNode {
279
+ fn hir_id ( & self ) -> hir :: HirId ;
276
280
fn span ( & self ) -> Span ;
277
281
}
278
282
279
- impl ast_node for hir:: Expr {
280
- fn id ( & self ) -> ast :: NodeId { self . id }
283
+ impl HirNode for hir:: Expr {
284
+ fn hir_id ( & self ) -> hir :: HirId { self . hir_id }
281
285
fn span ( & self ) -> Span { self . span }
282
286
}
283
287
284
- impl ast_node for hir:: Pat {
285
- fn id ( & self ) -> ast :: NodeId { self . id }
288
+ impl HirNode for hir:: Pat {
289
+ fn hir_id ( & self ) -> hir :: HirId { self . hir_id }
286
290
fn span ( & self ) -> Span { self . span }
287
291
}
288
292
@@ -610,7 +614,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
610
614
ty : target,
611
615
mutbl : deref. mutbl ,
612
616
} ) ;
613
- self . cat_rvalue_node ( expr. id , expr. span , ref_ty)
617
+ self . cat_rvalue_node ( expr. hir_id , expr. span , ref_ty)
614
618
} else {
615
619
previous ( ) ?
616
620
} ) ;
@@ -625,7 +629,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
625
629
adjustment:: Adjust :: Borrow ( _) |
626
630
adjustment:: Adjust :: Unsize => {
627
631
// Result is an rvalue.
628
- Ok ( self . cat_rvalue_node ( expr. id , expr. span , target) )
632
+ Ok ( self . cat_rvalue_node ( expr. hir_id , expr. span , target) )
629
633
}
630
634
}
631
635
}
@@ -669,8 +673,8 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
669
673
}
670
674
671
675
hir:: ExprPath ( ref qpath) => {
672
- let def = self . tables . qpath_def ( qpath, expr. hir_id ) ;
673
- 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)
674
678
}
675
679
676
680
hir:: ExprType ( ref e, _) => {
@@ -688,35 +692,35 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
688
692
hir:: ExprLit ( ..) | hir:: ExprBreak ( ..) |
689
693
hir:: ExprContinue ( ..) | hir:: ExprStruct ( ..) | hir:: ExprRepeat ( ..) |
690
694
hir:: ExprInlineAsm ( ..) | hir:: ExprBox ( ..) => {
691
- Ok ( self . cat_rvalue_node ( expr. id ( ) , expr. span ( ) , expr_ty) )
695
+ Ok ( self . cat_rvalue_node ( expr. hir_id , expr. span , expr_ty) )
692
696
}
693
697
}
694
698
}
695
699
696
700
pub fn cat_def ( & self ,
697
- id : ast :: NodeId ,
701
+ hir_id : hir :: HirId ,
698
702
span : Span ,
699
703
expr_ty : Ty < ' tcx > ,
700
704
def : Def )
701
705
-> McResult < cmt_ < ' tcx > > {
702
- debug ! ( "cat_def: id={} expr={:?} def={:?}" ,
703
- id , expr_ty, def) ;
706
+ debug ! ( "cat_def: id={:? } expr={:?} def={:?}" ,
707
+ hir_id , expr_ty, def) ;
704
708
705
709
match def {
706
710
Def :: StructCtor ( ..) | Def :: VariantCtor ( ..) | Def :: Const ( ..) |
707
711
Def :: AssociatedConst ( ..) | Def :: Fn ( ..) | Def :: Method ( ..) => {
708
- Ok ( self . cat_rvalue_node ( id , span, expr_ty) )
712
+ Ok ( self . cat_rvalue_node ( hir_id , span, expr_ty) )
709
713
}
710
714
711
715
Def :: Static ( def_id, mutbl) => {
712
716
// `#[thread_local]` statics may not outlive the current function.
713
717
for attr in & self . tcx . get_attrs ( def_id) [ ..] {
714
718
if attr. check_name ( "thread_local" ) {
715
- return Ok ( self . cat_rvalue_node ( id , span, expr_ty) ) ;
719
+ return Ok ( self . cat_rvalue_node ( hir_id , span, expr_ty) ) ;
716
720
}
717
721
}
718
722
Ok ( cmt_ {
719
- id : id ,
723
+ hir_id ,
720
724
span : span,
721
725
cat : Categorization :: StaticItem ,
722
726
mutbl : if mutbl { McDeclared } else { McImmutable } ,
@@ -726,12 +730,12 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
726
730
}
727
731
728
732
Def :: Upvar ( var_id, _, fn_node_id) => {
729
- self . cat_upvar ( id , span, var_id, fn_node_id)
733
+ self . cat_upvar ( hir_id , span, var_id, fn_node_id)
730
734
}
731
735
732
736
Def :: Local ( vid) => {
733
737
Ok ( cmt_ {
734
- id ,
738
+ hir_id ,
735
739
span,
736
740
cat : Categorization :: Local ( vid) ,
737
741
mutbl : MutabilityCategory :: from_local ( self . tcx , self . tables , vid) ,
@@ -747,7 +751,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
747
751
// Categorize an upvar, complete with invisible derefs of closure
748
752
// environment and upvar reference as appropriate.
749
753
fn cat_upvar ( & self ,
750
- id : ast :: NodeId ,
754
+ hir_id : hir :: HirId ,
751
755
span : Span ,
752
756
var_id : ast:: NodeId ,
753
757
fn_node_id : ast:: NodeId )
@@ -814,7 +818,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
814
818
// from the environment (perhaps we should eventually desugar
815
819
// this field further, but it will do for now).
816
820
let cmt_result = cmt_ {
817
- id ,
821
+ hir_id ,
818
822
span,
819
823
cat : Categorization :: Upvar ( Upvar { id : upvar_id, kind : kind} ) ,
820
824
mutbl : var_mutbl,
@@ -830,10 +834,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
830
834
cmt_result
831
835
}
832
836
ty:: ClosureKind :: FnMut => {
833
- 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)
834
838
}
835
839
ty:: ClosureKind :: Fn => {
836
- 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)
837
841
}
838
842
} ;
839
843
@@ -848,7 +852,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
848
852
ty:: UpvarCapture :: ByRef ( upvar_borrow) => {
849
853
let ptr = BorrowedPtr ( upvar_borrow. kind , upvar_borrow. region ) ;
850
854
cmt_ {
851
- id ,
855
+ hir_id ,
852
856
span,
853
857
cat : Categorization :: Deref ( Rc :: new ( cmt_result) , ptr) ,
854
858
mutbl : MutabilityCategory :: from_borrow_kind ( upvar_borrow. kind ) ,
@@ -864,7 +868,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
864
868
}
865
869
866
870
fn env_deref ( & self ,
867
- id : ast :: NodeId ,
871
+ hir_id : hir :: HirId ,
868
872
span : Span ,
869
873
upvar_id : ty:: UpvarId ,
870
874
upvar_mutbl : MutabilityCategory ,
@@ -908,7 +912,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
908
912
}
909
913
910
914
let ret = cmt_ {
911
- id ,
915
+ hir_id ,
912
916
span,
913
917
cat : Categorization :: Deref ( Rc :: new ( cmt_result) , env_ptr) ,
914
918
mutbl : deref_mutbl,
@@ -932,17 +936,16 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
932
936
}
933
937
934
938
pub fn cat_rvalue_node ( & self ,
935
- id : ast :: NodeId ,
939
+ hir_id : hir :: HirId ,
936
940
span : Span ,
937
941
expr_ty : Ty < ' tcx > )
938
942
-> cmt_ < ' tcx > {
939
943
debug ! (
940
944
"cat_rvalue_node(id={:?}, span={:?}, expr_ty={:?})" ,
941
- id ,
945
+ hir_id ,
942
946
span,
943
947
expr_ty,
944
948
) ;
945
- let hir_id = self . tcx . hir . node_to_hir_id ( id) ;
946
949
let promotable = self . rvalue_promotable_map . as_ref ( ) . map ( |m| m. contains ( & hir_id. local_id ) )
947
950
. unwrap_or ( false ) ;
948
951
@@ -970,18 +973,18 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
970
973
} else {
971
974
self . temporary_scope ( hir_id. local_id )
972
975
} ;
973
- let ret = self . cat_rvalue ( id , span, re, expr_ty) ;
976
+ let ret = self . cat_rvalue ( hir_id , span, re, expr_ty) ;
974
977
debug ! ( "cat_rvalue_node ret {:?}" , ret) ;
975
978
ret
976
979
}
977
980
978
981
pub fn cat_rvalue ( & self ,
979
- cmt_id : ast :: NodeId ,
982
+ cmt_hir_id : hir :: HirId ,
980
983
span : Span ,
981
984
temp_scope : ty:: Region < ' tcx > ,
982
985
expr_ty : Ty < ' tcx > ) -> cmt_ < ' tcx > {
983
986
let ret = cmt_ {
984
- id : cmt_id ,
987
+ hir_id : cmt_hir_id ,
985
988
span : span,
986
989
cat : Categorization :: Rvalue ( temp_scope) ,
987
990
mutbl : McDeclared ,
@@ -992,15 +995,15 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
992
995
ret
993
996
}
994
997
995
- pub fn cat_field < N : ast_node > ( & self ,
998
+ pub fn cat_field < N : HirNode > ( & self ,
996
999
node : & N ,
997
1000
base_cmt : cmt < ' tcx > ,
998
1001
f_index : usize ,
999
1002
f_ident : ast:: Ident ,
1000
1003
f_ty : Ty < ' tcx > )
1001
1004
-> cmt_ < ' tcx > {
1002
1005
let ret = cmt_ {
1003
- id : node. id ( ) ,
1006
+ hir_id : node. hir_id ( ) ,
1004
1007
span : node. span ( ) ,
1005
1008
mutbl : base_cmt. mutbl . inherit ( ) ,
1006
1009
cat : Categorization :: Interior ( base_cmt,
@@ -1042,13 +1045,13 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1042
1045
mutbl,
1043
1046
} ) ;
1044
1047
1045
- 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) ) ;
1046
1049
self . cat_deref ( expr, base_cmt, note)
1047
1050
}
1048
1051
1049
1052
pub fn cat_deref (
1050
1053
& self ,
1051
- node : & impl ast_node ,
1054
+ node : & impl HirNode ,
1052
1055
base_cmt : cmt < ' tcx > ,
1053
1056
note : Note ,
1054
1057
) -> McResult < cmt_ < ' tcx > > {
@@ -1074,7 +1077,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1074
1077
ref ty => bug ! ( "unexpected type in cat_deref: {:?}" , ty)
1075
1078
} ;
1076
1079
let ret = cmt_ {
1077
- id : node. id ( ) ,
1080
+ hir_id : node. hir_id ( ) ,
1078
1081
span : node. span ( ) ,
1079
1082
// For unique ptrs, we inherit mutability from the owning reference.
1080
1083
mutbl : MutabilityCategory :: from_pointer_kind ( base_cmt. mutbl , ptr) ,
@@ -1086,7 +1089,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1086
1089
Ok ( ret)
1087
1090
}
1088
1091
1089
- fn cat_index < N : ast_node > ( & self ,
1092
+ fn cat_index < N : HirNode > ( & self ,
1090
1093
elt : & N ,
1091
1094
base_cmt : cmt < ' tcx > ,
1092
1095
element_ty : Ty < ' tcx > ,
@@ -1106,7 +1109,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1106
1109
//! presuming that `base_cmt` is not of fixed-length type.
1107
1110
//!
1108
1111
//! # Parameters
1109
- //! - `elt`: the AST node being indexed
1112
+ //! - `elt`: the HIR node being indexed
1110
1113
//! - `base_cmt`: the cmt of `elt`
1111
1114
1112
1115
let interior_elem = InteriorElement ( context) ;
@@ -1115,14 +1118,14 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1115
1118
return Ok ( ret) ;
1116
1119
}
1117
1120
1118
- pub fn cat_imm_interior < N : ast_node > ( & self ,
1121
+ pub fn cat_imm_interior < N : HirNode > ( & self ,
1119
1122
node : & N ,
1120
1123
base_cmt : cmt < ' tcx > ,
1121
1124
interior_ty : Ty < ' tcx > ,
1122
1125
interior : InteriorKind )
1123
1126
-> cmt_ < ' tcx > {
1124
1127
let ret = cmt_ {
1125
- id : node. id ( ) ,
1128
+ hir_id : node. hir_id ( ) ,
1126
1129
span : node. span ( ) ,
1127
1130
mutbl : base_cmt. mutbl . inherit ( ) ,
1128
1131
cat : Categorization :: Interior ( base_cmt, interior) ,
@@ -1133,7 +1136,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1133
1136
ret
1134
1137
}
1135
1138
1136
- pub fn cat_downcast_if_needed < N : ast_node > ( & self ,
1139
+ pub fn cat_downcast_if_needed < N : HirNode > ( & self ,
1137
1140
node : & N ,
1138
1141
base_cmt : cmt < ' tcx > ,
1139
1142
variant_did : DefId )
@@ -1143,7 +1146,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1143
1146
if self . tcx . adt_def ( base_did) . variants . len ( ) != 1 {
1144
1147
let base_ty = base_cmt. ty ;
1145
1148
let ret = Rc :: new ( cmt_ {
1146
- id : node. id ( ) ,
1149
+ hir_id : node. hir_id ( ) ,
1147
1150
span : node. span ( ) ,
1148
1151
mutbl : base_cmt. mutbl . inherit ( ) ,
1149
1152
cat : Categorization :: Downcast ( base_cmt, variant_did) ,
@@ -1193,6 +1196,8 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
1193
1196
// value, and I consider them to produce the value that was
1194
1197
// matched. So if you have something like:
1195
1198
//
1199
+ // (FIXME: `@@3` is not legal code anymore!)
1200
+ //
1196
1201
// let x = @@3;
1197
1202
// match x {
1198
1203
// @@y { ... }
0 commit comments