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