@@ -18,11 +18,13 @@ use rustc_front::hir;
18
18
use rustc_front:: util:: walk_pat;
19
19
use syntax:: codemap:: { respan, Span , Spanned , DUMMY_SP } ;
20
20
21
+ use std:: cell:: RefCell ;
22
+
21
23
pub type PatIdMap = FnvHashMap < ast:: Name , ast:: NodeId > ;
22
24
23
25
// This is used because same-named variables in alternative patterns need to
24
26
// use the NodeId of their namesake in the first pattern.
25
- pub fn pat_id_map ( dm : & DefMap , pat : & hir:: Pat ) -> PatIdMap {
27
+ pub fn pat_id_map ( dm : & RefCell < DefMap > , pat : & hir:: Pat ) -> PatIdMap {
26
28
let mut map = FnvHashMap ( ) ;
27
29
pat_bindings ( dm, pat, |_bm, p_id, _s, path1| {
28
30
map. insert ( path1. node , p_id) ;
@@ -36,7 +38,7 @@ pub fn pat_is_refutable(dm: &DefMap, pat: &hir::Pat) -> bool {
36
38
hir:: PatEnum ( _, _) |
37
39
hir:: PatIdent ( _, _, None ) |
38
40
hir:: PatStruct ( ..) => {
39
- match dm. borrow ( ) . get ( & pat. id ) . map ( |d| d. full_def ( ) ) {
41
+ match dm. get ( & pat. id ) . map ( |d| d. full_def ( ) ) {
40
42
Some ( DefVariant ( ..) ) => true ,
41
43
_ => false
42
44
}
@@ -51,7 +53,7 @@ pub fn pat_is_variant_or_struct(dm: &DefMap, pat: &hir::Pat) -> bool {
51
53
hir:: PatEnum ( _, _) |
52
54
hir:: PatIdent ( _, _, None ) |
53
55
hir:: PatStruct ( ..) => {
54
- match dm. borrow ( ) . get ( & pat. id ) . map ( |d| d. full_def ( ) ) {
56
+ match dm. get ( & pat. id ) . map ( |d| d. full_def ( ) ) {
55
57
Some ( DefVariant ( ..) ) | Some ( DefStruct ( ..) ) => true ,
56
58
_ => false
57
59
}
@@ -63,7 +65,7 @@ pub fn pat_is_variant_or_struct(dm: &DefMap, pat: &hir::Pat) -> bool {
63
65
pub fn pat_is_const ( dm : & DefMap , pat : & hir:: Pat ) -> bool {
64
66
match pat. node {
65
67
hir:: PatIdent ( _, _, None ) | hir:: PatEnum ( ..) | hir:: PatQPath ( ..) => {
66
- match dm. borrow ( ) . get ( & pat. id ) . map ( |d| d. full_def ( ) ) {
68
+ match dm. get ( & pat. id ) . map ( |d| d. full_def ( ) ) {
67
69
Some ( DefConst ( ..) ) | Some ( DefAssociatedConst ( ..) ) => true ,
68
70
_ => false
69
71
}
@@ -77,7 +79,7 @@ pub fn pat_is_const(dm: &DefMap, pat: &hir::Pat) -> bool {
77
79
pub fn pat_is_resolved_const ( dm : & DefMap , pat : & hir:: Pat ) -> bool {
78
80
match pat. node {
79
81
hir:: PatIdent ( _, _, None ) | hir:: PatEnum ( ..) | hir:: PatQPath ( ..) => {
80
- match dm. borrow ( ) . get ( & pat. id )
82
+ match dm. get ( & pat. id )
81
83
. and_then ( |d| if d. depth == 0 { Some ( d. base_def ) }
82
84
else { None } ) {
83
85
Some ( DefConst ( ..) ) | Some ( DefAssociatedConst ( ..) ) => true ,
@@ -108,12 +110,12 @@ pub fn pat_is_binding_or_wild(dm: &DefMap, pat: &hir::Pat) -> bool {
108
110
109
111
/// Call `it` on every "binding" in a pattern, e.g., on `a` in
110
112
/// `match foo() { Some(a) => (), None => () }`
111
- pub fn pat_bindings < I > ( dm : & DefMap , pat : & hir:: Pat , mut it : I ) where
113
+ pub fn pat_bindings < I > ( dm : & RefCell < DefMap > , pat : & hir:: Pat , mut it : I ) where
112
114
I : FnMut ( hir:: BindingMode , ast:: NodeId , Span , & Spanned < ast:: Name > ) ,
113
115
{
114
116
walk_pat ( pat, |p| {
115
117
match p. node {
116
- hir:: PatIdent ( binding_mode, ref pth, _) if pat_is_binding ( dm , p) => {
118
+ hir:: PatIdent ( binding_mode, ref pth, _) if pat_is_binding ( & dm . borrow ( ) , p) => {
117
119
it ( binding_mode, p. id , p. span , & respan ( pth. span , pth. node . name ) ) ;
118
120
}
119
121
_ => { }
@@ -122,12 +124,12 @@ pub fn pat_bindings<I>(dm: &DefMap, pat: &hir::Pat, mut it: I) where
122
124
} ) ;
123
125
}
124
126
125
- pub fn pat_bindings_hygienic < I > ( dm : & DefMap , pat : & hir:: Pat , mut it : I ) where
127
+ pub fn pat_bindings_hygienic < I > ( dm : & RefCell < DefMap > , pat : & hir:: Pat , mut it : I ) where
126
128
I : FnMut ( hir:: BindingMode , ast:: NodeId , Span , & Spanned < ast:: Ident > ) ,
127
129
{
128
130
walk_pat ( pat, |p| {
129
131
match p. node {
130
- hir:: PatIdent ( binding_mode, ref pth, _) if pat_is_binding ( dm , p) => {
132
+ hir:: PatIdent ( binding_mode, ref pth, _) if pat_is_binding ( & dm . borrow ( ) , p) => {
131
133
it ( binding_mode, p. id , p. span , & respan ( pth. span , pth. node ) ) ;
132
134
}
133
135
_ => { }
@@ -153,7 +155,7 @@ pub fn pat_contains_bindings(dm: &DefMap, pat: &hir::Pat) -> bool {
153
155
154
156
/// Checks if the pattern contains any `ref` or `ref mut` bindings,
155
157
/// and if yes wether its containing mutable ones or just immutables ones.
156
- pub fn pat_contains_ref_binding ( dm : & DefMap , pat : & hir:: Pat ) -> Option < hir:: Mutability > {
158
+ pub fn pat_contains_ref_binding ( dm : & RefCell < DefMap > , pat : & hir:: Pat ) -> Option < hir:: Mutability > {
157
159
let mut result = None ;
158
160
pat_bindings ( dm, pat, |mode, _, _, _| {
159
161
match mode {
@@ -172,7 +174,7 @@ pub fn pat_contains_ref_binding(dm: &DefMap, pat: &hir::Pat) -> Option<hir::Muta
172
174
173
175
/// Checks if the patterns for this arm contain any `ref` or `ref mut`
174
176
/// bindings, and if yes wether its containing mutable ones or just immutables ones.
175
- pub fn arm_contains_ref_binding ( dm : & DefMap , arm : & hir:: Arm ) -> Option < hir:: Mutability > {
177
+ pub fn arm_contains_ref_binding ( dm : & RefCell < DefMap > , arm : & hir:: Arm ) -> Option < hir:: Mutability > {
176
178
arm. pats . iter ( )
177
179
. filter_map ( |pat| pat_contains_ref_binding ( dm, pat) )
178
180
. max_by ( |m| match * m {
@@ -226,7 +228,7 @@ pub fn necessary_variants(dm: &DefMap, pat: &hir::Pat) -> Vec<DefId> {
226
228
hir:: PatEnum ( _, _) |
227
229
hir:: PatIdent ( _, _, None ) |
228
230
hir:: PatStruct ( ..) => {
229
- match dm. borrow ( ) . get ( & p. id ) {
231
+ match dm. get ( & p. id ) {
230
232
Some ( & PathResolution { base_def : DefVariant ( _, id, _) , .. } ) => {
231
233
variants. push ( id) ;
232
234
}
0 commit comments