@@ -59,8 +59,6 @@ struct ConstToPat<'tcx> {
59
59
// inference context used for checking `T: Structural` bounds.
60
60
infcx : InferCtxt < ' tcx > ,
61
61
62
- include_lint_checks : bool ,
63
-
64
62
treat_byte_string_as_slice : bool ,
65
63
}
66
64
@@ -93,7 +91,6 @@ impl<'tcx> ConstToPat<'tcx> {
93
91
span,
94
92
infcx,
95
93
param_env : pat_ctxt. param_env ,
96
- include_lint_checks : pat_ctxt. include_lint_checks ,
97
94
saw_const_match_error : Cell :: new ( false ) ,
98
95
saw_const_match_lint : Cell :: new ( false ) ,
99
96
behind_reference : Cell :: new ( false ) ,
@@ -134,7 +131,7 @@ impl<'tcx> ConstToPat<'tcx> {
134
131
} )
135
132
} ) ;
136
133
137
- if self . include_lint_checks && !self . saw_const_match_error . get ( ) {
134
+ if !self . saw_const_match_error . get ( ) {
138
135
// If we were able to successfully convert the const to some pat,
139
136
// double-check that all types in the const implement `Structural`.
140
137
@@ -239,21 +236,19 @@ impl<'tcx> ConstToPat<'tcx> {
239
236
240
237
let kind = match cv. ty ( ) . kind ( ) {
241
238
ty:: Float ( _) => {
242
- if self . include_lint_checks {
243
239
tcx. emit_spanned_lint (
244
240
lint:: builtin:: ILLEGAL_FLOATING_POINT_LITERAL_PATTERN ,
245
241
id,
246
242
span,
247
243
FloatPattern ,
248
244
) ;
249
- }
250
245
PatKind :: Constant { value : cv }
251
246
}
252
247
ty:: Adt ( adt_def, _) if adt_def. is_union ( ) => {
253
248
// Matching on union fields is unsafe, we can't hide it in constants
254
249
self . saw_const_match_error . set ( true ) ;
255
250
let err = UnionPattern { span } ;
256
- tcx. sess . create_err ( err) . emit_unless ( ! self . include_lint_checks ) ;
251
+ tcx. sess . emit_err ( err) ;
257
252
PatKind :: Wild
258
253
}
259
254
ty:: Adt ( ..)
@@ -267,7 +262,7 @@ impl<'tcx> ConstToPat<'tcx> {
267
262
{
268
263
self . saw_const_match_error . set ( true ) ;
269
264
let err = TypeNotStructural { span, non_sm_ty } ;
270
- tcx. sess . create_err ( err) . emit_unless ( ! self . include_lint_checks ) ;
265
+ tcx. sess . emit_err ( err) ;
271
266
PatKind :: Wild
272
267
}
273
268
// If the type is not structurally comparable, just emit the constant directly,
@@ -280,8 +275,7 @@ impl<'tcx> ConstToPat<'tcx> {
280
275
// Backwards compatibility hack because we can't cause hard errors on these
281
276
// types, so we compare them via `PartialEq::eq` at runtime.
282
277
ty:: Adt ( ..) if !self . type_marked_structural ( cv. ty ( ) ) && self . behind_reference . get ( ) => {
283
- if self . include_lint_checks
284
- && !self . saw_const_match_error . get ( )
278
+ if !self . saw_const_match_error . get ( )
285
279
&& !self . saw_const_match_lint . get ( )
286
280
{
287
281
self . saw_const_match_lint . set ( true ) ;
@@ -305,7 +299,7 @@ impl<'tcx> ConstToPat<'tcx> {
305
299
) ;
306
300
self . saw_const_match_error . set ( true ) ;
307
301
let err = TypeNotStructural { span, non_sm_ty : cv. ty ( ) } ;
308
- tcx. sess . create_err ( err) . emit_unless ( ! self . include_lint_checks ) ;
302
+ tcx. sess . emit_err ( err) ;
309
303
PatKind :: Wild
310
304
}
311
305
ty:: Adt ( adt_def, substs) if adt_def. is_enum ( ) => {
@@ -339,7 +333,7 @@ impl<'tcx> ConstToPat<'tcx> {
339
333
ty:: Dynamic ( ..) => {
340
334
self . saw_const_match_error . set ( true ) ;
341
335
let err = InvalidPattern { span, non_sm_ty : cv. ty ( ) } ;
342
- tcx. sess . create_err ( err) . emit_unless ( ! self . include_lint_checks ) ;
336
+ tcx. sess . emit_err ( err) ;
343
337
PatKind :: Wild
344
338
}
345
339
// `&str` is represented as `ConstValue::Slice`, let's keep using this
@@ -406,8 +400,7 @@ impl<'tcx> ConstToPat<'tcx> {
406
400
// to figure out how to get a reference again.
407
401
ty:: Adt ( _, _) if !self . type_marked_structural ( * pointee_ty) => {
408
402
if self . behind_reference . get ( ) {
409
- if self . include_lint_checks
410
- && !self . saw_const_match_error . get ( )
403
+ if !self . saw_const_match_error . get ( )
411
404
&& !self . saw_const_match_lint . get ( )
412
405
{
413
406
self . saw_const_match_lint . set ( true ) ;
@@ -423,7 +416,7 @@ impl<'tcx> ConstToPat<'tcx> {
423
416
if !self . saw_const_match_error . get ( ) {
424
417
self . saw_const_match_error . set ( true ) ;
425
418
let err = TypeNotStructural { span, non_sm_ty : * pointee_ty } ;
426
- tcx. sess . create_err ( err) . emit_unless ( ! self . include_lint_checks ) ;
419
+ tcx. sess . emit_err ( err) ;
427
420
}
428
421
PatKind :: Wild
429
422
}
@@ -437,7 +430,7 @@ impl<'tcx> ConstToPat<'tcx> {
437
430
// (except slices, which are handled in a separate arm above).
438
431
439
432
let err = UnsizedPattern { span, non_sm_ty : * pointee_ty } ;
440
- tcx. sess . create_err ( err) . emit_unless ( ! self . include_lint_checks ) ;
433
+ tcx. sess . emit_err ( err) ;
441
434
442
435
PatKind :: Wild
443
436
} else {
@@ -465,8 +458,7 @@ impl<'tcx> ConstToPat<'tcx> {
465
458
// compilation choices change the runtime behaviour of the match.
466
459
// See https://github.com/rust-lang/rust/issues/70861 for examples.
467
460
ty:: FnPtr ( ..) | ty:: RawPtr ( ..) => {
468
- if self . include_lint_checks
469
- && !self . saw_const_match_error . get ( )
461
+ if !self . saw_const_match_error . get ( )
470
462
&& !self . saw_const_match_lint . get ( )
471
463
{
472
464
self . saw_const_match_lint . set ( true ) ;
@@ -482,13 +474,12 @@ impl<'tcx> ConstToPat<'tcx> {
482
474
_ => {
483
475
self . saw_const_match_error . set ( true ) ;
484
476
let err = InvalidPattern { span, non_sm_ty : cv. ty ( ) } ;
485
- tcx. sess . create_err ( err) . emit_unless ( ! self . include_lint_checks ) ;
477
+ tcx. sess . emit_err ( err) ;
486
478
PatKind :: Wild
487
479
}
488
480
} ;
489
481
490
- if self . include_lint_checks
491
- && !self . saw_const_match_error . get ( )
482
+ if !self . saw_const_match_error . get ( )
492
483
&& !self . saw_const_match_lint . get ( )
493
484
&& mir_structural_match_violation
494
485
// FIXME(#73448): Find a way to bring const qualification into parity with
0 commit comments