@@ -150,14 +150,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
150
150
self . write_ty ( pat. id , typ) ;
151
151
}
152
152
PatKind :: TupleStruct ( ref path, ref subpats, ddpos) => {
153
- self . check_pat_tuple_struct ( pat, path, & subpats, ddpos, expected) ;
153
+ let pat_ty = self . check_pat_tuple_struct ( pat, path, & subpats, ddpos, expected) ;
154
+ write_ty ( pat. id , pat_ty) ;
154
155
}
155
156
PatKind :: Path ( ref opt_qself, ref path) => {
156
157
let opt_qself_ty = opt_qself. as_ref ( ) . map ( |qself| self . to_ty ( & qself. ty ) ) ;
157
- self . check_pat_path ( pat, opt_qself_ty, path, expected) ;
158
+ let pat_ty = self . check_pat_path ( pat, opt_qself_ty, path, expected) ;
159
+ write_ty ( pat. id , pat_ty) ;
158
160
}
159
161
PatKind :: Struct ( ref path, ref fields, etc) => {
160
- self . check_pat_struct ( pat, path, fields, etc, expected) ;
162
+ let pat_ty = self . check_pat_struct ( pat, path, fields, etc, expected) ;
163
+ write_ty ( pat. id , pat_ty) ;
161
164
}
162
165
PatKind :: Tuple ( ref elements, ddpos) => {
163
166
let mut expected_len = elements. len ( ) ;
@@ -481,40 +484,38 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
481
484
path : & hir:: Path ,
482
485
fields : & ' gcx [ Spanned < hir:: FieldPat > ] ,
483
486
etc : bool ,
484
- expected : Ty < ' tcx > )
487
+ expected : Ty < ' tcx > ) -> Ty < ' tcx >
485
488
{
486
489
// Resolve the path and check the definition for errors.
487
490
let ( variant, pat_ty) = if let Some ( variant_ty) = self . check_struct_path ( path, pat. id ,
488
491
pat. span ) {
489
492
variant_ty
490
493
} else {
491
- self . write_error ( pat. id ) ;
492
494
for field in fields {
493
495
self . check_pat ( & field. node . pat , self . tcx . types . err ) ;
494
496
}
495
- return ;
497
+ return tcx . types . err ;
496
498
} ;
497
- self . write_ty ( pat. id , pat_ty) ;
498
499
499
500
// Type check the path.
500
501
self . demand_eqtype ( pat. span , expected, pat_ty) ;
501
502
502
503
// Type check subpatterns.
503
504
self . check_struct_pat_fields ( pat_ty, pat. span , variant, fields, etc) ;
505
+ pat_ty
504
506
}
505
507
506
508
fn check_pat_path ( & self ,
507
509
pat : & hir:: Pat ,
508
510
opt_self_ty : Option < Ty < ' tcx > > ,
509
511
path : & hir:: Path ,
510
- expected : Ty < ' tcx > )
512
+ expected : Ty < ' tcx > ) -> Ty < ' tcx >
511
513
{
512
514
let tcx = self . tcx ;
513
515
let report_unexpected_def = || {
514
516
span_err ! ( tcx. sess, pat. span, E0533 ,
515
517
"`{}` does not name a unit variant, unit struct or a constant" ,
516
518
pprust:: path_to_string( path) ) ;
517
- self . write_error ( pat. id ) ;
518
519
} ;
519
520
520
521
// Resolve the path and check the definition for errors.
@@ -523,18 +524,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
523
524
match def {
524
525
Def :: Err => {
525
526
self . set_tainted_by_errors ( ) ;
526
- self . write_error ( pat. id ) ;
527
- return ;
527
+ return tcx. types . err ;
528
528
}
529
529
Def :: Method ( ..) => {
530
530
report_unexpected_def ( ) ;
531
- return ;
531
+ return tcx . types . err ;
532
532
}
533
533
Def :: Variant ( ..) | Def :: Struct ( ..) => {
534
534
let variant = tcx. expect_variant_def ( def) ;
535
535
if variant. kind != VariantKind :: Unit {
536
536
report_unexpected_def ( ) ;
537
- return ;
537
+ return tcx . types . err ;
538
538
}
539
539
}
540
540
Def :: Const ( ..) | Def :: AssociatedConst ( ..) => { } // OK
@@ -543,20 +543,19 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
543
543
544
544
// Type check the path.
545
545
let pat_ty = self . instantiate_value_path ( segments, opt_ty, def, pat. span , pat. id ) ;
546
- self . write_ty ( pat. id , pat_ty) ;
547
546
self . demand_suptype ( pat. span , expected, pat_ty) ;
547
+ pat_ty
548
548
}
549
549
550
550
fn check_pat_tuple_struct ( & self ,
551
551
pat : & hir:: Pat ,
552
552
path : & hir:: Path ,
553
553
subpats : & ' gcx [ P < hir:: Pat > ] ,
554
554
ddpos : Option < usize > ,
555
- expected : Ty < ' tcx > )
555
+ expected : Ty < ' tcx > ) -> Ty < ' tcx >
556
556
{
557
557
let tcx = self . tcx ;
558
558
let on_error = || {
559
- self . write_error ( pat. id ) ;
560
559
for pat in subpats {
561
560
self . check_pat ( & pat, tcx. types . err ) ;
562
561
}
@@ -580,11 +579,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
580
579
Def :: Err => {
581
580
self . set_tainted_by_errors ( ) ;
582
581
on_error ( ) ;
583
- return ;
582
+ return tcx . types . err ;
584
583
}
585
584
Def :: Const ( ..) | Def :: AssociatedConst ( ..) | Def :: Method ( ..) => {
586
585
report_unexpected_def ( false ) ;
587
- return ;
586
+ return tcx . types . err ;
588
587
}
589
588
Def :: Variant ( ..) | Def :: Struct ( ..) => {
590
589
tcx. expect_variant_def ( def)
@@ -597,21 +596,18 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
597
596
report_unexpected_def ( true ) ;
598
597
} else if variant. kind != VariantKind :: Tuple {
599
598
report_unexpected_def ( false ) ;
600
- return ;
599
+ return tcx . types . err ;
601
600
}
602
601
603
602
// Type check the path.
604
603
let pat_ty = self . instantiate_value_path ( segments, opt_ty, def, pat. span , pat. id ) ;
605
- self . write_ty ( pat. id , pat_ty) ;
606
-
607
604
let pat_ty = if pat_ty. is_fn ( ) {
608
605
// Replace constructor type with constructed type for tuple struct patterns.
609
606
tcx. no_late_bound_regions ( & pat_ty. fn_ret ( ) ) . unwrap ( )
610
607
} else {
611
608
// Leave the type as is for unit structs (backward compatibility).
612
609
pat_ty
613
610
} ;
614
- self . write_ty ( pat. id , pat_ty) ;
615
611
self . demand_eqtype ( pat. span , expected, pat_ty) ;
616
612
617
613
// Type check subpatterns.
@@ -644,7 +640,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
644
640
variant. fields. len( ) , fields_ending, subpats. len( ) ) )
645
641
. emit ( ) ;
646
642
on_error ( ) ;
643
+ return tcx. types . err ;
647
644
}
645
+ pat_ty
648
646
}
649
647
650
648
fn check_struct_pat_fields ( & self ,
0 commit comments