@@ -409,25 +409,43 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
409
409
// reference. This makes the rest of the matching logic simpler as it doesn't have
410
410
// to figure out how to get a reference again.
411
411
ty:: Adt ( adt_def, _) if !self . type_marked_structural ( pointee_ty) => {
412
- if self . include_lint_checks
413
- && !self . saw_const_match_error . get ( )
414
- && !self . saw_const_match_lint . get ( )
415
- {
416
- self . saw_const_match_lint . set ( true ) ;
417
- let path = self . tcx ( ) . def_path_str ( adt_def. did ) ;
418
- let msg = format ! (
419
- "to use a constant of type `{}` in a pattern, \
420
- `{}` must be annotated with `#[derive(PartialEq, Eq)]`",
421
- path, path,
422
- ) ;
423
- self . tcx ( ) . struct_span_lint_hir (
424
- lint:: builtin:: INDIRECT_STRUCTURAL_MATCH ,
425
- self . id ,
426
- self . span ,
427
- |lint| lint. build ( & msg) . emit ( ) ,
428
- ) ;
412
+ if self . behind_reference . get ( ) {
413
+ if self . include_lint_checks
414
+ && !self . saw_const_match_error . get ( )
415
+ && !self . saw_const_match_lint . get ( )
416
+ {
417
+ self . saw_const_match_lint . set ( true ) ;
418
+ let path = self . tcx ( ) . def_path_str ( adt_def. did ) ;
419
+ let msg = format ! (
420
+ "to use a constant of type `{}` in a pattern, \
421
+ `{}` must be annotated with `#[derive(PartialEq, Eq)]`",
422
+ path, path,
423
+ ) ;
424
+ self . tcx ( ) . struct_span_lint_hir (
425
+ lint:: builtin:: INDIRECT_STRUCTURAL_MATCH ,
426
+ self . id ,
427
+ self . span ,
428
+ |lint| lint. build ( & msg) . emit ( ) ,
429
+ ) ;
430
+ }
431
+ PatKind :: Constant { value : cv }
432
+ } else {
433
+ if !self . saw_const_match_error . get ( ) {
434
+ self . saw_const_match_error . set ( true ) ;
435
+ let path = self . tcx ( ) . def_path_str ( adt_def. did ) ;
436
+ let msg = format ! (
437
+ "to use a constant of type `{}` in a pattern, \
438
+ `{}` must be annotated with `#[derive(PartialEq, Eq)]`",
439
+ path, path,
440
+ ) ;
441
+ if self . include_lint_checks {
442
+ tcx. sess . span_err ( span, & msg) ;
443
+ } else {
444
+ tcx. sess . delay_span_bug ( span, & msg)
445
+ }
446
+ }
447
+ PatKind :: Wild
429
448
}
430
- PatKind :: Constant { value : cv }
431
449
}
432
450
// All other references are converted into deref patterns and then recursively
433
451
// convert the dereferenced constant to a pattern that is the sub-pattern of the
0 commit comments