@@ -4,7 +4,7 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_help};
44use clippy_utils:: macros:: { is_panic, root_macro_call_first_node} ;
55use clippy_utils:: ty:: is_type_diagnostic_item;
66use 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} ;
88use pulldown_cmark:: Event :: {
99 Code , End , FootnoteReference , HardBreak , Html , Rule , SoftBreak , Start , TaskListMarker , Text ,
1010} ;
@@ -461,14 +461,14 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
461461 if !( is_entrypoint_fn ( cx, item. owner_id . to_def_id ( ) ) || in_external_macro ( cx. tcx . sess , item. span ) ) {
462462 let body = cx. tcx . hir ( ) . body ( body_id) ;
463463
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 ) ;
465465 missing_headers:: check (
466466 cx,
467467 item. owner_id ,
468468 sig,
469469 headers,
470470 Some ( body_id) ,
471- panic_span ,
471+ panic_info ,
472472 self . check_private_items ,
473473 ) ;
474474 }
@@ -806,6 +806,7 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
806806
807807struct FindPanicUnwrap < ' a , ' tcx > {
808808 cx : & ' a LateContext < ' tcx > ,
809+ is_const : bool ,
809810 panic_span : Option < Span > ,
810811 typeck_results : & ' tcx ty:: TypeckResults < ' tcx > ,
811812}
@@ -815,14 +816,15 @@ impl<'a, 'tcx> FindPanicUnwrap<'a, 'tcx> {
815816 cx : & ' a LateContext < ' tcx > ,
816817 typeck_results : & ' tcx ty:: TypeckResults < ' tcx > ,
817818 body : impl Visitable < ' tcx > ,
818- ) -> Option < Span > {
819+ ) -> Option < ( Span , bool ) > {
819820 let mut vis = Self {
820821 cx,
822+ is_const : false ,
821823 panic_span : None ,
822824 typeck_results,
823825 } ;
824826 body. visit ( & mut vis) ;
825- vis. panic_span
827+ vis. panic_span . map ( |el| ( el , vis . is_const ) )
826828 }
827829}
828830
@@ -841,6 +843,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> {
841843 "assert" | "assert_eq" | "assert_ne"
842844 )
843845 {
846+ self . is_const = in_constant ( self . cx , expr. hir_id ) ;
844847 self . panic_span = Some ( macro_call. span ) ;
845848 }
846849 }
0 commit comments