@@ -19,6 +19,7 @@ use check::{check_expr, check_expr_has_type, check_expr_with_expectation};
19
19
use check:: { check_expr_coercable_to_type, demand, FnCtxt , Expectation } ;
20
20
use check:: { check_expr_with_lvalue_pref} ;
21
21
use check:: { instantiate_path, resolve_ty_and_def_ufcs, structurally_resolved_type} ;
22
+ use lint;
22
23
use require_same_types;
23
24
use util:: nodemap:: FnvHashMap ;
24
25
use session:: Session ;
@@ -138,7 +139,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
138
139
if pat_is_resolved_const ( & tcx. def_map . borrow ( ) , pat) => {
139
140
if let hir:: PatEnum ( ref path, ref subpats) = pat. node {
140
141
if !( subpats. is_some ( ) && subpats. as_ref ( ) . unwrap ( ) . is_empty ( ) ) {
141
- bad_struct_kind_err ( tcx. sess , pat. span , path, false ) ;
142
+ bad_struct_kind_err ( tcx. sess , pat, path, false ) ;
142
143
return ;
143
144
}
144
145
}
@@ -590,10 +591,21 @@ pub fn check_pat_struct<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, pat: &'tcx hir::Pat,
590
591
}
591
592
592
593
// This function exists due to the warning "diagnostic code E0164 already used"
593
- fn bad_struct_kind_err ( sess : & Session , span : Span , path : & hir:: Path , is_warning : bool ) {
594
+ fn bad_struct_kind_err ( sess : & Session , pat : & hir :: Pat , path : & hir:: Path , lint : bool ) {
594
595
let name = pprust:: path_to_string ( path) ;
595
- span_err_or_warn ! ( is_warning, sess, span, E0164 ,
596
- "`{}` does not name a tuple variant or a tuple struct" , name) ;
596
+ let msg = format ! ( "`{}` does not name a tuple variant or a tuple struct" , name) ;
597
+ if lint {
598
+ let expanded_msg =
599
+ format ! ( "{}; RFC 218 disallowed matching of unit variants or unit structs via {}(..)" ,
600
+ msg,
601
+ name) ;
602
+ sess. add_lint ( lint:: builtin:: MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT ,
603
+ pat. id ,
604
+ pat. span ,
605
+ expanded_msg) ;
606
+ } else {
607
+ span_err ! ( sess, pat. span, E0164 , "{}" , msg) ;
608
+ }
597
609
}
598
610
599
611
pub fn check_pat_enum < ' a , ' tcx > ( pcx : & pat_ctxt < ' a , ' tcx > ,
@@ -657,17 +669,8 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
657
669
opt_ty, def, pat. span , pat. id ) ;
658
670
659
671
let report_bad_struct_kind = |is_warning| {
660
- bad_struct_kind_err ( tcx. sess , pat. span , path, is_warning) ;
661
- if is_warning {
662
- // Boo! Too painful to attach this to the actual warning,
663
- // it should go away at some point though.
664
- tcx. sess . span_note_without_error (
665
- pat. span ,
666
- "this warning will become a HARD ERROR in a future release. \
667
- See RFC 218 for details.") ;
668
- return ;
669
- }
670
-
672
+ bad_struct_kind_err ( tcx. sess , pat, path, is_warning) ;
673
+ if is_warning { return ; }
671
674
fcx. write_error ( pat. id ) ;
672
675
if let Some ( subpats) = subpats {
673
676
for pat in subpats {
0 commit comments