@@ -738,52 +738,33 @@ impl EarlyLintPass for DeprecatedAttr {
738738 }
739739}
740740
741- trait UnusedDocCommentExt {
742- fn warn_if_doc (
743- & self ,
744- cx : & EarlyContext < ' _ > ,
745- node_span : Span ,
746- node_kind : & str ,
747- attrs : & [ ast:: Attribute ] ,
748- ) ;
749- }
741+ fn warn_if_doc ( cx : & EarlyContext < ' _ > , node_span : Span , node_kind : & str , attrs : & [ ast:: Attribute ] ) {
742+ let mut attrs = attrs. into_iter ( ) . peekable ( ) ;
750743
751- impl UnusedDocCommentExt for UnusedDocComment {
752- fn warn_if_doc (
753- & self ,
754- cx : & EarlyContext < ' _ > ,
755- node_span : Span ,
756- node_kind : & str ,
757- attrs : & [ ast:: Attribute ] ,
758- ) {
759- let mut attrs = attrs. into_iter ( ) . peekable ( ) ;
760-
761- // Accumulate a single span for sugared doc comments.
762- let mut sugared_span: Option < Span > = None ;
744+ // Accumulate a single span for sugared doc comments.
745+ let mut sugared_span: Option < Span > = None ;
763746
764- while let Some ( attr) = attrs. next ( ) {
765- if attr. is_doc_comment ( ) {
766- sugared_span = Some (
767- sugared_span. map_or_else ( || attr. span , |span| span. with_hi ( attr. span . hi ( ) ) ) ,
768- ) ;
769- }
747+ while let Some ( attr) = attrs. next ( ) {
748+ if attr. is_doc_comment ( ) {
749+ sugared_span =
750+ Some ( sugared_span. map_or_else ( || attr. span , |span| span. with_hi ( attr. span . hi ( ) ) ) ) ;
751+ }
770752
771- if attrs. peek ( ) . map ( |next_attr| next_attr. is_doc_comment ( ) ) . unwrap_or_default ( ) {
772- continue ;
773- }
753+ if attrs. peek ( ) . map ( |next_attr| next_attr. is_doc_comment ( ) ) . unwrap_or_default ( ) {
754+ continue ;
755+ }
774756
775- let span = sugared_span. take ( ) . unwrap_or_else ( || attr. span ) ;
757+ let span = sugared_span. take ( ) . unwrap_or_else ( || attr. span ) ;
776758
777- if attr. is_doc_comment ( ) || attr. check_name ( sym:: doc) {
778- cx. struct_span_lint ( UNUSED_DOC_COMMENTS , span, |lint| {
779- let mut err = lint. build ( "unused doc comment" ) ;
780- err. span_label (
781- node_span,
782- format ! ( "rustdoc does not generate documentation for {}" , node_kind) ,
783- ) ;
784- err. emit ( ) ;
785- } ) ;
786- }
759+ if attr. is_doc_comment ( ) || attr. check_name ( sym:: doc) {
760+ cx. struct_span_lint ( UNUSED_DOC_COMMENTS , span, |lint| {
761+ let mut err = lint. build ( "unused doc comment" ) ;
762+ err. span_label (
763+ node_span,
764+ format ! ( "rustdoc does not generate documentation for {}" , node_kind) ,
765+ ) ;
766+ err. emit ( ) ;
767+ } ) ;
787768 }
788769 }
789770}
@@ -797,16 +778,16 @@ impl EarlyLintPass for UnusedDocComment {
797778 ast:: StmtKind :: Semi ( ..) | ast:: StmtKind :: Expr ( ..) | ast:: StmtKind :: Mac ( ..) => return ,
798779 } ;
799780
800- self . warn_if_doc ( cx, stmt. span , kind, stmt. kind . attrs ( ) ) ;
781+ warn_if_doc ( cx, stmt. span , kind, stmt. kind . attrs ( ) ) ;
801782 }
802783
803784 fn check_arm ( & mut self , cx : & EarlyContext < ' _ > , arm : & ast:: Arm ) {
804785 let arm_span = arm. pat . span . with_hi ( arm. body . span . hi ( ) ) ;
805- self . warn_if_doc ( cx, arm_span, "match arms" , & arm. attrs ) ;
786+ warn_if_doc ( cx, arm_span, "match arms" , & arm. attrs ) ;
806787 }
807788
808789 fn check_expr ( & mut self , cx : & EarlyContext < ' _ > , expr : & ast:: Expr ) {
809- self . warn_if_doc ( cx, expr. span , "expressions" , & expr. attrs ) ;
790+ warn_if_doc ( cx, expr. span , "expressions" , & expr. attrs ) ;
810791 }
811792}
812793
0 commit comments