@@ -35,16 +35,28 @@ use std::ops::ControlFlow;
35
35
/// For more background on why Rust has this requirement, and issues
36
36
/// that arose when the requirement was not enforced completely, see
37
37
/// Rust RFC 1445, rust-lang/rust#61188, and rust-lang/rust#62307.
38
- ///
39
- /// When the `valtree_semantics` flag is set, then we also deny additional
40
- /// types that are not evaluatable to valtrees, such as floats and fn ptrs.
41
38
pub fn search_for_structural_match_violation < ' tcx > (
42
39
span : Span ,
43
40
tcx : TyCtxt < ' tcx > ,
44
41
ty : Ty < ' tcx > ,
45
- valtree_semantics : bool ,
46
42
) -> Option < Ty < ' tcx > > {
47
- ty. visit_with ( & mut Search { tcx, span, seen : FxHashSet :: default ( ) , valtree_semantics } )
43
+ ty. visit_with ( & mut Search { tcx, span, seen : FxHashSet :: default ( ) , adt_const_param : false } )
44
+ . break_value ( )
45
+ }
46
+
47
+ /// This method traverses the structure of `ty`, trying to find any
48
+ /// types that are not allowed to be used in a const generic.
49
+ ///
50
+ /// This is either because the type does not implement `StructuralEq`
51
+ /// and `StructuralPartialEq`, or because the type is intentionally
52
+ /// not supported in const generics (such as floats and raw pointers,
53
+ /// which are allowed in match blocks).
54
+ pub fn search_for_adt_const_param_violation < ' tcx > (
55
+ span : Span ,
56
+ tcx : TyCtxt < ' tcx > ,
57
+ ty : Ty < ' tcx > ,
58
+ ) -> Option < Ty < ' tcx > > {
59
+ ty. visit_with ( & mut Search { tcx, span, seen : FxHashSet :: default ( ) , adt_const_param : true } )
48
60
. break_value ( )
49
61
}
50
62
@@ -108,8 +120,9 @@ struct Search<'tcx> {
108
120
seen : FxHashSet < hir:: def_id:: DefId > ,
109
121
110
122
// Additionally deny things that have been allowed in patterns,
111
- // but are not evaluatable to a valtree, such as floats and fn ptrs.
112
- valtree_semantics : bool ,
123
+ // but are not allowed in adt const params, such as floats and
124
+ // fn ptrs.
125
+ adt_const_param : bool ,
113
126
}
114
127
115
128
impl < ' tcx > Search < ' tcx > {
@@ -167,15 +180,15 @@ impl<'tcx> TypeVisitor<'tcx> for Search<'tcx> {
167
180
}
168
181
169
182
ty:: FnPtr ( ..) => {
170
- if !self . valtree_semantics {
183
+ if !self . adt_const_param {
171
184
return ControlFlow :: CONTINUE ;
172
185
} else {
173
186
return ControlFlow :: Break ( ty) ;
174
187
}
175
188
}
176
189
177
190
ty:: RawPtr ( ..) => {
178
- if !self . valtree_semantics {
191
+ if !self . adt_const_param {
179
192
// structural-match ignores substructure of
180
193
// `*const _`/`*mut _`, so skip `super_visit_with`.
181
194
//
@@ -197,7 +210,7 @@ impl<'tcx> TypeVisitor<'tcx> for Search<'tcx> {
197
210
}
198
211
199
212
ty:: Float ( _) => {
200
- if !self . valtree_semantics {
213
+ if !self . adt_const_param {
201
214
return ControlFlow :: CONTINUE ;
202
215
} else {
203
216
return ControlFlow :: Break ( ty) ;
0 commit comments