@@ -18,19 +18,21 @@ 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) ;
29
31
} ) ;
30
32
map
31
33
}
32
34
33
- pub fn pat_is_refutable ( dm : & DefMap , pat : & hir:: Pat ) -> bool {
35
+ pub fn pat_is_refutable ( dm : & RefCell < DefMap > , pat : & hir:: Pat ) -> bool {
34
36
match pat. node {
35
37
hir:: PatLit ( _) | hir:: PatRange ( _, _) | hir:: PatQPath ( ..) => true ,
36
38
hir:: PatEnum ( _, _) |
@@ -46,7 +48,7 @@ pub fn pat_is_refutable(dm: &DefMap, pat: &hir::Pat) -> bool {
46
48
}
47
49
}
48
50
49
- pub fn pat_is_variant_or_struct ( dm : & DefMap , pat : & hir:: Pat ) -> bool {
51
+ pub fn pat_is_variant_or_struct ( dm : & RefCell < DefMap > , pat : & hir:: Pat ) -> bool {
50
52
match pat. node {
51
53
hir:: PatEnum ( _, _) |
52
54
hir:: PatIdent ( _, _, None ) |
@@ -60,7 +62,7 @@ pub fn pat_is_variant_or_struct(dm: &DefMap, pat: &hir::Pat) -> bool {
60
62
}
61
63
}
62
64
63
- pub fn pat_is_const ( dm : & DefMap , pat : & hir:: Pat ) -> bool {
65
+ pub fn pat_is_const ( dm : & RefCell < DefMap > , pat : & hir:: Pat ) -> bool {
64
66
match pat. node {
65
67
hir:: PatIdent ( _, _, None ) | hir:: PatEnum ( ..) | hir:: PatQPath ( ..) => {
66
68
match dm. borrow ( ) . get ( & pat. id ) . map ( |d| d. full_def ( ) ) {
@@ -74,7 +76,7 @@ pub fn pat_is_const(dm: &DefMap, pat: &hir::Pat) -> bool {
74
76
75
77
// Same as above, except that partially-resolved defs cause `false` to be
76
78
// returned instead of a panic.
77
- pub fn pat_is_resolved_const ( dm : & DefMap , pat : & hir:: Pat ) -> bool {
79
+ pub fn pat_is_resolved_const ( dm : & RefCell < DefMap > , pat : & hir:: Pat ) -> bool {
78
80
match pat. node {
79
81
hir:: PatIdent ( _, _, None ) | hir:: PatEnum ( ..) | hir:: PatQPath ( ..) => {
80
82
match dm. borrow ( ) . get ( & pat. id )
@@ -88,7 +90,7 @@ pub fn pat_is_resolved_const(dm: &DefMap, pat: &hir::Pat) -> bool {
88
90
}
89
91
}
90
92
91
- pub fn pat_is_binding ( dm : & DefMap , pat : & hir:: Pat ) -> bool {
93
+ pub fn pat_is_binding ( dm : & RefCell < DefMap > , pat : & hir:: Pat ) -> bool {
92
94
match pat. node {
93
95
hir:: PatIdent ( ..) => {
94
96
!pat_is_variant_or_struct ( dm, pat) &&
@@ -98,7 +100,7 @@ pub fn pat_is_binding(dm: &DefMap, pat: &hir::Pat) -> bool {
98
100
}
99
101
}
100
102
101
- pub fn pat_is_binding_or_wild ( dm : & DefMap , pat : & hir:: Pat ) -> bool {
103
+ pub fn pat_is_binding_or_wild ( dm : & RefCell < DefMap > , pat : & hir:: Pat ) -> bool {
102
104
match pat. node {
103
105
hir:: PatIdent ( ..) => pat_is_binding ( dm, pat) ,
104
106
hir:: PatWild => true ,
@@ -108,7 +110,7 @@ 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| {
@@ -122,7 +124,7 @@ 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| {
@@ -138,7 +140,7 @@ pub fn pat_bindings_hygienic<I>(dm: &DefMap, pat: &hir::Pat, mut it: I) where
138
140
139
141
/// Checks if the pattern contains any patterns that bind something to
140
142
/// an ident, e.g. `foo`, or `Foo(foo)` or `foo @ Bar(..)`.
141
- pub fn pat_contains_bindings ( dm : & DefMap , pat : & hir:: Pat ) -> bool {
143
+ pub fn pat_contains_bindings ( dm : & RefCell < DefMap > , pat : & hir:: Pat ) -> bool {
142
144
let mut contains_bindings = false ;
143
145
walk_pat ( pat, |p| {
144
146
if pat_is_binding ( dm, p) {
@@ -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 {
@@ -183,7 +185,7 @@ pub fn arm_contains_ref_binding(dm: &DefMap, arm: &hir::Arm) -> Option<hir::Muta
183
185
184
186
/// Checks if the pattern contains any patterns that bind something to
185
187
/// an ident or wildcard, e.g. `foo`, or `Foo(_)`, `foo @ Bar(..)`,
186
- pub fn pat_contains_bindings_or_wild ( dm : & DefMap , pat : & hir:: Pat ) -> bool {
188
+ pub fn pat_contains_bindings_or_wild ( dm : & RefCell < DefMap > , pat : & hir:: Pat ) -> bool {
187
189
let mut contains_bindings = false ;
188
190
walk_pat ( pat, |p| {
189
191
if pat_is_binding_or_wild ( dm, p) {
@@ -219,7 +221,7 @@ pub fn def_to_path(tcx: &ty::ctxt, id: DefId) -> hir::Path {
219
221
}
220
222
221
223
/// Return variants that are necessary to exist for the pattern to match.
222
- pub fn necessary_variants ( dm : & DefMap , pat : & hir:: Pat ) -> Vec < DefId > {
224
+ pub fn necessary_variants ( dm : & RefCell < DefMap > , pat : & hir:: Pat ) -> Vec < DefId > {
223
225
let mut variants = vec ! [ ] ;
224
226
walk_pat ( pat, |p| {
225
227
match p. node {
0 commit comments