1
1
use rustc_errors:: { Diag , EmissionGuarantee , SubdiagMessageOp , Subdiagnostic } ;
2
2
use rustc_macros:: { LintDiagnostic , Subdiagnostic } ;
3
- use rustc_middle:: thir:: Pat ;
4
3
use rustc_middle:: ty:: Ty ;
5
4
use rustc_span:: Span ;
6
5
7
6
use crate :: rustc:: { RustcPatCtxt , WitnessPat } ;
8
7
9
8
#[ derive( Subdiagnostic ) ]
10
9
#[ label( pattern_analysis_uncovered) ]
11
- pub struct Uncovered < ' tcx > {
10
+ pub struct Uncovered {
12
11
#[ primary_span]
13
12
span : Span ,
14
13
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
18
17
remainder : usize ,
19
18
}
20
19
21
- impl < ' tcx > Uncovered < ' tcx > {
22
- pub fn new < ' p > (
20
+ impl Uncovered {
21
+ pub fn new < ' p , ' tcx > (
23
22
span : Span ,
24
23
cx : & RustcPatCtxt < ' p , ' tcx > ,
25
24
witnesses : Vec < WitnessPat < ' p , ' tcx > > ,
26
25
) -> Self
27
26
where
28
27
' tcx : ' p ,
29
28
{
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 ( ) ;
31
30
Self {
32
31
span,
33
32
count : witnesses. len ( ) ,
34
33
// Substitute dummy values if witnesses is smaller than 3. These will never be read.
35
34
witness_2 : witnesses
36
35
. 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 ( ) ,
39
38
witness_3 : witnesses
40
39
. 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 ( ) ,
43
42
witness_1,
44
43
remainder : witnesses. len ( ) . saturating_sub ( 3 ) ,
45
44
}
@@ -49,19 +48,19 @@ impl<'tcx> Uncovered<'tcx> {
49
48
#[ derive( LintDiagnostic ) ]
50
49
#[ diag( pattern_analysis_overlapping_range_endpoints) ]
51
50
#[ note]
52
- pub struct OverlappingRangeEndpoints < ' tcx > {
51
+ pub struct OverlappingRangeEndpoints {
53
52
#[ label]
54
53
pub range : Span ,
55
54
#[ subdiagnostic]
56
- pub overlap : Vec < Overlap < ' tcx > > ,
55
+ pub overlap : Vec < Overlap > ,
57
56
}
58
57
59
- pub struct Overlap < ' tcx > {
58
+ pub struct Overlap {
60
59
pub span : Span ,
61
- pub range : Pat < ' tcx > ,
60
+ pub range : String , // a printed pattern
62
61
}
63
62
64
- impl < ' tcx > Subdiagnostic for Overlap < ' tcx > {
63
+ impl Subdiagnostic for Overlap {
65
64
fn add_to_diag_with < G : EmissionGuarantee , F : SubdiagMessageOp < G > > (
66
65
self ,
67
66
diag : & mut Diag < ' _ , G > ,
@@ -78,38 +77,38 @@ impl<'tcx> Subdiagnostic for Overlap<'tcx> {
78
77
79
78
#[ derive( LintDiagnostic ) ]
80
79
#[ diag( pattern_analysis_excluside_range_missing_max) ]
81
- pub struct ExclusiveRangeMissingMax < ' tcx > {
80
+ pub struct ExclusiveRangeMissingMax {
82
81
#[ label]
83
82
#[ suggestion( code = "{suggestion}" , applicability = "maybe-incorrect" ) ]
84
83
/// This is an exclusive range that looks like `lo..max` (i.e. doesn't match `max`).
85
84
pub first_range : Span ,
86
85
/// Suggest `lo..=max` instead.
87
86
pub suggestion : String ,
88
- pub max : Pat < ' tcx > ,
87
+ pub max : String , // a printed pattern
89
88
}
90
89
91
90
#[ derive( LintDiagnostic ) ]
92
91
#[ diag( pattern_analysis_excluside_range_missing_gap) ]
93
- pub struct ExclusiveRangeMissingGap < ' tcx > {
92
+ pub struct ExclusiveRangeMissingGap {
94
93
#[ label]
95
94
#[ suggestion( code = "{suggestion}" , applicability = "maybe-incorrect" ) ]
96
95
/// This is an exclusive range that looks like `lo..gap` (i.e. doesn't match `gap`).
97
96
pub first_range : Span ,
98
- pub gap : Pat < ' tcx > ,
97
+ pub gap : String , // a printed pattern
99
98
/// Suggest `lo..=gap` instead.
100
99
pub suggestion : String ,
101
100
#[ subdiagnostic]
102
101
/// 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 > ,
104
103
}
105
104
106
- pub struct GappedRange < ' tcx > {
105
+ pub struct GappedRange {
107
106
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
110
109
}
111
110
112
- impl < ' tcx > Subdiagnostic for GappedRange < ' tcx > {
111
+ impl Subdiagnostic for GappedRange {
113
112
fn add_to_diag_with < G : EmissionGuarantee , F : SubdiagMessageOp < G > > (
114
113
self ,
115
114
diag : & mut Diag < ' _ , G > ,
@@ -134,7 +133,7 @@ impl<'tcx> Subdiagnostic for GappedRange<'tcx> {
134
133
pub ( crate ) struct NonExhaustiveOmittedPattern < ' tcx > {
135
134
pub scrut_ty : Ty < ' tcx > ,
136
135
#[ subdiagnostic]
137
- pub uncovered : Uncovered < ' tcx > ,
136
+ pub uncovered : Uncovered ,
138
137
}
139
138
140
139
#[ derive( LintDiagnostic ) ]
0 commit comments