11use rustc_errors:: { Diag , EmissionGuarantee , SubdiagMessageOp , Subdiagnostic } ;
22use rustc_macros:: { LintDiagnostic , Subdiagnostic } ;
3- use rustc_middle:: thir:: Pat ;
43use rustc_middle:: ty:: Ty ;
54use rustc_span:: Span ;
65
76use crate :: rustc:: { RustcPatCtxt , WitnessPat } ;
87
98#[ derive( Subdiagnostic ) ]
109#[ label( pattern_analysis_uncovered) ]
11- pub struct Uncovered < ' tcx > {
10+ pub struct Uncovered {
1211 #[ primary_span]
1312 span : Span ,
1413 count : usize ,
15- witness_1 : Pat < ' tcx > ,
16- witness_2 : Pat < ' tcx > ,
17- witness_3 : Pat < ' tcx > ,
14+ witness_1 : String , // a printed pattern
15+ witness_2 : String , // a printed pattern
16+ witness_3 : String , // a printed pattern
1817 remainder : usize ,
1918}
2019
21- impl < ' tcx > Uncovered < ' tcx > {
22- pub fn new < ' p > (
20+ impl Uncovered {
21+ pub fn new < ' p , ' tcx > (
2322 span : Span ,
2423 cx : & RustcPatCtxt < ' p , ' tcx > ,
2524 witnesses : Vec < WitnessPat < ' p , ' tcx > > ,
2625 ) -> Self
2726 where
2827 ' tcx : ' p ,
2928 {
30- let witness_1 = cx. hoist_witness_pat ( witnesses. get ( 0 ) . unwrap ( ) ) ;
29+ let witness_1 = cx. hoist_witness_pat ( witnesses. get ( 0 ) . unwrap ( ) ) . to_string ( ) ;
3130 Self {
3231 span,
3332 count : witnesses. len ( ) ,
3433 // Substitute dummy values if witnesses is smaller than 3. These will never be read.
3534 witness_2 : witnesses
3635 . get ( 1 )
37- . map ( |w| cx. hoist_witness_pat ( w) )
38- . unwrap_or_else ( || witness_1 . clone ( ) ) ,
36+ . map ( |w| cx. hoist_witness_pat ( w) . to_string ( ) )
37+ . unwrap_or_default ( ) ,
3938 witness_3 : witnesses
4039 . get ( 2 )
41- . map ( |w| cx. hoist_witness_pat ( w) )
42- . unwrap_or_else ( || witness_1 . clone ( ) ) ,
40+ . map ( |w| cx. hoist_witness_pat ( w) . to_string ( ) )
41+ . unwrap_or_default ( ) ,
4342 witness_1,
4443 remainder : witnesses. len ( ) . saturating_sub ( 3 ) ,
4544 }
@@ -49,19 +48,19 @@ impl<'tcx> Uncovered<'tcx> {
4948#[ derive( LintDiagnostic ) ]
5049#[ diag( pattern_analysis_overlapping_range_endpoints) ]
5150#[ note]
52- pub struct OverlappingRangeEndpoints < ' tcx > {
51+ pub struct OverlappingRangeEndpoints {
5352 #[ label]
5453 pub range : Span ,
5554 #[ subdiagnostic]
56- pub overlap : Vec < Overlap < ' tcx > > ,
55+ pub overlap : Vec < Overlap > ,
5756}
5857
59- pub struct Overlap < ' tcx > {
58+ pub struct Overlap {
6059 pub span : Span ,
61- pub range : Pat < ' tcx > ,
60+ pub range : String , // a printed pattern
6261}
6362
64- impl < ' tcx > Subdiagnostic for Overlap < ' tcx > {
63+ impl Subdiagnostic for Overlap {
6564 fn add_to_diag_with < G : EmissionGuarantee , F : SubdiagMessageOp < G > > (
6665 self ,
6766 diag : & mut Diag < ' _ , G > ,
@@ -78,38 +77,38 @@ impl<'tcx> Subdiagnostic for Overlap<'tcx> {
7877
7978#[ derive( LintDiagnostic ) ]
8079#[ diag( pattern_analysis_excluside_range_missing_max) ]
81- pub struct ExclusiveRangeMissingMax < ' tcx > {
80+ pub struct ExclusiveRangeMissingMax {
8281 #[ label]
8382 #[ suggestion( code = "{suggestion}" , applicability = "maybe-incorrect" ) ]
8483 /// This is an exclusive range that looks like `lo..max` (i.e. doesn't match `max`).
8584 pub first_range : Span ,
8685 /// Suggest `lo..=max` instead.
8786 pub suggestion : String ,
88- pub max : Pat < ' tcx > ,
87+ pub max : String , // a printed pattern
8988}
9089
9190#[ derive( LintDiagnostic ) ]
9291#[ diag( pattern_analysis_excluside_range_missing_gap) ]
93- pub struct ExclusiveRangeMissingGap < ' tcx > {
92+ pub struct ExclusiveRangeMissingGap {
9493 #[ label]
9594 #[ suggestion( code = "{suggestion}" , applicability = "maybe-incorrect" ) ]
9695 /// This is an exclusive range that looks like `lo..gap` (i.e. doesn't match `gap`).
9796 pub first_range : Span ,
98- pub gap : Pat < ' tcx > ,
97+ pub gap : String , // a printed pattern
9998 /// Suggest `lo..=gap` instead.
10099 pub suggestion : String ,
101100 #[ subdiagnostic]
102101 /// All these ranges skipped over `gap` which we think is probably a mistake.
103- pub gap_with : Vec < GappedRange < ' tcx > > ,
102+ pub gap_with : Vec < GappedRange > ,
104103}
105104
106- pub struct GappedRange < ' tcx > {
105+ pub struct GappedRange {
107106 pub span : Span ,
108- pub gap : Pat < ' tcx > ,
109- pub first_range : Pat < ' tcx > ,
107+ pub gap : String , // a printed pattern
108+ pub first_range : String , // a printed pattern
110109}
111110
112- impl < ' tcx > Subdiagnostic for GappedRange < ' tcx > {
111+ impl Subdiagnostic for GappedRange {
113112 fn add_to_diag_with < G : EmissionGuarantee , F : SubdiagMessageOp < G > > (
114113 self ,
115114 diag : & mut Diag < ' _ , G > ,
@@ -134,7 +133,7 @@ impl<'tcx> Subdiagnostic for GappedRange<'tcx> {
134133pub ( crate ) struct NonExhaustiveOmittedPattern < ' tcx > {
135134 pub scrut_ty : Ty < ' tcx > ,
136135 #[ subdiagnostic]
137- pub uncovered : Uncovered < ' tcx > ,
136+ pub uncovered : Uncovered ,
138137}
139138
140139#[ derive( LintDiagnostic ) ]
0 commit comments