@@ -4,7 +4,7 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_help};
4
4
use clippy_utils:: macros:: { is_panic, root_macro_call_first_node} ;
5
5
use clippy_utils:: ty:: is_type_diagnostic_item;
6
6
use clippy_utils:: visitors:: Visitable ;
7
- use clippy_utils:: { is_entrypoint_fn, is_trait_impl_item, method_chain_args} ;
7
+ use clippy_utils:: { in_constant , is_entrypoint_fn, is_trait_impl_item, method_chain_args} ;
8
8
use pulldown_cmark:: Event :: {
9
9
Code , End , FootnoteReference , HardBreak , Html , Rule , SoftBreak , Start , TaskListMarker , Text ,
10
10
} ;
@@ -461,14 +461,14 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
461
461
if !( is_entrypoint_fn ( cx, item. owner_id . to_def_id ( ) ) || in_external_macro ( cx. tcx . sess , item. span ) ) {
462
462
let body = cx. tcx . hir ( ) . body ( body_id) ;
463
463
464
- let panic_span = FindPanicUnwrap :: find_span ( cx, cx. tcx . typeck ( item. owner_id ) , body. value ) ;
464
+ let panic_info = FindPanicUnwrap :: find_span ( cx, cx. tcx . typeck ( item. owner_id ) , body. value ) ;
465
465
missing_headers:: check (
466
466
cx,
467
467
item. owner_id ,
468
468
sig,
469
469
headers,
470
470
Some ( body_id) ,
471
- panic_span ,
471
+ panic_info ,
472
472
self . check_private_items ,
473
473
) ;
474
474
}
@@ -806,6 +806,7 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
806
806
807
807
struct FindPanicUnwrap < ' a , ' tcx > {
808
808
cx : & ' a LateContext < ' tcx > ,
809
+ is_const : bool ,
809
810
panic_span : Option < Span > ,
810
811
typeck_results : & ' tcx ty:: TypeckResults < ' tcx > ,
811
812
}
@@ -815,14 +816,15 @@ impl<'a, 'tcx> FindPanicUnwrap<'a, 'tcx> {
815
816
cx : & ' a LateContext < ' tcx > ,
816
817
typeck_results : & ' tcx ty:: TypeckResults < ' tcx > ,
817
818
body : impl Visitable < ' tcx > ,
818
- ) -> Option < Span > {
819
+ ) -> Option < ( Span , bool ) > {
819
820
let mut vis = Self {
820
821
cx,
822
+ is_const : false ,
821
823
panic_span : None ,
822
824
typeck_results,
823
825
} ;
824
826
body. visit ( & mut vis) ;
825
- vis. panic_span
827
+ vis. panic_span . map ( |el| ( el , vis . is_const ) )
826
828
}
827
829
}
828
830
@@ -841,6 +843,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> {
841
843
"assert" | "assert_eq" | "assert_ne"
842
844
)
843
845
{
846
+ self . is_const = in_constant ( self . cx , expr. hir_id ) ;
844
847
self . panic_span = Some ( macro_call. span ) ;
845
848
}
846
849
}
0 commit comments