@@ -53,7 +53,7 @@ declare_lint_pass!(TestWithoutFailCase => [TEST_WITHOUT_FAIL_CASE]);
5353
5454impl < ' tcx > LateLintPass < ' tcx > for TestWithoutFailCase {
5555 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]`.
5757 if let ItemKind :: Fn ( _, _, body_id) = item. kind
5858 && is_in_test_function ( cx. tcx , item. hir_id ( ) )
5959 {
@@ -80,8 +80,6 @@ impl<'tcx> LateLintPass<'tcx> for TestWithoutFailCase {
8080struct SearchPanicIntraFunction < ' a , ' tcx > {
8181 /// The lint context
8282 cx : & ' a LateContext < ' tcx > ,
83- /// Whether we are inside a constant context
84- is_const : bool ,
8583 /// The span where a panic was found
8684 panic_span : Option < Span > ,
8785 /// Type checking results for the current body
@@ -95,7 +93,6 @@ impl<'a, 'tcx> SearchPanicIntraFunction<'a, 'tcx> {
9593 pub fn new ( cx : & ' a LateContext < ' tcx > , typeck_results : & ' tcx ty:: TypeckResults < ' tcx > ) -> Self {
9694 Self {
9795 cx,
98- is_const : false ,
9996 panic_span : None ,
10097 typeck_results,
10198 visited_functions : FxHashSet :: default ( ) ,
@@ -107,10 +104,10 @@ impl<'a, 'tcx> SearchPanicIntraFunction<'a, 'tcx> {
107104 cx : & ' a LateContext < ' tcx > ,
108105 typeck_results : & ' tcx ty:: TypeckResults < ' tcx > ,
109106 body : impl Visitable < ' tcx > ,
110- ) -> Option < ( Span , bool ) > {
107+ ) -> Option < Span > {
111108 let mut visitor = Self :: new ( cx, typeck_results) ;
112109 body. visit ( & mut visitor) ;
113- visitor. panic_span . map ( |span| ( span , visitor . is_const ) )
110+ visitor. panic_span
114111 }
115112
116113 /// Checks the called function to see if it contains a panic
@@ -127,7 +124,6 @@ impl<'a, 'tcx> SearchPanicIntraFunction<'a, 'tcx> {
127124 let typeck_results = self . cx . tcx . typeck ( local_def_id) ;
128125 let mut new_visitor = SearchPanicIntraFunction {
129126 cx : self . cx ,
130- is_const : false ,
131127 panic_span : None ,
132128 typeck_results,
133129 visited_functions : self . visited_functions . clone ( ) ,
@@ -156,7 +152,6 @@ impl<'tcx> Visitor<'tcx> for SearchPanicIntraFunction<'_, 'tcx> {
156152
157153 match expr. kind {
158154 ExprKind :: Call ( callee, args) => {
159- // Function call
160155 if let ExprKind :: Path ( ref qpath) = callee. kind {
161156 if let Res :: Def ( _, def_id) = self . cx . qpath_res ( qpath, callee. hir_id ) {
162157 self . check_called_function ( def_id, expr. span ) ;
@@ -165,21 +160,18 @@ impl<'tcx> Visitor<'tcx> for SearchPanicIntraFunction<'_, 'tcx> {
165160 }
166161 }
167162 }
168- // Visit callee and arguments
169163 self . visit_expr ( callee) ;
170164 for arg in args {
171165 self . visit_expr ( arg) ;
172166 }
173167 } ,
174168 ExprKind :: MethodCall ( _, receiver, args, _) => {
175- // Method call
176169 if let Some ( def_id) = self . typeck_results . type_dependent_def_id ( expr. hir_id ) {
177170 self . check_called_function ( def_id, expr. span ) ;
178171 if self . panic_span . is_some ( ) {
179172 return ;
180173 }
181174 }
182- // Visit receiver and arguments
183175 self . visit_expr ( receiver) ;
184176 for arg in args {
185177 self . visit_expr ( arg) ;
@@ -202,7 +194,6 @@ impl<'tcx> Visitor<'tcx> for SearchPanicIntraFunction<'_, 'tcx> {
202194 if is_panic ( self . cx , macro_call. def_id )
203195 || matches ! ( macro_name. as_str( ) , "assert" | "assert_eq" | "assert_ne" )
204196 {
205- self . is_const = self . cx . tcx . hir ( ) . is_inside_const_context ( expr. hir_id ) ;
206197 self . panic_span = Some ( macro_call. span ) ;
207198 return ;
208199 }
0 commit comments