1
1
use clippy_utils:: attrs:: is_doc_hidden;
2
- use clippy_utils:: diagnostics:: { span_lint, span_lint_and_help, span_lint_and_then } ;
2
+ use clippy_utils:: diagnostics:: { span_lint, span_lint_and_help} ;
3
3
use clippy_utils:: macros:: { is_panic, root_macro_call_first_node} ;
4
4
use clippy_utils:: ty:: is_type_diagnostic_item;
5
5
use clippy_utils:: visitors:: Visitable ;
@@ -10,10 +10,7 @@ use pulldown_cmark::Event::{
10
10
use pulldown_cmark:: Tag :: { CodeBlock , Heading , Item , Link , Paragraph } ;
11
11
use pulldown_cmark:: { BrokenLink , CodeBlockKind , CowStr , Options } ;
12
12
use rustc_ast:: ast:: Attribute ;
13
- use rustc_ast:: token:: CommentKind ;
14
- use rustc_ast:: { AttrKind , AttrStyle } ;
15
13
use rustc_data_structures:: fx:: FxHashSet ;
16
- use rustc_errors:: Applicability ;
17
14
use rustc_hir as hir;
18
15
use rustc_hir:: intravisit:: { self , Visitor } ;
19
16
use rustc_hir:: { AnonConst , Expr } ;
@@ -35,6 +32,7 @@ mod link_with_quotes;
35
32
mod markdown;
36
33
mod missing_headers;
37
34
mod needless_doctest_main;
35
+ mod suspicious_doc_comments;
38
36
39
37
declare_clippy_lint ! {
40
38
/// ### What it does
@@ -308,7 +306,6 @@ declare_clippy_lint! {
308
306
"suspicious usage of (outer) doc comments"
309
307
}
310
308
311
- #[ expect( clippy:: module_name_repetitions) ]
312
309
#[ derive( Clone ) ]
313
310
pub struct Doc {
314
311
valid_idents : FxHashSet < String > ,
@@ -451,7 +448,7 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
451
448
return None ;
452
449
}
453
450
454
- check_almost_inner_doc ( cx, attrs) ;
451
+ suspicious_doc_comments :: check ( cx, attrs) ;
455
452
456
453
let ( fragments, _) = attrs_to_doc_fragments ( attrs. iter ( ) . map ( |attr| ( attr, None ) ) , true ) ;
457
454
let mut doc = String :: new ( ) ;
@@ -481,43 +478,6 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
481
478
) )
482
479
}
483
480
484
- /// Looks for `///!` and `/**!` comments, which were probably meant to be `//!` and `/*!`
485
- fn check_almost_inner_doc ( cx : & LateContext < ' _ > , attrs : & [ Attribute ] ) {
486
- let replacements: Vec < _ > = attrs
487
- . iter ( )
488
- . filter_map ( |attr| {
489
- if let AttrKind :: DocComment ( com_kind, sym) = attr. kind
490
- && let AttrStyle :: Outer = attr. style
491
- && let Some ( com) = sym. as_str ( ) . strip_prefix ( '!' )
492
- {
493
- let sugg = match com_kind {
494
- CommentKind :: Line => format ! ( "//!{com}" ) ,
495
- CommentKind :: Block => format ! ( "/*!{com}*/" ) ,
496
- } ;
497
- Some ( ( attr. span , sugg) )
498
- } else {
499
- None
500
- }
501
- } )
502
- . collect ( ) ;
503
-
504
- if let Some ( ( & ( lo_span, _) , & ( hi_span, _) ) ) = replacements. first ( ) . zip ( replacements. last ( ) ) {
505
- span_lint_and_then (
506
- cx,
507
- SUSPICIOUS_DOC_COMMENTS ,
508
- lo_span. to ( hi_span) ,
509
- "this is an outer doc comment and does not apply to the parent module or crate" ,
510
- |diag| {
511
- diag. multipart_suggestion (
512
- "use an inner doc comment to document the parent module or crate" ,
513
- replacements,
514
- Applicability :: MaybeIncorrect ,
515
- ) ;
516
- } ,
517
- ) ;
518
- }
519
- }
520
-
521
481
const RUST_CODE : & [ & str ] = & [ "rust" , "no_run" , "should_panic" , "compile_fail" ] ;
522
482
523
483
/// Checks parsed documentation.
0 commit comments