Skip to content

Commit 6230b56

Browse files
Update clippy code
1 parent 4191e94 commit 6230b56

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

src/tools/clippy/clippy_lints/src/doc/doc_suspicious_footnotes.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
22
use rustc_ast::attr::AttributeExt as _;
33
use rustc_ast::token::{CommentKind, DocFragmentKind};
44
use rustc_errors::Applicability;
5+
use rustc_hir::attrs::AttributeKind;
56
use rustc_hir::{AttrStyle, Attribute};
67
use rustc_lint::{LateContext, LintContext};
78

@@ -45,7 +46,13 @@ pub fn check(cx: &LateContext<'_>, doc: &str, range: Range<usize>, fragments: &F
4546
if let DocFragmentKind::Sugared(_) = this_fragment.kind {
4647
let (doc_attr, doc_attr_comment_kind, attr_style) = attrs
4748
.iter()
48-
.filter(|attr| attr.span().overlaps(this_fragment.span))
49+
.filter(|attr| {
50+
matches!(
51+
attr,
52+
Attribute::Parsed(AttributeKind::DocComment { span, .. })
53+
if span.overlaps(this_fragment.span),
54+
)
55+
})
4956
.rev()
5057
.find_map(|attr| {
5158
let (_, fragment) = attr.doc_str_and_fragment_kind()?;

src/tools/clippy/clippy_lints/src/doc/suspicious_doc_comments.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ fn collect_doc_replacements(attrs: &[Attribute]) -> Vec<(Span, String)> {
3939
.filter_map(|attr| {
4040
if let Attribute::Parsed(AttributeKind::DocComment {
4141
style: AttrStyle::Outer,
42-
kind,
42+
kind: DocFragmentKind::Sugared(comment_kind),
4343
comment,
4444
..
4545
}) = attr
4646
&& let Some(com) = comment.as_str().strip_prefix('!')
4747
{
48-
let sugg = match kind {
49-
DocFragmentKind::Sugared(CommentKind::Block) => format!("/*!{com}*/"),
50-
DocFragmentKind::Sugared(CommentKind::Line) | DocFragmentKind::Raw(_) => format!("//!{com}"),
48+
let sugg = match comment_kind {
49+
CommentKind::Block => format!("/*!{com}*/"),
50+
CommentKind::Line => format!("//!{com}"),
5151
};
5252
Some((attr.span(), sugg))
5353
} else {

src/tools/clippy/clippy_utils/src/attrs.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use crate::source::SpanRangeExt;
44
use crate::{sym, tokenize_with_text};
5-
use rustc_ast::attr;
65
use rustc_ast::attr::AttributeExt;
76
use rustc_errors::Applicability;
87
use rustc_hir::attrs::AttributeKind;
@@ -87,11 +86,7 @@ pub fn is_proc_macro(attrs: &[impl AttributeExt]) -> bool {
8786

8887
/// Checks whether `attrs` contain `#[doc(hidden)]`
8988
pub fn is_doc_hidden(attrs: &[impl AttributeExt]) -> bool {
90-
attrs
91-
.iter()
92-
.filter(|attr| attr.has_name(sym::doc))
93-
.filter_map(AttributeExt::meta_item_list)
94-
.any(|l| attr::list_contains_name(&l, sym::hidden))
89+
attrs.iter().any(|attr| attr.is_doc_hidden())
9590
}
9691

9792
/// Checks whether the given ADT, or any of its fields/variants, are marked as `#[non_exhaustive]`

0 commit comments

Comments
 (0)