@@ -16,8 +16,8 @@ use std::cell::Cell;
16
16
17
17
use super :: PatCtxt ;
18
18
use crate :: errors:: {
19
- IndirectStructuralMatch , InvalidPattern , NaNPattern , PointerPattern , TypeNotPartialEq ,
20
- TypeNotStructural , UnionPattern , UnsizedPattern ,
19
+ InvalidPattern , NaNPattern , PointerPattern , TypeNotPartialEq , TypeNotStructural , UnionPattern ,
20
+ UnsizedPattern ,
21
21
} ;
22
22
23
23
impl < ' a , ' tcx > PatCtxt < ' a , ' tcx > {
@@ -49,15 +49,6 @@ struct ConstToPat<'tcx> {
49
49
// value.
50
50
saw_const_match_error : Cell < Option < ErrorGuaranteed > > ,
51
51
52
- // This tracks if we emitted some diagnostic for a given const value, so that
53
- // we will not subsequently issue an irrelevant lint for the same const
54
- // value.
55
- saw_const_match_lint : Cell < bool > ,
56
-
57
- // For backcompat we need to keep allowing non-structurally-eq types behind references.
58
- // See also all the `cant-hide-behind` tests.
59
- behind_reference : Cell < bool > ,
60
-
61
52
// inference context used for checking `T: Structural` bounds.
62
53
infcx : InferCtxt < ' tcx > ,
63
54
@@ -84,8 +75,6 @@ impl<'tcx> ConstToPat<'tcx> {
84
75
infcx,
85
76
param_env : pat_ctxt. param_env ,
86
77
saw_const_match_error : Cell :: new ( None ) ,
87
- saw_const_match_lint : Cell :: new ( false ) ,
88
- behind_reference : Cell :: new ( false ) ,
89
78
treat_byte_string_as_slice : pat_ctxt
90
79
. typeck_results
91
80
. treat_byte_string_as_slice
@@ -197,7 +186,7 @@ impl<'tcx> ConstToPat<'tcx> {
197
186
// complained about structural match violations there, so we don't
198
187
// have to check anything any more.
199
188
}
200
- } else if !have_valtree && ! self . saw_const_match_lint . get ( ) {
189
+ } else if !have_valtree {
201
190
// The only way valtree construction can fail without the structural match
202
191
// checker finding a violation is if there is a pointer somewhere.
203
192
self . tcx ( ) . emit_node_span_lint (
@@ -274,36 +263,11 @@ impl<'tcx> ConstToPat<'tcx> {
274
263
cv : ValTree < ' tcx > ,
275
264
ty : Ty < ' tcx > ,
276
265
) -> Result < Box < Pat < ' tcx > > , FallbackToOpaqueConst > {
277
- let id = self . id ;
278
266
let span = self . span ;
279
267
let tcx = self . tcx ( ) ;
280
268
let param_env = self . param_env ;
281
269
282
270
let kind = match ty. kind ( ) {
283
- // If the type is not structurally comparable, just emit the constant directly,
284
- // causing the pattern match code to treat it opaquely.
285
- // FIXME: This code doesn't emit errors itself, the caller emits the errors.
286
- // So instead of specific errors, you just get blanket errors about the whole
287
- // const type. See
288
- // https://github.com/rust-lang/rust/pull/70743#discussion_r404701963 for
289
- // details.
290
- // Backwards compatibility hack because we can't cause hard errors on these
291
- // types, so we compare them via `PartialEq::eq` at runtime.
292
- ty:: Adt ( ..) if !self . type_marked_structural ( ty) && self . behind_reference . get ( ) => {
293
- if self . saw_const_match_error . get ( ) . is_none ( ) && !self . saw_const_match_lint . get ( ) {
294
- self . saw_const_match_lint . set ( true ) ;
295
- tcx. emit_node_span_lint (
296
- lint:: builtin:: INDIRECT_STRUCTURAL_MATCH ,
297
- id,
298
- span,
299
- IndirectStructuralMatch { non_sm_ty : ty } ,
300
- ) ;
301
- }
302
- // Since we are behind a reference, we can just bubble the error up so we get a
303
- // constant at reference type, making it easy to let the fallback call
304
- // `PartialEq::eq` on it.
305
- return Err ( FallbackToOpaqueConst ) ;
306
- }
307
271
ty:: FnDef ( ..) => {
308
272
let e = tcx. dcx ( ) . emit_err ( InvalidPattern { span, non_sm_ty : ty } ) ;
309
273
self . saw_const_match_error . set ( Some ( e) ) ;
@@ -377,38 +341,6 @@ impl<'tcx> ConstToPat<'tcx> {
377
341
ty:: Str => {
378
342
PatKind :: Constant { value : mir:: Const :: Ty ( ty:: Const :: new_value ( tcx, cv, ty) ) }
379
343
}
380
- // Backwards compatibility hack: support references to non-structural types,
381
- // but hard error if we aren't behind a double reference. We could just use
382
- // the fallback code path below, but that would allow *more* of this fishy
383
- // code to compile, as then it only goes through the future incompat lint
384
- // instead of a hard error.
385
- ty:: Adt ( _, _) if !self . type_marked_structural ( * pointee_ty) => {
386
- if self . behind_reference . get ( ) {
387
- if self . saw_const_match_error . get ( ) . is_none ( )
388
- && !self . saw_const_match_lint . get ( )
389
- {
390
- self . saw_const_match_lint . set ( true ) ;
391
- tcx. emit_node_span_lint (
392
- lint:: builtin:: INDIRECT_STRUCTURAL_MATCH ,
393
- self . id ,
394
- span,
395
- IndirectStructuralMatch { non_sm_ty : * pointee_ty } ,
396
- ) ;
397
- }
398
- return Err ( FallbackToOpaqueConst ) ;
399
- } else {
400
- if let Some ( e) = self . saw_const_match_error . get ( ) {
401
- // We already errored. Signal that in the pattern, so that follow up errors can be silenced.
402
- PatKind :: Error ( e)
403
- } else {
404
- let err = TypeNotStructural { span, non_sm_ty : * pointee_ty } ;
405
- let e = tcx. dcx ( ) . emit_err ( err) ;
406
- self . saw_const_match_error . set ( Some ( e) ) ;
407
- // We errored. Signal that in the pattern, so that follow up errors can be silenced.
408
- PatKind :: Error ( e)
409
- }
410
- }
411
- }
412
344
// All other references are converted into deref patterns and then recursively
413
345
// convert the dereferenced constant to a pattern that is the sub-pattern of the
414
346
// deref pattern.
@@ -419,7 +351,6 @@ impl<'tcx> ConstToPat<'tcx> {
419
351
// We errored. Signal that in the pattern, so that follow up errors can be silenced.
420
352
PatKind :: Error ( e)
421
353
} else {
422
- let old = self . behind_reference . replace ( true ) ;
423
354
// `b"foo"` produces a `&[u8; 3]`, but you can't use constants of array type when
424
355
// matching against references, you can only use byte string literals.
425
356
// The typechecker has a special case for byte string literals, by treating them
@@ -434,7 +365,6 @@ impl<'tcx> ConstToPat<'tcx> {
434
365
} ;
435
366
// References have the same valtree representation as their pointee.
436
367
let subpattern = self . recur ( cv, pointee_ty) ?;
437
- self . behind_reference . set ( old) ;
438
368
PatKind :: Deref { subpattern }
439
369
}
440
370
}
0 commit comments