@@ -45,7 +45,7 @@ pub use coercion::can_coerce;
45
45
use fn_ctxt:: FnCtxt ;
46
46
use rustc_data_structures:: unord:: UnordSet ;
47
47
use rustc_errors:: codes:: * ;
48
- use rustc_errors:: { struct_span_code_err, Applicability , ErrorGuaranteed } ;
48
+ use rustc_errors:: { pluralize , struct_span_code_err, Applicability , ErrorGuaranteed } ;
49
49
use rustc_hir as hir;
50
50
use rustc_hir:: def:: { DefKind , Res } ;
51
51
use rustc_hir:: intravisit:: Visitor ;
@@ -421,6 +421,36 @@ fn report_unexpected_variant_res(
421
421
err. multipart_suggestion_verbose ( descr, suggestion, Applicability :: MaybeIncorrect ) ;
422
422
err
423
423
}
424
+ Res :: Def ( DefKind :: Variant , _) if expr. is_none ( ) => {
425
+ let fields = & tcx. expect_variant_res ( res) . fields . raw ;
426
+
427
+ let span = qpath. span ( ) . shrink_to_hi ( ) . to ( span. shrink_to_hi ( ) ) ;
428
+ let ( msg, sugg) = if fields. is_empty ( ) {
429
+ ( "use the struct variant pattern syntax" . to_string ( ) , " {}" . to_string ( ) )
430
+ } else {
431
+ let msg = format ! (
432
+ "the struct variant's field{s} {are} being ignored" ,
433
+ s = pluralize!( fields. len( ) ) ,
434
+ are = pluralize!( "is" , fields. len( ) )
435
+ ) ;
436
+ let fields = fields
437
+ . iter ( )
438
+ . map ( |field| format ! ( "{}: _" , field. name. to_ident_string( ) ) )
439
+ . collect :: < Vec < _ > > ( )
440
+ . join ( ", " ) ;
441
+ let sugg = format ! ( " {{ /* {} */ }}" , fields, ) ;
442
+ ( msg, sugg)
443
+ } ;
444
+
445
+ err. span_label ( span, format ! ( "not a {expected}" ) ) ;
446
+ err. span_suggestion_verbose (
447
+ qpath. span ( ) . shrink_to_hi ( ) . to ( span. shrink_to_hi ( ) ) ,
448
+ msg,
449
+ sugg,
450
+ Applicability :: HasPlaceholders ,
451
+ ) ;
452
+ err
453
+ }
424
454
_ => err. with_span_label ( span, format ! ( "not a {expected}" ) ) ,
425
455
}
426
456
. emit ( )
0 commit comments