@@ -6,31 +6,10 @@ use rustc_data_structures::fx::FxHashSet;
6
6
use rustc_hir as hir;
7
7
use rustc_hir:: lang_items:: LangItem ;
8
8
use rustc_middle:: ty:: query:: Providers ;
9
- use rustc_middle:: ty:: { self , AdtDef , Ty , TyCtxt , TypeSuperVisitable , TypeVisitable , TypeVisitor } ;
9
+ use rustc_middle:: ty:: { self , Ty , TyCtxt , TypeSuperVisitable , TypeVisitable , TypeVisitor } ;
10
10
use rustc_span:: Span ;
11
11
use std:: ops:: ControlFlow ;
12
12
13
- #[ derive( Debug ) ]
14
- pub struct NonStructuralMatchTy < ' tcx > {
15
- pub ty : Ty < ' tcx > ,
16
- pub kind : NonStructuralMatchTyKind < ' tcx > ,
17
- }
18
-
19
- #[ derive( Debug ) ]
20
- pub enum NonStructuralMatchTyKind < ' tcx > {
21
- Adt ( AdtDef < ' tcx > ) ,
22
- Param ,
23
- Dynamic ,
24
- Foreign ,
25
- Opaque ,
26
- Closure ,
27
- Generator ,
28
- Projection ,
29
- Float ,
30
- FnPtr ,
31
- RawPtr ,
32
- }
33
-
34
13
/// This method traverses the structure of `ty`, trying to find an
35
14
/// instance of an ADT (i.e. struct or enum) that doesn't implement
36
15
/// the structural-match traits, or a generic type parameter
@@ -64,7 +43,7 @@ pub fn search_for_structural_match_violation<'tcx>(
64
43
tcx : TyCtxt < ' tcx > ,
65
44
ty : Ty < ' tcx > ,
66
45
valtree_semantics : bool ,
67
- ) -> Option < NonStructuralMatchTy < ' tcx > > {
46
+ ) -> Option < Ty < ' tcx > > {
68
47
ty. visit_with ( & mut Search { tcx, span, seen : FxHashSet :: default ( ) , valtree_semantics } )
69
48
. break_value ( )
70
49
}
@@ -140,40 +119,33 @@ impl<'tcx> Search<'tcx> {
140
119
}
141
120
142
121
impl < ' tcx > TypeVisitor < ' tcx > for Search < ' tcx > {
143
- type BreakTy = NonStructuralMatchTy < ' tcx > ;
122
+ type BreakTy = Ty < ' tcx > ;
144
123
145
124
fn visit_ty ( & mut self , ty : Ty < ' tcx > ) -> ControlFlow < Self :: BreakTy > {
146
125
debug ! ( "Search visiting ty: {:?}" , ty) ;
147
126
148
127
let ( adt_def, substs) = match * ty. kind ( ) {
149
128
ty:: Adt ( adt_def, substs) => ( adt_def, substs) ,
150
129
ty:: Param ( _) => {
151
- let kind = NonStructuralMatchTyKind :: Param ;
152
- return ControlFlow :: Break ( NonStructuralMatchTy { ty, kind } ) ;
130
+ return ControlFlow :: Break ( ty) ;
153
131
}
154
132
ty:: Dynamic ( ..) => {
155
- let kind = NonStructuralMatchTyKind :: Dynamic ;
156
- return ControlFlow :: Break ( NonStructuralMatchTy { ty, kind } ) ;
133
+ return ControlFlow :: Break ( ty) ;
157
134
}
158
135
ty:: Foreign ( _) => {
159
- let kind = NonStructuralMatchTyKind :: Foreign ;
160
- return ControlFlow :: Break ( NonStructuralMatchTy { ty, kind } ) ;
136
+ return ControlFlow :: Break ( ty) ;
161
137
}
162
138
ty:: Opaque ( ..) => {
163
- let kind = NonStructuralMatchTyKind :: Opaque ;
164
- return ControlFlow :: Break ( NonStructuralMatchTy { ty, kind } ) ;
139
+ return ControlFlow :: Break ( ty) ;
165
140
}
166
141
ty:: Projection ( ..) => {
167
- let kind = NonStructuralMatchTyKind :: Projection ;
168
- return ControlFlow :: Break ( NonStructuralMatchTy { ty, kind } ) ;
142
+ return ControlFlow :: Break ( ty) ;
169
143
}
170
144
ty:: Closure ( ..) => {
171
- let kind = NonStructuralMatchTyKind :: Closure ;
172
- return ControlFlow :: Break ( NonStructuralMatchTy { ty, kind } ) ;
145
+ return ControlFlow :: Break ( ty) ;
173
146
}
174
147
ty:: Generator ( ..) | ty:: GeneratorWitness ( ..) => {
175
- let kind = NonStructuralMatchTyKind :: Generator ;
176
- return ControlFlow :: Break ( NonStructuralMatchTy { ty, kind } ) ;
148
+ return ControlFlow :: Break ( ty) ;
177
149
}
178
150
ty:: FnDef ( ..) => {
179
151
// Types of formals and return in `fn(_) -> _` are also irrelevant;
@@ -198,10 +170,7 @@ impl<'tcx> TypeVisitor<'tcx> for Search<'tcx> {
198
170
if !self . valtree_semantics {
199
171
return ControlFlow :: CONTINUE ;
200
172
} else {
201
- return ControlFlow :: Break ( NonStructuralMatchTy {
202
- ty,
203
- kind : NonStructuralMatchTyKind :: FnPtr ,
204
- } ) ;
173
+ return ControlFlow :: Break ( ty) ;
205
174
}
206
175
}
207
176
@@ -223,21 +192,15 @@ impl<'tcx> TypeVisitor<'tcx> for Search<'tcx> {
223
192
// pointer. Therefore, one can still use `C` in a pattern.
224
193
return ControlFlow :: CONTINUE ;
225
194
} else {
226
- return ControlFlow :: Break ( NonStructuralMatchTy {
227
- ty,
228
- kind : NonStructuralMatchTyKind :: FnPtr ,
229
- } ) ;
195
+ return ControlFlow :: Break ( ty) ;
230
196
}
231
197
}
232
198
233
199
ty:: Float ( _) => {
234
200
if !self . valtree_semantics {
235
201
return ControlFlow :: CONTINUE ;
236
202
} else {
237
- return ControlFlow :: Break ( NonStructuralMatchTy {
238
- ty,
239
- kind : NonStructuralMatchTyKind :: Float ,
240
- } ) ;
203
+ return ControlFlow :: Break ( ty) ;
241
204
}
242
205
}
243
206
@@ -263,8 +226,7 @@ impl<'tcx> TypeVisitor<'tcx> for Search<'tcx> {
263
226
264
227
if !self . type_marked_structural ( ty) {
265
228
debug ! ( "Search found ty: {:?}" , ty) ;
266
- let kind = NonStructuralMatchTyKind :: Adt ( adt_def) ;
267
- return ControlFlow :: Break ( NonStructuralMatchTy { ty, kind } ) ;
229
+ return ControlFlow :: Break ( ty) ;
268
230
}
269
231
270
232
// structural-match does not care about the
0 commit comments