@@ -53,7 +53,7 @@ declare_lint_pass!(TestWithoutFailCase => [TEST_WITHOUT_FAIL_CASE]);
53
53
54
54
impl < ' tcx > LateLintPass < ' tcx > for TestWithoutFailCase {
55
55
fn check_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx Item < ' tcx > ) {
56
- // Only interested in functions that are test functions
56
+ // Only interested in functions that are annotated with `#[test]`.
57
57
if let ItemKind :: Fn ( _, _, body_id) = item. kind
58
58
&& is_in_test_function ( cx. tcx , item. hir_id ( ) )
59
59
{
@@ -80,8 +80,6 @@ impl<'tcx> LateLintPass<'tcx> for TestWithoutFailCase {
80
80
struct SearchPanicIntraFunction < ' a , ' tcx > {
81
81
/// The lint context
82
82
cx : & ' a LateContext < ' tcx > ,
83
- /// Whether we are inside a constant context
84
- is_const : bool ,
85
83
/// The span where a panic was found
86
84
panic_span : Option < Span > ,
87
85
/// Type checking results for the current body
@@ -95,7 +93,6 @@ impl<'a, 'tcx> SearchPanicIntraFunction<'a, 'tcx> {
95
93
pub fn new ( cx : & ' a LateContext < ' tcx > , typeck_results : & ' tcx ty:: TypeckResults < ' tcx > ) -> Self {
96
94
Self {
97
95
cx,
98
- is_const : false ,
99
96
panic_span : None ,
100
97
typeck_results,
101
98
visited_functions : FxHashSet :: default ( ) ,
@@ -107,10 +104,10 @@ impl<'a, 'tcx> SearchPanicIntraFunction<'a, 'tcx> {
107
104
cx : & ' a LateContext < ' tcx > ,
108
105
typeck_results : & ' tcx ty:: TypeckResults < ' tcx > ,
109
106
body : impl Visitable < ' tcx > ,
110
- ) -> Option < ( Span , bool ) > {
107
+ ) -> Option < Span > {
111
108
let mut visitor = Self :: new ( cx, typeck_results) ;
112
109
body. visit ( & mut visitor) ;
113
- visitor. panic_span . map ( |span| ( span , visitor . is_const ) )
110
+ visitor. panic_span
114
111
}
115
112
116
113
/// Checks the called function to see if it contains a panic
@@ -127,7 +124,6 @@ impl<'a, 'tcx> SearchPanicIntraFunction<'a, 'tcx> {
127
124
let typeck_results = self . cx . tcx . typeck ( local_def_id) ;
128
125
let mut new_visitor = SearchPanicIntraFunction {
129
126
cx : self . cx ,
130
- is_const : false ,
131
127
panic_span : None ,
132
128
typeck_results,
133
129
visited_functions : self . visited_functions . clone ( ) ,
@@ -156,7 +152,6 @@ impl<'tcx> Visitor<'tcx> for SearchPanicIntraFunction<'_, 'tcx> {
156
152
157
153
match expr. kind {
158
154
ExprKind :: Call ( callee, args) => {
159
- // Function call
160
155
if let ExprKind :: Path ( ref qpath) = callee. kind {
161
156
if let Res :: Def ( _, def_id) = self . cx . qpath_res ( qpath, callee. hir_id ) {
162
157
self . check_called_function ( def_id, expr. span ) ;
@@ -165,21 +160,18 @@ impl<'tcx> Visitor<'tcx> for SearchPanicIntraFunction<'_, 'tcx> {
165
160
}
166
161
}
167
162
}
168
- // Visit callee and arguments
169
163
self . visit_expr ( callee) ;
170
164
for arg in args {
171
165
self . visit_expr ( arg) ;
172
166
}
173
167
} ,
174
168
ExprKind :: MethodCall ( _, receiver, args, _) => {
175
- // Method call
176
169
if let Some ( def_id) = self . typeck_results . type_dependent_def_id ( expr. hir_id ) {
177
170
self . check_called_function ( def_id, expr. span ) ;
178
171
if self . panic_span . is_some ( ) {
179
172
return ;
180
173
}
181
174
}
182
- // Visit receiver and arguments
183
175
self . visit_expr ( receiver) ;
184
176
for arg in args {
185
177
self . visit_expr ( arg) ;
@@ -202,7 +194,6 @@ impl<'tcx> Visitor<'tcx> for SearchPanicIntraFunction<'_, 'tcx> {
202
194
if is_panic ( self . cx , macro_call. def_id )
203
195
|| matches ! ( macro_name. as_str( ) , "assert" | "assert_eq" | "assert_ne" )
204
196
{
205
- self . is_const = self . cx . tcx . hir ( ) . is_inside_const_context ( expr. hir_id ) ;
206
197
self . panic_span = Some ( macro_call. span ) ;
207
198
return ;
208
199
}
0 commit comments