@@ -72,22 +72,6 @@ struct TopInfo<'tcx> {
72
72
/// found type `std::result::Result<_, _>`
73
73
/// ```
74
74
span : Option < Span > ,
75
- /// This refers to the parent pattern. Used to provide extra diagnostic information on errors.
76
- /// ```text
77
- /// error[E0308]: mismatched types
78
- /// --> $DIR/const-in-struct-pat.rs:8:17
79
- /// |
80
- /// L | struct f;
81
- /// | --------- unit struct defined here
82
- /// ...
83
- /// L | let Thing { f } = t;
84
- /// | ^
85
- /// | |
86
- /// | expected struct `std::string::String`, found struct `f`
87
- /// | `f` is interpreted as a unit struct, not a new binding
88
- /// | help: bind the struct field to a different name instead: `f: other_f`
89
- /// ```
90
- parent_pat : Option < & ' tcx Pat < ' tcx > > ,
91
75
}
92
76
93
77
impl < ' tcx > FnCtxt < ' _ , ' tcx > {
@@ -147,7 +131,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
147
131
span : Option < Span > ,
148
132
origin_expr : bool ,
149
133
) {
150
- let info = TopInfo { expected, origin_expr, span, parent_pat : None } ;
134
+ let info = TopInfo { expected, origin_expr, span } ;
151
135
self . check_pat ( pat, expected, INITIAL_BM , info) ;
152
136
}
153
137
@@ -190,9 +174,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
190
174
self . check_pat_struct ( pat, qpath, fields, has_rest_pat, expected, def_bm, ti)
191
175
}
192
176
PatKind :: Or ( pats) => {
193
- let parent_pat = Some ( pat) ;
194
177
for pat in pats {
195
- self . check_pat ( pat, expected, def_bm, TopInfo { parent_pat , ..ti } ) ;
178
+ self . check_pat ( pat, expected, def_bm, ti ) ;
196
179
}
197
180
expected
198
181
}
@@ -621,7 +604,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
621
604
}
622
605
623
606
if let Some ( p) = sub {
624
- self . check_pat ( p, expected, def_bm, TopInfo { parent_pat : Some ( pat ) , ..ti } ) ;
607
+ self . check_pat ( p, expected, def_bm, ti ) ;
625
608
}
626
609
627
610
local_ty
@@ -782,7 +765,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
782
765
let Some ( ( variant, pat_ty) ) = self . check_struct_path ( qpath, pat. hir_id ) else {
783
766
let err = self . tcx . ty_error ( ) ;
784
767
for field in fields {
785
- let ti = TopInfo { parent_pat : Some ( pat ) , ..ti } ;
768
+ let ti = ti ;
786
769
self . check_pat ( field. pat , err, def_bm, ti) ;
787
770
}
788
771
return err;
@@ -799,11 +782,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
799
782
}
800
783
}
801
784
802
- fn check_pat_path < ' b > (
785
+ fn check_pat_path (
803
786
& self ,
804
- pat : & Pat < ' _ > ,
787
+ pat : & Pat < ' tcx > ,
805
788
qpath : & hir:: QPath < ' _ > ,
806
- path_resolution : ( Res , Option < Ty < ' tcx > > , & ' b [ hir:: PathSegment < ' b > ] ) ,
789
+ path_resolution : ( Res , Option < Ty < ' tcx > > , & ' tcx [ hir:: PathSegment < ' tcx > ] ) ,
807
790
expected : Ty < ' tcx > ,
808
791
ti : TopInfo < ' tcx > ,
809
792
) -> Ty < ' tcx > {
@@ -837,7 +820,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
837
820
if let Some ( err) =
838
821
self . demand_suptype_with_origin ( & self . pattern_cause ( ti, pat. span ) , expected, pat_ty)
839
822
{
840
- self . emit_bad_pat_path ( err, pat. span , res, pat_res, pat_ty, segments, ti . parent_pat ) ;
823
+ self . emit_bad_pat_path ( err, pat, res, pat_res, pat_ty, segments) ;
841
824
}
842
825
pat_ty
843
826
}
@@ -876,16 +859,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
876
859
false
877
860
}
878
861
879
- fn emit_bad_pat_path < ' b > (
862
+ fn emit_bad_pat_path (
880
863
& self ,
881
864
mut e : DiagnosticBuilder < ' _ , ErrorGuaranteed > ,
882
- pat_span : Span ,
865
+ pat : & hir :: Pat < ' tcx > ,
883
866
res : Res ,
884
867
pat_res : Res ,
885
868
pat_ty : Ty < ' tcx > ,
886
- segments : & ' b [ hir:: PathSegment < ' b > ] ,
887
- parent_pat : Option < & Pat < ' _ > > ,
869
+ segments : & ' tcx [ hir:: PathSegment < ' tcx > ] ,
888
870
) {
871
+ let pat_span = pat. span ;
889
872
if let Some ( span) = self . tcx . hir ( ) . res_span ( pat_res) {
890
873
e. span_label ( span, & format ! ( "{} defined here" , res. descr( ) ) ) ;
891
874
if let [ hir:: PathSegment { ident, .. } ] = & * segments {
@@ -898,8 +881,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
898
881
res. descr( ) ,
899
882
) ,
900
883
) ;
901
- match parent_pat {
902
- Some ( Pat { kind : hir:: PatKind :: Struct ( ..) , .. } ) => {
884
+ match self . tcx . hir ( ) . get ( self . tcx . hir ( ) . get_parent_node ( pat . hir_id ) ) {
885
+ hir :: Node :: Pat ( Pat { kind : hir:: PatKind :: Struct ( ..) , .. } ) => {
903
886
e. span_suggestion_verbose (
904
887
ident. span . shrink_to_hi ( ) ,
905
888
"bind the struct field to a different name instead" ,
@@ -960,9 +943,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
960
943
) -> Ty < ' tcx > {
961
944
let tcx = self . tcx ;
962
945
let on_error = || {
963
- let parent_pat = Some ( pat) ;
964
946
for pat in subpats {
965
- self . check_pat ( pat, tcx. ty_error ( ) , def_bm, TopInfo { parent_pat , ..ti } ) ;
947
+ self . check_pat ( pat, tcx. ty_error ( ) , def_bm, ti ) ;
966
948
}
967
949
} ;
968
950
let report_unexpected_res = |res : Res | {
@@ -1046,7 +1028,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1046
1028
} ;
1047
1029
for ( i, subpat) in subpats. iter ( ) . enumerate_and_adjust ( variant. fields . len ( ) , ddpos) {
1048
1030
let field_ty = self . field_ty ( subpat. span , & variant. fields [ i] , substs) ;
1049
- self . check_pat ( subpat, field_ty, def_bm, TopInfo { parent_pat : Some ( pat ) , ..ti } ) ;
1031
+ self . check_pat ( subpat, field_ty, def_bm, ti ) ;
1050
1032
1051
1033
self . tcx . check_stability (
1052
1034
variant. fields [ i] . did ,
@@ -1324,7 +1306,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1324
1306
}
1325
1307
} ;
1326
1308
1327
- self . check_pat ( field. pat , field_ty, def_bm, TopInfo { parent_pat : Some ( pat ) , ..ti } ) ;
1309
+ self . check_pat ( field. pat , field_ty, def_bm, ti ) ;
1328
1310
}
1329
1311
1330
1312
let mut unmentioned_fields = variant
@@ -1936,7 +1918,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1936
1918
let err = tcx. ty_error ( ) ;
1937
1919
( err, err)
1938
1920
} ;
1939
- self . check_pat ( inner, inner_ty, def_bm, TopInfo { parent_pat : Some ( pat ) , ..ti } ) ;
1921
+ self . check_pat ( inner, inner_ty, def_bm, ti ) ;
1940
1922
rptr_ty
1941
1923
}
1942
1924
0 commit comments