@@ -6,31 +6,10 @@ use rustc_data_structures::fx::FxHashSet;
66use rustc_hir as hir;
77use rustc_hir:: lang_items:: LangItem ;
88use 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 } ;
1010use rustc_span:: Span ;
1111use std:: ops:: ControlFlow ;
1212
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-
3413/// This method traverses the structure of `ty`, trying to find an
3514/// instance of an ADT (i.e. struct or enum) that doesn't implement
3615/// the structural-match traits, or a generic type parameter
@@ -64,7 +43,7 @@ pub fn search_for_structural_match_violation<'tcx>(
6443 tcx : TyCtxt < ' tcx > ,
6544 ty : Ty < ' tcx > ,
6645 valtree_semantics : bool ,
67- ) -> Option < NonStructuralMatchTy < ' tcx > > {
46+ ) -> Option < Ty < ' tcx > > {
6847 ty. visit_with ( & mut Search { tcx, span, seen : FxHashSet :: default ( ) , valtree_semantics } )
6948 . break_value ( )
7049}
@@ -140,40 +119,33 @@ impl<'tcx> Search<'tcx> {
140119}
141120
142121impl < ' tcx > TypeVisitor < ' tcx > for Search < ' tcx > {
143- type BreakTy = NonStructuralMatchTy < ' tcx > ;
122+ type BreakTy = Ty < ' tcx > ;
144123
145124 fn visit_ty ( & mut self , ty : Ty < ' tcx > ) -> ControlFlow < Self :: BreakTy > {
146125 debug ! ( "Search visiting ty: {:?}" , ty) ;
147126
148127 let ( adt_def, substs) = match * ty. kind ( ) {
149128 ty:: Adt ( adt_def, substs) => ( adt_def, substs) ,
150129 ty:: Param ( _) => {
151- let kind = NonStructuralMatchTyKind :: Param ;
152- return ControlFlow :: Break ( NonStructuralMatchTy { ty, kind } ) ;
130+ return ControlFlow :: Break ( ty) ;
153131 }
154132 ty:: Dynamic ( ..) => {
155- let kind = NonStructuralMatchTyKind :: Dynamic ;
156- return ControlFlow :: Break ( NonStructuralMatchTy { ty, kind } ) ;
133+ return ControlFlow :: Break ( ty) ;
157134 }
158135 ty:: Foreign ( _) => {
159- let kind = NonStructuralMatchTyKind :: Foreign ;
160- return ControlFlow :: Break ( NonStructuralMatchTy { ty, kind } ) ;
136+ return ControlFlow :: Break ( ty) ;
161137 }
162138 ty:: Opaque ( ..) => {
163- let kind = NonStructuralMatchTyKind :: Opaque ;
164- return ControlFlow :: Break ( NonStructuralMatchTy { ty, kind } ) ;
139+ return ControlFlow :: Break ( ty) ;
165140 }
166141 ty:: Projection ( ..) => {
167- let kind = NonStructuralMatchTyKind :: Projection ;
168- return ControlFlow :: Break ( NonStructuralMatchTy { ty, kind } ) ;
142+ return ControlFlow :: Break ( ty) ;
169143 }
170144 ty:: Closure ( ..) => {
171- let kind = NonStructuralMatchTyKind :: Closure ;
172- return ControlFlow :: Break ( NonStructuralMatchTy { ty, kind } ) ;
145+ return ControlFlow :: Break ( ty) ;
173146 }
174147 ty:: Generator ( ..) | ty:: GeneratorWitness ( ..) => {
175- let kind = NonStructuralMatchTyKind :: Generator ;
176- return ControlFlow :: Break ( NonStructuralMatchTy { ty, kind } ) ;
148+ return ControlFlow :: Break ( ty) ;
177149 }
178150 ty:: FnDef ( ..) => {
179151 // Types of formals and return in `fn(_) -> _` are also irrelevant;
@@ -198,10 +170,7 @@ impl<'tcx> TypeVisitor<'tcx> for Search<'tcx> {
198170 if !self . valtree_semantics {
199171 return ControlFlow :: CONTINUE ;
200172 } else {
201- return ControlFlow :: Break ( NonStructuralMatchTy {
202- ty,
203- kind : NonStructuralMatchTyKind :: FnPtr ,
204- } ) ;
173+ return ControlFlow :: Break ( ty) ;
205174 }
206175 }
207176
@@ -223,21 +192,15 @@ impl<'tcx> TypeVisitor<'tcx> for Search<'tcx> {
223192 // pointer. Therefore, one can still use `C` in a pattern.
224193 return ControlFlow :: CONTINUE ;
225194 } else {
226- return ControlFlow :: Break ( NonStructuralMatchTy {
227- ty,
228- kind : NonStructuralMatchTyKind :: FnPtr ,
229- } ) ;
195+ return ControlFlow :: Break ( ty) ;
230196 }
231197 }
232198
233199 ty:: Float ( _) => {
234200 if !self . valtree_semantics {
235201 return ControlFlow :: CONTINUE ;
236202 } else {
237- return ControlFlow :: Break ( NonStructuralMatchTy {
238- ty,
239- kind : NonStructuralMatchTyKind :: Float ,
240- } ) ;
203+ return ControlFlow :: Break ( ty) ;
241204 }
242205 }
243206
@@ -263,8 +226,7 @@ impl<'tcx> TypeVisitor<'tcx> for Search<'tcx> {
263226
264227 if !self . type_marked_structural ( ty) {
265228 debug ! ( "Search found ty: {:?}" , ty) ;
266- let kind = NonStructuralMatchTyKind :: Adt ( adt_def) ;
267- return ControlFlow :: Break ( NonStructuralMatchTy { ty, kind } ) ;
229+ return ControlFlow :: Break ( ty) ;
268230 }
269231
270232 // structural-match does not care about the
0 commit comments